英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论