简体   繁体   中英

Laravel dusk, incorrect testing result

I just discovered Laravel Dusk, and wrote first test, which had to check for text on the page, but Laravel Dusk doesn`t see my page.

Test:

namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class FirstTest extends DuskTestCase
{
    public function testExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                ->assertSee('Laravel');
        });
    }
}

And $browser->visit('/') check is successful, but $browser->visit('/') ->assertSee('Laravel'); check was failed.

In directory tests/Browser/Screenshots I found screenshot that page, which contains No input file specified

a part of file .env :

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:lypVdWwGkDn/R5L5PQ8tOUgfzf2WTzCSZU6GndMPuNM=
APP_DEBUG=true
APP_URL=http://127.0.0.1

After added file .env.dusk.local which contains:

APP_URL=http://127.0.0.1:9519

(As specified in the Laravel Dusk manual , the port must match the one specified in DuskTestCase.php )

tests/Browser/screenshots/failed-test-* contains: command:

Error text:

Time: 2.58 seconds, Memory: 12.00MB

There was 1 failure:

1) Tests\Browser\FirstTest::testExample
Did not see expected text [Laravel] within element [body].
Failed asserting that false is true.

/home/vagrant/code/homestead_test/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:400 /home/vagrant/code/homestead_test/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:371 /home/vagrant/code/homestead_test/tests/Browser/FirstTest.php:18 /home/vagrant/code/homestead_test/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67 /home/vagrant/code/homestead_test/tests/Browser/FirstTest.php:19

FAILURES! Tests: 1, Assertions: 1, Failures: 1.

Sorry for my English =)

UPD:

a part of .env.dusk.local after deleting port: (for Jonas Staudenmeir).

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:lypVdWwGkDn/R5L5PQ8tOUgfzf2WTzCSZU6GndMPuNM=
APP_DEBUG=true
APP_URL=http://127.0.0.1

Solved. I changed .env.dusk.local (was set virtual host domain), and it's working.

eg APP_URL=http://homestead.test

Special thanks to @Jonas Staudenmeir

If Test fails on laravel desk it given me a random page of phpmyadmin on screenshot page.It must give me the page on which its giving an error.Please see the page bellow. Click Here.

There is a few ways you can try:

1.make sure copy ".env" rename ".env.dusk.local" and change APP_URL={ http://localhost:8000 } //you serve 2. run php artisan serve 3. run php artisan dusk Time: 2.17 seconds, Memory: 18.00 MB

OK (1 test, 1 assertion)

debug: 1.change DuskTestCase.php to see what website page you browse http://localhost:9515 , DesiredCapabilities::chrome()

2.add one line in your test file ExampleTest.php pause(1000)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM