我刚刚发现 Laravel Dusk,并编写了第一个测试,它必须检查页面上的文本,但 Laravel Dusk 看不到我的页面。
测试:
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');
});
}
}
并且$browser->visit('/')
检查成功,但$browser->visit('/')
->assertSee('Laravel');
检查失败。
在目录tests/Browser/Screenshots
中,我找到了该页面的屏幕截图,其中包含No input file specified
文件的一部分.env
:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:lypVdWwGkDn/R5L5PQ8tOUgfzf2WTzCSZU6GndMPuNM=
APP_DEBUG=true
APP_URL=http://127.0.0.1
添加文件后.env.dusk.local
,其中包含:
APP_URL=http://127.0.0.1:9519
(如Laravel Dusk
手册中所述,端口必须与中指定的端口匹配DuskTestCase.php
)
tests/Browser/screenshots/failed-test-*
包含:command:
错误文字:
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.
对不起我的英语=)
升级版:
删除端口后的一部分.env.dusk.local
:(对于 Jonas Staudenmeir)。
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:lypVdWwGkDn/R5L5PQ8tOUgfzf2WTzCSZU6GndMPuNM=
APP_DEBUG=true
APP_URL=http://127.0.0.1