'How to test url of new tab after clicking a link in laravel dusk

I'm testing my website using Laravel Dusk and I want to test a link that open a new tab to check if it goes to the correct URL. My test looks like this;

$this->browse(function (Browser $browser) {
     $browser->loginAs(User::find(1))
        ->visit('/test')
        ->waitForLocation('/test')
        ->click('#test-link');
     $window = collect($browser->driver->getWindowHandles())->last();
     $browser->driver->switchTo()->window($window);
     $url = $browser->driver->getCurrentURL();
     Assert::assertTrue($url == 'http://foobar.com');
});

The problem here is that the URL that I'm getting is just about:blank. At first, I thought it's because the new tab is still loading but I tried to add a pause(5000) before getting current URL but it still returns about:blank. Why does the new tab doesn't proceed with the URL of the link?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source