【问题标题】:How to fail a test if element is not present using Protractor如果使用量角器不存在元素,如何使测试失败
【发布时间】:2021-05-19 07:11:39
【问题描述】:

如果使用量角器不存在元素,我需要测试失败。在这里,我已经实现了代码。当预期条件超出我预期的条件时,它将失败。不幸的是,测试用例通过了。任何人都可以建议我是否错过了什么。

crossAttribute.isPresent().then(function (deleteAttribute) {
                if(deleteAttribute){
                    crossAttribute.click();
                }else{
                    console.log('Cross is not present to delete attribute') 
                }
                expect(crossAttribute).toBeTruthy;
            });

【问题讨论】:

    标签: javascript protractor


    【解决方案1】:

    这将很容易工作

    let attributeIsPresent = await crossAttribute.isPresent()
    if (attributeIsPresent) {
      await crossAttribute.click();
    } else {
      expect(false).toBe(true)
    }
    

    您的代码不起作用,因为您使用了错误的变量 crossAttribute 而不是 deleteAttribute

    【讨论】:

    • Sergey,按照上面的例子,我使用了同样的方法,它抛出了一个错误 - Error: Cross is not present to delete attribute 。但它不是继续执行,而是中止。你能建议继续执行吗?
    • 这不是你想要的吗?
    • 或者您想继续测试用例,但将其标记为失败?
    • Sergey,是的,想继续测试用例,但只需将其标记为失败
    • 通过添加 expect(false).toBe(true) ,抛出错误并继续执行。
    猜你喜欢
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 2013-12-14
    • 2012-11-13
    • 2016-07-28
    相关资源
    最近更新 更多