简体   繁体   English

Laravel 黄昏,错误的测试结果

[英]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.我刚刚发现了 Laravel Dusk,并编写了第一个测试,它必须检查页面上的文本,但是 Laravel Dusk 没有看到我的页面。

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');并且$browser->visit('/')检查成功,但是$browser->visit('/') ->assertSee('Laravel'); check was failed.检查失败。

In directory tests/Browser/Screenshots I found screenshot that page, which contains No input file specified在目录tests/Browser/Screenshots我找到了该页面的屏幕截图,其中包含未No input file specified

a part of file .env :文件.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:添加文件.env.dusk.local ,其中包含:

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 ) (如Laravel Dusk手册中指定的,端口必须与DuskTestCase.php指定的DuskTestCase.php

tests/Browser/screenshots/failed-test-* contains: command: tests/Browser/screenshots/failed-test-*包含: 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 /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).删除端口后.env.dusk.local的一部分.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

Solved.解决了。 I changed .env.dusk.local (was set virtual host domain), and it's working.我更改了.env.dusk.local (设置了虚拟主机域),它正在工作。

eg APP_URL=http://homestead.test例如APP_URL=http://homestead.test

Special thanks to @Jonas Staudenmeir特别感谢@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.如果在 Laravel 桌面上测试失败,它会在屏幕截图页面上给我一个随机的 phpmyadmin 页面。它必须给我一个错误的页面。请参阅下面的页面。 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 1.确保复制“.env”重命名“.env.dusk.local”并更改APP_URL={ http://localhost:8000 } //you serve 2. run php artisan serve 3. run php artisan dusk 时间:2.17秒,内存:18.00 MB

OK (1 test, 1 assertion) OK(1 个测试,1 个断言)

debug: 1.change DuskTestCase.php to see what website page you browse http://localhost:9515 , DesiredCapabilities::chrome()调试: 1.更改 DuskTestCase.php 以查看您浏览的网站页面http://localhost:9515 , DesiredCapabilities::chrome()

2.add one line in your test file ExampleTest.php pause(1000) 2.在你的测试文件中添加一行 ExampleTest.php pause(1000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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