我已經在Nightwatch中爲我的UI測試創建了此自定義命令。這是在充分:Nightwatch:使用自定義命令遍歷所有選擇的標籤
exports.command = function(element, callback) {
var self = this;
try {
this.waitForElementVisible('body', 15000);
console.log("trying..");
window.addEventListener('load', function() {
var selects = document.getElementsByName("select");
console.log(selects);
}, false);
} catch (err) {
console.log("code failed, here's the problem..");
console.log(err);
}
this
.useXpath()
// click dropdowns
.waitForElementVisible(element, 15000)
.click(element)
.useCss()
.waitForElementVisible('option[value="02To0000000L1Hy"]', 15000)
// operation we want all select boxes to perform
.setValue('option[value="02To0000000L1Hy"]', "02To0000000L1Hy")
.useXpath()
.click(element + '/option[4]');
if (typeof callback === "function") {
callback.call(self);
}
return this; // allows the command to be chained.
};
什麼我試圖做的是網頁加載完畢後,我想檢索所有的選擇框,並對其執行相同的操作。除try/catch塊中的代碼外,所有內容都正常工作。我不斷收到'[ReferenceError:window is not defined]',我不確定如何通過它。