【问题标题】:Expected and Actual Values in Failed Protractor Test Cases失败的量角器测试用例中的预期值和实际值
【发布时间】:2017-09-26 19:17:12
【问题描述】:

我最近安装了jasmine-spec-reporter 包,以便在执行测试套件期间生成更详细和有用的日志记录。

我希望能够为失败的测试用例记录 expected 和 actual 值,并且想知道我是否需要以 expect(someCondition).toEqual(true); 的形式明确声明以便我看到这些值。

例如,我有如下函数:

it('should log in', function(done) {
    var customerNameElement;

    customerNameElement = element.all(by.xpath('some_xpath')).first();

    core.infoMessage(browser, JSON.stringify(params, undefined, 4));
    login.login(browser, undefined, undefined, getWaitTime())
        .then(function() {
             return browser.wait(protractor.ExpectedConditions.and(
                 function() { return core.isUnobscured(browser, customerNameElement); 
        }, protractor.ExpectedConditions.elementToBeClickable(customerNameElement)), getWaitTime());
    })
    .catch(fail)
    .then(done);
});

我仍然可以将故障记录到控制台,但不是以我想要的形式。 jasmine-spec-reporter 是否处理此问题,还是我必须在每个测试用例中添加上面的语句?

另外,.catch() 中的 fail 关键字是否有任何我可以利用的属性?它来自:

// Jasmine 2.5.2 的类型定义 // 项目:http://jasmine.github.io/

谢谢

【问题讨论】:

  • 是否已经为失败的测试用例记录了预期值和实际值?即expected true to be false...expected 1 to equal 2等。
  • @Gunderson,这是我返回的一个示例:× should display the text element - Failed: No element found using locator: By(xpath, some_xpath) 但话又说回来,xpath 可能没有预期值。想法? (这是另一个测试用例,不是上面列出的)
  • 嗯,这是一个 ElementFinder 错误,它描述了您面临的问题(该元素不存在,因此它无法执行您尝试执行的任何操作)。我不明白你到底想要什么来代替那个错误?
  • 我认为某些it 函数不会产生expected 和actual 值,例如上面的那个。对于xpath 错误,我同意你的观点,抛出的错误是应该产生的。有没有办法将Expected 0 to be 1 更改为Expected false to be true?

标签: jasmine protractor e2e-testing


【解决方案1】:

您可以尝试在 protractor_config 文件中添加以下内容:

让 SpecReporter = require('jasmine-spec-reporter').SpecReporter;

exports.config = { // 你的配置在这里 ...

onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter({
规格:{
displayStacktrace: true

}
}));
} }

另外,在jasmineNodeOpts部分添加打印功能
茉莉花节点选择:{ ... 打印:函数(){} }

【讨论】:

    猜你喜欢
    • 2022-01-23
    • 2012-08-17
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-28
    • 2020-10-09
    • 2021-07-29
    相关资源
    最近更新 更多