我是Javascript(Nightwatch JS)和一般编程的新手。
我有一个问题,在我的If,Else If,Else测试用例中,不继续进行Else If语句。
我认为这是因为我的IF语句中的条件是断言(.expect.element();)
我想知道是否有人可以给我一些关于如何处理我的IF语句的指示。
基本上我想验证:
If (checkbox is un-clickable) {
run set code;
} Else if (this checkbox is clickable) {
run set code;
} Else {
.end();
}
这是我的样本测试。
' Uninstall Missions Module ' : function(uninstallModule) {
uninstallModule
.url('http://drupal8.develop:8091/admin/modules/uninstall')
.setValue('#edit-text', "Missions")
.pause(800);
uninstallModule.expect.element('#edit-uninstall-missions').to.be.present;
uninstallModule.waitForElementVisible('//*[@id="system-modules-uninstall"]/table/tbody/tr[31]/td[3]/div/div/ul/li/a', 1000, false);
if (uninstallModule.expect.element('#edit-uninstall-missions').to.not.be.enabled) {
uninstallModule.expect.element('body').text.to.contain('Remove mission entities')
uninstallModule
.url('http://drupal8.develop:8091/admin/modules/uninstall/entity/mission')
.verify.urlEquals('http://drupal8.develop:8091/admin/modules/uninstall/entity/mission');
uninstallModule.expect.element('body').text.to.contain('Are you sure you want to delete all mission entities?');
uninstallModule.click('xpath', '//*[@id="edit-submit"]');
uninstallModule
.pause(10000)
.verify.visible("body > div.layout-container > main > div.region.region-highlighted > div > h2", "All mission entities have been deleted.");
} else if (uninstallModule.expect.element('#edit-uninstall-missions').to.be.enabled) {
uninstallModule
.url('http://drupal8.develop:8091/admin/modules/uninstall')
.setValue('#edit-text', "Missions");
uninstallModule.click('#edit-uninstall-missions');
uninstallModule.pause(800);
uninstallModule.verify.urlEquals("http://drupal8.develop:8091/admin/modules/uninstall/confirm");
uninstallModule.click('xpath', '//*[@id="edit-submit"]');
uninstallModule.pause(1000);
uninstallModule.verify.visible('body > div.layout-container > main > div.region.region-highlighted > div.messages.messages--status', "The selected modules have been uninstalled.");
} else {
uninstallModule.end();
}
},
}

答案 0 :(得分:4)
有关夜间守望(以及其他e2e测试框架)的两件事需要了解
使用夜视仪,您可以使用 getAttribute 来阅读所需的值:
client.getAttribute('#edit-uninstall-missions', 'enabled', result => {
// I'm not sure about the type returned in result.value
// you can test it and adjust
const enabled = result && result.value !== "false"
&& result.value !== false;
if (enabled){
// Continue your test here
} else {
// Another test here
}
});
答案 1 :(得分:0)
这就是我的所作所为。
uninstallModule.getAttribute('#edit-uninstall-missions', 'disabled', function(results) {
console.log(results.value);
if (results.value == "true") {
console.log("It's true bro");
} else if (results.value != "true") {
console.log ("It's null");
} else {
console.log("It's Neither");
}
});