i try laravel dusk today and set up login with modal component. this is my test code
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');
});
}
when I run dusk command, dusk simulates the login and it works fine. my modal works properly and then redirects to the right page. somehow, my test fails because it says the actual url is still /
not /home
which i expected. Laravel dusk will take a screenshot everytime the test fails. when i look at the screenshot, it's on the right page or url as in assertPathIs()
.
anyone can point out why is this happend? any help would be appreciated.
You could add a waitForLocation like this:
->waitForLocation('/home');
before
->assertPathIs('/home');
.
It is best practice to use an explicit wait (eg ->waitForLocation('/home');
rather than an implicit wait (eg ->pause(3000)
See:
- http://elementalselenium.com/tips/47-waiting
- https://laravel.com/docs/5.6/dusk#waiting-for-elements
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.