简体   繁体   English

用laravel黄昏测试一个新窗口

[英]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). 我有这个页面,当点击一个特定的按钮时,会弹出一个新窗口(例如,一个带有_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. 我想验证一个文本字符串出现在这个新窗口中,但是,使用Laravel Dusk, assertSee似乎是测试原始窗口而不是新打开的窗口。

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 ) (我在github问题中找到了这个答案, https://github.com/laravel/dusk/issues/336

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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