我的测试期望值有误
我收到此错误
[08:41:37] E/launcher - expected { Object (browser_, then, ...) } to equal true
[08:41:37] E/launcher - AssertionError: expected { Object (browser_, then, ...) } to equal true
at role.element.getText.then (/Users/jburquez/akamai/ConsoleUI/tests/e2e/console_bdd/steps/manage_agents_steps.js:114:109)
at elementArrayFinder_.then (/Users/jburquez/akamai/ConsoleUI/node_modules/protractor/built/element.js:804:32)
at ManagedPromise.invokeCallback_ (/Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:1376:14)
at TaskQueue.execute_ (/Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:3084:14)
at TaskQueue.executeNext_ (/Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:3067:27)
at asyncRun (/Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:2927:27)
at /Users/jburquez/akamai/ConsoleUI/node_modules/selenium-webdriver/lib/promise.js:668:7
at process._tickCallback (internal/process/next_tick.js:68:7)
[08:41:37] E/launcher - Process exited with error code 199
[08:41:37] '<anonymous>' errored after 1.42 min
[08:41:37] Error in plugin "gulp-protractor"
Message:
protractor exited with code 199
Details:
domain: [object Object]
domainThrown: true
这是我在台阶上的代码
Then('Validate role {editrole} is selected', { timeout:30 * 1000 }, (editrole) => {
var agentRoles = element.all(by.repeater('ctrl.roles'));
agentRoles.each((role) => {
return role.element(by.xpath(".//div[@class='md-whiteframe-1dp outset inset']/md-checkbox")).getText()
.then((roleSelected) => {
if (editrole === roleSelected) {
expect(element(".//div[@class='md-whiteframe-1dp outset inset']/md-checkbox").isSelected()).to.be.equal(true);
}
});
});
});
我想做的是验证是否检查了一个元素,因此阅读另一条建议,我看到.isSelected()
是对此的最佳选择,但我不确定为什么会引发此错误。
希望你能帮助我!
答案 0 :(得分:1)
您似乎正在尝试将对象与布尔值进行比较。 您必须兑现承诺,否则必须使用“最终”(如果您使用“ chai”作为断言库)。下面的示例:
expect(element(".//div[@class='md-whiteframe-1dp outset inset']/md-checkbox").isSelected()).to.eventually.equal(true);
或
element(".//div[@class='md-whiteframe-1dp outset inset']/md-checkbox").isSelected().then(function (select) {
expect(select).to.be.true;
});
花点时间找出正确地将诺言与诺言结合使用的方法。
答案 1 :(得分:0)
我建议查看异步/等待语法。并且您也可以尝试在此处使用browser.wait(ExpectedConditions.elementToBeSelected)
Then('Validate role {editrole} is selected', { timeout:30 * 1000 }, async (editrole) => {
const agentRoles = element.all(by.repeater('ctrl.roles'))
expect(await agentRoles.count()).not.to.be(0)
await browser.wait(ExpectedConditions.elementToBeSelected(
element(by.cssContainingText('div.md-whiteframe-1dp.outset.inset md-checkbox', editrole))
), 10000, `Expected ${editrole} to be selected`);
});