cucumber-js and Chai how to expect if element with given selector exist in DOM

前端 未结 2 368
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 04:10

I have a problem with cucumberjs. I cannot find a way to ensure that element with given selector is presented into DOM. I\'m using cucumberjs with Chai. https://github.co

2条回答
  •  遥遥无期
    2021-01-12 05:03

    Almost all functions in Protractor return promises that will resolve into the values you actually want to test against. So if you're just trying to do something like the following, it will always fail because it's asserting on the promise object returned by isPresent:

    expect(element.isPresent()).to.be.false
    

    I would recommend using the chai-as-promised plugin for Chai to handle situations like this. It provides the eventually chain that will resolve promises for you and assert on the resulting value. The above example would look like this:

    expect(element.isPresent()).to.eventually.be.false
    

提交回复
热议问题