I have this page that, when a particular button is clicked, a new window pops up (eg. an anchor tag with _target = blank). I want to verify that a string of text appears in this new window but, with Laravel Dusk, assertSee
appears to be testing the original window and not the newly opened window.
Any ideas as to how I can test the contents of the newly opened window?
I just ran into this problem today. You can use the browser driver to get all the opened windows, and then switch to the tab that was opened last.
// Get the last opened tab
$window = collect($browser->driver->getWindowHandles())->last();
// Switch to the tab
$browser->driver->switchTo()->window($window);
// Check if the path is correct
$browser->assertPathIs('/path/of/site/in/new/tab');
You might need to add a pause after switching to the new window, since dusk is pretty fast and it may start asserting before the new page is fully loaded.
(I found this answer in a github issue, https://github.com/laravel/dusk/issues/336)
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