Nightwatch 在每次调用时使用相同的元素选择器。

huangapple go评论77阅读模式
英文:

Nightwatch using same element selector for each call

问题

以下是翻译好的部分:

有没有办法在执行相同元素上的多个操作时避免两次或更多次使用元素的选择器?

例如:
('Some test',function(浏览器){
浏览器
.waitForElementVisible('选择器',10000)
.click('THE SAME 选择器')
}),

它不能像Cypress一样排列吗?

Cy
  .get('元素')
  .should('be.visible')
  .click() - 就像只提到元素选择器的三个动作

还是将元素保存为变量,然后使用它?

我在互联网上搜索过,但没有找到合适的话题。

英文:

Is there a way to avoid using element's selector twice or more when executing several actions on the same element?

E.g.
('Some test', function (browser) {
browser
.waitForElementVisible('selector', 10000)
.click('THE SAME selector')
}),

Can't it be arranged just like in Cypress?

Cy
  .get('element')
  .should('be.visible')
  .click()    - like 3 actions with only one mentioning of the element's selector

Or to save the element as a variable and use it then?

I have searched throughout the Internet but haven't found any proper topic

答案1

得分: 2

以下是已翻译的内容:

"The way that you would do this is to move the locator into a page object or into a variable as described in the API Docs"

"The reason why NightwatchJS doesn't follow the Cypress pattern is that we allow chaining of all commands. This means that you can create more complex tests."

"A click can only happen if it is visible in Nightwatch so you don't need to add an assert for it before clicking"

英文:

The way that you would do this is to move the locator into a page object or into a variable as described in the API Docs

The reason why NightwatchJS doesn't follow the Cypress pattern is that we allow chaining of all commands. This means that you can create more complex tests.

const githubButton = 'a[aria-label="Nightwatch on Github"]';

  before(browser => browser.navigateTo('https://nightwatchjs.org/'));

  after(browser => browser.end());

  it('click element', function (browser) {
    browser
      .click(githubButton)
  });    

A click can only happen if it is visible in Nightwatch so you don't need to add an assert for it before clicking

huangapple
  • 本文由 发表于 2023年5月31日 22:40:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76374699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定