简体   繁体   中英

testing a new window with laravel dusk

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM