我正在做基于Protractor+selenium+jasmine的e2e测试。我有以下代码
describe("test google search box", function () {
function firstPart() {
console.log("before starting");
browser.get("http://www.google.com");
console.log("after running");
}
function secondPart() {
console.log("begin validation");
var searchBox = element(By.id('kw'));
**expect(searchBox.getAttribute("id")).toEqual("kw1"); //this is a intentional failure**
console.log("after validation");
}
beforeEach(function () {
return browser.ignoreSynchronization = true;
});
it("if search box exists", function () {
var flow = browser.controlFlow();
protractor.promise.all(flow.execute(firstPart), flow.execute(secondPart));
});
});
我不想执行 'console.log("验证后");'因为上一步故意失败了。这将如何完成?
感谢您的帮助。
最佳答案
如果您只想记录已解决的 promise ,请将日志记录放在 promise 中:
function log(message) {
browser.controlFlow().execute(function(){
console.log(message);
});
}
function firstPart() {
log("before starting");
browser.get("http://www.google.com");
log("after running");
}
function secondPart() {
log("begin validation");
var searchBox = element(By.id('kw'));
expect(searchBox.getAttribute("id")).toEqual("kw1"); //this is a intentional failure**
log("after validation");
}
it("if search box exists", function () {
firstPart();
secondPart();
});
输出:
Started
before starting
after running
begin validation
F
Failures:
...
关于node.js - [Protractor]如何避免验证失败后输出 "console.log",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37588392/