[Protractor]验证失败后如何避免“console.log”输出

时间:2016-06-02 09:51:53

标签: node.js protractor

我正在进行基于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(“验证后”);'因为上一步故意失败。这将如何完成?

感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

如果您只想记录已解决的承诺,请将记录放在承诺中:

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:
...

答案 1 :(得分:0)

即将推出的jasminewd功能 - 用于量角器的茉莉花。但是目前你不能在没有黑客的情况下做得很好 -

https://github.com/angular/protractor/issues/3234