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.
Accessing The Current URL echo url()->current(); // Get the current URL including the query string... echo url()->full();
Laravel Dusk provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require you to install JDK or Selenium on your local computer. Instead, Dusk uses a standalone ChromeDriver installation. However, you are free to utilize any other Selenium compatible driver you wish.
For laravel dusk to be able to run the browser automation test on your local environment, It needs to know your application url. For this, Go to your environment file . env , and set the APP_URL property to be your application url. This value should match the URL you use to access your application in the browser.
Route::get('browser', function () { //create new agent instance $agent = new Jenssegers\Agent\Agent(); //check if agent is robot if ($agent->isRobot()) { return $agent->robot(); } //if agent is not robot then get agent browser and platform like Chrome in Linux $agent = $agent->browser() . " in " .
Here is a way to check the URL value in Laravel Dusk:
$browser->visit($a);
$url = $browser->driver->getCurrentURL();
$this->assertEquals($b, $url);
You can use assertUrlIs()
:
$browser->assertUrlIs($b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With