Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to assert current URL value in Laravel Dusk?

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.

like image 354
rap-2-h Avatar asked Jan 17 '18 08:01

rap-2-h


People also ask

How can I get current URL in laravel?

Accessing The Current URL echo url()->current(); // Get the current URL including the query string... echo url()->full();

How does laravel dusk work?

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.

How do you run a dusk test?

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.

How do I get browser in laravel 8?

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 " .


2 Answers

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

$browser->visit($a);
$url = $browser->driver->getCurrentURL();
$this->assertEquals($b, $url);
like image 146
rap-2-h Avatar answered Oct 16 '22 04:10

rap-2-h


You can use assertUrlIs():

$browser->assertUrlIs($b);
like image 23
Jonas Staudenmeir Avatar answered Oct 16 '22 05:10

Jonas Staudenmeir