使用Selenium检测Chrome中弹出窗口的关闭 [英] Detecting the closing of a popup in Chrome, using Selenium

查看:1098
本文介绍了使用Selenium检测Chrome中弹出窗口的关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用PHP(5.3.15)编写一个Selenium(服务器2.31.0)测试,需要测试一个弹出窗口关闭。弹出窗口是使用 jQuery UI对话框构件实现的。弹出窗口本身包含一些简单的文本( HelloWorld ),它不会出现在弹出窗口外面。



检测外观使用 isTextPresent(HelloWorld); 弹出窗口很好。然后我用 clickAt(// a [contains(@class,'ui-dialog-titlebar-close')]); (我可以看看作品),然后用!isTextPresent(HelloWorld); 关闭弹出框进行测试。我应该补充一点,我正在做适当的事情来确保弹出窗口有时间打开/关闭;有一个重复的停顿&检查周期,我也可以看到效果,如果我迫使显式睡眠问题。



这适用于Firefox(19.0.2),但在Chrome下失败25.0.1364.172)。即该窗口正在关闭,但我没有在Selenium下检测到它。我预计这是由于Selenium如何执行 isTextPresent 检查和/或弹出窗口只隐藏而不是关闭。



我正在寻找一种方法来检测适用于Chrome的关闭弹出窗口。跨浏览器将是伟大的,但目前,我可以在不同的浏览器上运行不同的测试。 可以使用 isVisible 在弹出窗口()上生成测试(就测试设计的内容而言,与之前检查的特定行为相反) isVisible(// a [contains(@class,\'ui-dialog-titlebar-close \')]); )在关闭弹出窗口后进行相应的否定测试。这适用于Chrome(25.0.1364.172)和Firefox(19.0.2)。



这不是对弹出窗口的内容进行同样的检查,但是,想要的效果是测试弹出窗口的存在,这是足够的。


I am writing a Selenium (server 2.31.0) test in PHP (5.3.15) that needs to test for a popup window closing. The popup window is implemented using the jQuery UI Dialog Widget. The popup itself contains some simple text (HelloWorld) that does not appear outside the popup.

Detecting the appearance of the popup is fine using isTextPresent("HelloWorld");. I am then closing the window with clickAt("//a[contains(@class, 'ui-dialog-titlebar-close')]"); (which I can see works) and then testing on the popup being closed with !isTextPresent("HelloWorld");. I should add that I am doing appropriate things to make sure that the popup is being given time to open / close; there's a repeated pause & check cycle and I can also see the effect if I force the issue with an explicit sleep.

This works fine under Firefox (19.0.2) but is failing under Chrome (25.0.1364.172). I.e. the window is being closed but I am not detecting this under Selenium. I expect this is due to how Selenium does the isTextPresent check and/or the popup only being hidden as opposed to closed.

I am looking for a method for detecting the closing popup that works on Chrome. Cross browser would be great but, for the moment, I would be able to run different tests on different browsers.

解决方案

An equivalent test (in terms of what the test is designed for, as opposed to the particular previous behaviour checked for) can be produced using isVisible on the popup (isVisible("//a[contains(@class, \'ui-dialog-titlebar-close\')]");) with a corresponding negative test after closing the popup. This works under both Chrome (25.0.1364.172) and Firefox (19.0.2).

This is not doing the same check on the contents of the popup but, since the desired effect is to test for the popup's presence, it is sufficient.

这篇关于使用Selenium检测Chrome中弹出窗口的关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆