11

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.

rap-2-h
  • 30,204
  • 37
  • 167
  • 263

3 Answers3

14

Here is a way to check the URL value in Laravel Dusk:

$browser->visit($a);
$url = $browser->driver->getCurrentURL();
$this->assertEquals($b, $url);
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
  • +1. `$browser->driver->getCurrentURL()` was helpful for me when using `waitUsing` (https://laravel.com/docs/5.7/dusk#waiting-for-elements) – Ryan Feb 27 '19 at 00:48
7

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.

igaster
  • 12,983
  • 6
  • 26
  • 27
5

You can use assertUrlIs():

$browser->assertUrlIs($b);
Jonas Staudenmeir
  • 24,815
  • 6
  • 63
  • 109