I'm testing a web application with subdomain routing with Laravel Dusk. I have some redirection between subdomain, if some kind of verification is invalid.
So, my goal is to visit
an URL $a
then assert that I was redirected and the new URL is $b
.
I can do:
$browser->visit($a);
But I don't know what to do right after to check what the current URL is.
Here is a way to check the URL value in Laravel Dusk:
$browser->visit($a);
$url = $browser->driver->getCurrentURL();
$this->assertEquals($b, $url);
你可以使用assertUrlIs()
:
$browser->assertUrlIs($b);
TLDR: The most convenient is assertPathIs()
A) Use assertPathIs()
to assert that the current relative path matches the given path.
$browser->visit('/admin')
->assertPathIs('/login');
B) Use assertUrlIs()
to assert that the current URL matches the given URL.
$browser->visit('/admin')
->assertUrlIs('http://fullhost.com/login');
Note that you must provide a full URL for this one. Use it when you have URLs with external domains.
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.