【问题标题】:Debug Protractor Test case in IntelliJ using Intellij JavaScript debugger使用 Intellij JavaScript 调试器在 IntelliJ 中调试量角器测试用例
【发布时间】:2015-02-26 03:52:04
【问题描述】:

我有一个关于在 Intellij Idea 14 中调试 Protractor 脚本的问题。 我确实根据这个文档设置了 Dubuger 配置:protractor/docs/debugging.md 并尝试通过在 console.log 上放置断点来检查 lblInvalidLoginMsg 对象的值来调试我的代码:

it('should do something', function() {
  txtEmail.sendKeys("aaa@asd.com");
  txtPassword.sendKeys("aaaaa");
  btnSignIn.click();
  lblInvalidLoginMsg.getAttribute('value').then(function(){
    console.log("hello");
  })

  expect(lblInvalidLoginMsg.getAttribute('value')).toEqual('Blah Blah');
});

问题是遇到断点时调试器没有显示任何值。调试器手表只显示我可以对对象应用的可用方法列表,例如getText()getID() 等,但没有预期的值。

控制台输出如下:

‌‌lblInvalidLoginMsg.getId()
‌ElementFinder
‌‌lblInvalidLoginMsg.isElementPresent();
‌webdriver.promise.Promise

“评估”功能也是如此。有什么我遗漏的吗?

更新:在调试模式 + 调试配置 + 量角器控制台结果中添加了我的脚本的屏幕截图。

【问题讨论】:

    标签: javascript debugging selenium intellij-idea protractor


    【解决方案1】:

    Protractor 严重依赖承诺的概念。要查看元素文本或属性的实际值,您需要使用then() 解析它们。示例:

    element(by.id('#myId')).then(function(elm) {
        elm.getText().then(function (text) {
            console.log(text);  // put a breakpoint here
        });  
    });
    

    或:

    lblInvalidLoginMsg.getAttribute('value').then(function(value) {
        console.log(value);  // value here would contain an actual attribute value
    });
    

    另外,当protractor暂停调试时,你可以使用浏览器开发工具,调用protractor注入的客户端脚本命令,见:

    另见:

    【讨论】:

    • 嗨,亚历克斯,感谢您的建议。我能够让 Protractor elementExplorer.js 工作,但在 IntelliJ Idea 中调试对我来说仍然是个谜。我确实根据您的建议在 then() 语句中设置了断点,但和之前一样,除了可用元素方法的列表之外什么也没有。我用调试模式下脚本的屏幕截图 + 调试器配置 + Protractor elementExplorer 控制台的结果更新了我的原始帖子。
    • @Vlad 这实际上是正确的。您将获得一个带有可用方法的元素实例。他们都会回报一个承诺。比如要获取getText()的值,就需要写elm.getText().then(function (text) { console.log(text); });..
    猜你喜欢
    • 2016-06-22
    • 2018-06-13
    • 2016-09-12
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2013-06-25
    相关资源
    最近更新 更多