【问题标题】:Can I access the document or window objects from within a protractor test?我可以从量角器测试中访问文档或窗口对象吗?
【发布时间】:2014-12-27 06:20:27
【问题描述】:

也许这是不可能的,我还不太明白 node 是如何工作的。在量角器中获取页面后,我希望能够在文档对象上运行断言。这样的事情有可能吗?如果有,怎么办?

谢谢!

【问题讨论】:

    标签: javascript testing protractor


    【解决方案1】:

    好的,找到了答案,所以我为别人回答我自己的问题:

    您可以使用 browser.executeScript 执行 javascript,然后在您的 promise 解析中使用返回值,如下所示:

    browser.executeScript('return document._config').then( function(_config){
            expect( _config.epid ).toBe( 1 );
        });

    【讨论】:

      【解决方案2】:

      您正在寻找的功能称为 executeScript 或 executeAsyncScript。它们将帮助您在浏览器中执行任意一段 javascript。

      看看这些链接: http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeScript http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeAsyncScript

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-11-23
        • 2011-11-26
        • 2019-10-05
        • 1970-01-01
        • 2020-12-03
        • 1970-01-01
        • 2010-10-30
        相关资源
        最近更新 更多