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');
    });
}

当我运行黄昏命令时,黄昏模拟登录并且工作正常。我的模态正常工作,然后重定向到正确的页面。不知何故,我的测试失败了,因为它说实际的 url 仍然/不是/home我所期望的。每次测试失败时,Laravel 黄昏都会截屏。当我查看屏幕截图时,它在正确的页面或 url 上,如assertPathIs().

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

4

1 回答 1

6

你可以像这样添加一个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

于 2018-04-09T15:13:29.190 回答