【问题标题】:How to use commands on sections in Nightwatch.js?如何在 Nightwatch.js 中的部分上使用命令?
【发布时间】:2015-09-11 15:31:44
【问题描述】:

所以基本上我已经开始使用 PageObjects 并且遇到了一些问题。

  1. 我想直接在某个部分执行命令。例如 - 我想.waitForElementVisible 直接在部分上(而不是在元素上)。甚至可能吗?我尝试了很多组合,例如:

    browser.page.topMenu().section.loginBox.section.unauthenticated.waitForElementVisible('@loginTooltip', 10000)

所以它看起来像这样:topMenu() 是我的 pageObject 文件,然后有 loginBox 部分包含 -> unauthenticated 部分包含 -> loginTooltip 部分。我想在最后一节.waitForElementVisible。这该怎么做?我知道我可以不受限制地组合我的部分,但是以后如何处理它们?

  1. [会说这个问题是一个奖励,因为它与标题中的问题无关] 我在逐节进行断言时遇到问题。这该怎么做?我尝试了很多方法,其中一种如下:

browser.page.topMenu().expect.section('@loginBox').to.be.visible - 这行得通 - 因为它只有一个部分

browser.page.topMenu().expect.section('@loginBox').section('@unauthenticated').to.be.visible - 不工作 - 我想检查 unauthenticated 里面的 loginBox 部分是否可见。如何做到这一点?

在此先感谢您的所有回答,我已经尝试自己解决这个问题,但没有成功。

【问题讨论】:

    标签: javascript selenium e2e-testing nightwatch.js


    【解决方案1】:

    好的,首先让我们把它分解一下,这样它会更具可读性:

    var topMenu = browser.page.topMenu(); // Declare the page object.
    var loginBox = topMenu.section.loginBox; // Declare the first section.
    var unauthenticated = loginBox.section.unauthenticated // Declare the second section.
    

    等等……

    一旦你想执行一个命令,你可以这样做:

    loginBox.waitForElementVisible('@unauthenticated');
    

    注意,应该声明节选择器:

    sections: {
       unauthenticated: {
          selector: '.unauthenticated_title',
          elements: {
            sectionElements: '.selector_selector'
          }
       },
       anotherSection: {
          ...
       }
    }
    

    第二个问题类似。

    loginBox.expect.element('@ unauthenticated').to.be.visible;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      相关资源
      最近更新 更多