Laravel Dusk无法匹配assertPathIs()中的url

ish*_*dif 4 laravel laravel-5.4

我今天尝试拉拉威尔(Laravel)黄昏,并使用模态组件设置登录名。这是我的测试代码

public function testBasicExample()
{
    $this->browse(function ($browser) {
        $browser->visit('/')
                ->assertSee('My App')
                ->press('Login')
                ->whenAvailable('.modal', function($modal){
                    $modal->type('id','1112')
                        ->type('password','password')
                        ->press('Submit');
                })
                ->assertPathIs('/home');
    });
}
Run Code Online (Sandbox Code Playgroud)

当我运行黄昏命令时,黄昏会模拟登录并且工作正常。我的模式可以正常工作,然后重定向到正确的页面。不知何故,我的测试失败了,因为它说实际的URL仍然/不是/home我期望的。每当测试失败时,Laravel黄昏都会拍摄一张屏幕截图。当我查看屏幕截图时,它位于的正确页面或url中assertPathIs()

任何人都可以指出为什么会这样吗?任何帮助,将不胜感激。

小智 5

您可以像这样添加一个waitForLocation:

->waitForLocation('/home');

之前

->assertPathIs('/home');


最佳做法是使用显式等待(例如,->waitForLocation('/home');而不是隐式等待(例如,->pause(3000)

请参阅:
- http://elementalselenium.com/tips/47-waiting
- https://laravel.com/docs/5.6/dusk#waiting-for-elements