【发布时间】:2017-06-30 14:41:45
【问题描述】:
我所有的 Geb/Spock 测试都在 Firefox 上完美运行,然后我尝试使用 Chrome (v59),当出现警报或确认弹出窗口时它一直挂起。
对于 Firefox,我使用 withAlert{} 或 withConfirm{} 来处理这些问题,但它不适用于 Chrome。
所以我对视图进行了一些挖掘,发现对话框由this widget 管理。所以我在我的页面对象中创建了<dialog> 的访问器,但 Chrome 仍然无法与之交互(无法检测到弹出窗口是否显示或关闭)。
我尝试了几件事,例如使用displayed 或等待显示文本但没有任何效果。
我不习惯 jQuery,所以也许我在这里遗漏了什么?
这是我必须与之交互的代码示例:
<dialog class="qq-alert-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<div class="qq-dialog-buttons">
<button type="button" class="qq-cancel-button-selector">Close</button>
</div>
</dialog>
这就是我尝试访问它的方式(在我的页面对象中):
alertPopUp {$("dialog", class:"qq-alert-dialog-selector")}
alertCloseButton {alertPopUp.children("div.qq-dialog-buttons").children("button")}
最后我想如何测试弹出窗口:
when: "Trying to upload ..."
uploadFileButton = incorrect.absolutePath
then: "An alerting pop up occurs"
waitFor{alertPopUp.displayed}
when: "Closing the pop up"
alertCloseButton.click(SubmitAClaim)
then: "Number of uploaded files should not change"
uploadedElements.size() == initialUploadedFiles
有人可以帮忙吗?我想这可能与 chrome 的 focus 有关(我的意思是它当前是在弹出窗口上还是在后面的页面上。
编辑:
毕竟,问题似乎与 jQuery 无关(我猜是好事)。感谢<dialog> 中的open attribute,我们可以验证对话框是否打开。我做过这样的事情:
when: "Trying to upload ..."
uploadFileButton = incorrect.absolutePath
then: "A alerting pop up occurs"
waitFor {alertPopUp.getAttribute("open") == "true"}
但我仍然无法与对话框交互:当我尝试单击alertCloseButton 时,它会引发ElementNotVisibleException。所以我猜它与浏览器焦点有关。
我试过了:
-
withWindow{}或driver.switchTo().window()但唯一可用的窗口是主窗口。 -
withFrame()但我得到了NoSuchFrameException -
driver.switchTo().alert()但它引发了NoAlertRaisedException
所以我想知道是否有人知道 Chrome 是如何看待<dialog> 标签(警报,确认,...)?
注意:根据caniuse.com,Chrome 是目前唯一兼容
<dialog>的浏览器。
【问题讨论】:
-
我设法通过使用
waitFor{alertPopUp.getAttribute("open") != null}来测试弹出窗口是否通过了,但我什至不确定它是否真的断言正确。我仍然挂断单击对话框中的按钮。 Selenium 提出ElementNotVisibleException并且我已经检查过:没有几个选定的元素不可见。只有一个 (alertCloseButton.size() == 1)。有没有人有想法或者我是否将其作为 ChromeDriver 2.30 上的问题记录?
标签: html google-chrome selenium spock geb