gpt4 book ai didi

javascript - Nightwatch js 在所有步骤中使用页面对象作为变量

转载 作者:太空宇宙 更新时间:2023-11-04 15:26:14 25 4
gpt4 key购买 nike

我有一些带有代码的页面对象文档:

var gmailItemClicks = {
composeClick: function () {
return this.section.leftToolbarSection.click('@compose');
}
};
module.exports = {
commands: [gmailItemClicks],
sections: {
leftToolbarSection: {
selector: '.nH.oy8Mbf.nn.aeN',
elements: {
compose: { selector: '.T-I.J-J5-Ji.T-I-KE.L3' },
}
},
};

以及包含许多步骤的测试文件,如下所示:

module.exports = {    
'1st step': function (client) {
gmail.composeClick();
},
'2d step': function (client) {
gmail.composeClick();
}
}

如果“gmail”变量出现在如下所示的每个步骤中,我可以使用它:

module.exports = {    
'1st step': function (client) {
var gmail = client.page.gmail();
gmail.composeClick();
},
'2d step': function (client) {
var gmail = client.page.gmail();
gmail.composeClick();
}
}

但我想将此变量与步骤中的测试代码分开。我尝试使用

const gmail = require('./../pages/gmail');

在 module.exports bloсk 之前的测试中,我尝试使用具有相同语法的 globals.js 文件,但收到错误“✖ TypeError: gmail.composeClick is not a function”。
现在我只有一个大函数,其中所有步骤都在函数内部声明一次,但测试日志看起来很难看,我看不到一个步骤何时开始以及在哪里停止。
我错过了什么?

最佳答案

您可以在 before block 中创建对象。这是我的代码中的样子:

(function gmailSpec() {
let gmailPage;
function before(client) {
gmailPage = client.page.gmail();
gmailPage.navigate()
}
function after(client) {
client.end();
}

function firstStep() {
gmailPage.composeClick()
}

function secondStep() {
gmailPage.composeClick()
}

module.exports = {
before,
after,
'1st step': firstStep,
'2nd step': secondStep
}
}());

希望对你有帮助:)

关于javascript - Nightwatch js 在所有步骤中使用页面对象作为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48114007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com