【问题标题】:Closing a window.confirm in protractor with phantomJs用phantomJs在量角器中关闭window.confirm
【发布时间】:2014-09-10 16:37:03
【问题描述】:

我正在使用 Protractor 为我的 AngularJS 应用程序编写 E2E 测试。

有时浏览器会遇到window.confirm

当使用 Chrome 作为测试浏览器时,以下代码可以正常工作:

var ptor = protractor.getInstance();
ptor.switchTo().alert().accept();

但在 PhantomJS 上会引发以下错误:

UnknownError: Invalid Command Method
==== async task ====
WebDriver.switchTo().alert()
    at tests/E2E/spec/search.spec.js:73:33
==== async task ====
Asynchronous test function: it()
Error
    at null.<anonymous> (tests/E2E/spec/search.spec.js:63:5)
    at Object.<anonymous> (tests/E2E/spec/search.spec.js:6:1)

关于如何使用 PhantomJS 处理它的任何线索?

【问题讨论】:

    标签: angularjs phantomjs protractor


    【解决方案1】:

    由于 PhantomJS/GhostDriver 尚不支持 switchTo().alert()

    我选择了以下解决方案:模拟 window.confirm 如下:

    beforeEach(function() {
        // bypassing PhantomJS 1.9.7/GhostDriver window.confirm (or alert) bug.
        // as WebDriver's switchTo().alert() is not implemented yet.
        browser.executeScript('window.confirm = function() {return true;}')
    });
    

    注意:我在量角器测试中使用了 jasmine,因此我需要将它放在 beforeEach 中,否则它不会有任何效果。

    【讨论】:

    • 帖子看起来很老,现在我使用的是 PhantomJS 2.1.7。运气好吗?
    猜你喜欢
    • 2015-05-07
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 2014-08-17
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多