node.js - [Protractor]如何避免验证失败后输出 "console.log"

标签 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("验证后");'因为上一步故意失败了。这将如何完成?

感谢您的帮助。

最佳答案

如果您只想记录已解决的 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/

相关文章:

node.js - 如何使用npm脚本重命名文件

angularjs - 使用 AngularJS 和 NodeJS、MongoDB 进行动态 URL 查询

html - 同一类元素的 Protractor 定位器

angularjs - 在 Protractor 中使用占位符查找元素?

javascript - 复杂键 - 按第一个键过滤并仅按第二个键排序

node.js - @angular/cli@8.3.19 安装后脚本失败

angularjs - Angular : how to check variable in scope without ng-bind and ng-model? 中的 Protractor 测试

javascript - Protractor 测试用例无法在 Firefox 上运行

Protractor - 套件中规范之间的 Action

node.js - socket.io redis 和内存泄漏