admin管理员组文章数量:1287884
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. isPresent returns object - no matter if the element exists or not. So the question is how to check if element is present in DOM.
I will edit the question to share one learned lesson. I read the documentation also want to thanks to Nathan Thompson. isPresent() returns a promise that will resolve to whether the element is present on the page.
.prototype.isElementPresent
The code examples is a little misleading. So if you want to expect if element with a given selector exist in DOM you must use something like this:
element(by.id('someId')).isPresent().then(function(isElementVisible) {
expect(isElementVisible).to.be.true;
});
Or use chai with promises.
expect(element.isPresent()).to.eventually.be.false
However, the word "eventually" sounds unpleasant. We want to be sure not eventually sure. :)
Here can be viewed article about this question into my personal blog.
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./cucumber/cucumber-js isPresent returns object - no matter if the element exists or not. So the question is how to check if element is present in DOM.
I will edit the question to share one learned lesson. I read the documentation also want to thanks to Nathan Thompson. isPresent() returns a promise that will resolve to whether the element is present on the page.
http://angular.github.io/protractor/#/api?view=Protractor.prototype.isElementPresent
The code examples is a little misleading. So if you want to expect if element with a given selector exist in DOM you must use something like this:
element(by.id('someId')).isPresent().then(function(isElementVisible) {
expect(isElementVisible).to.be.true;
});
Or use chai with promises.
expect(element.isPresent()).to.eventually.be.false
However, the word "eventually" sounds unpleasant. We want to be sure not eventually sure. :)
Here can be viewed article about this question into my personal blog.
Share Improve this question edited Jun 14, 2015 at 10:07 Georgi Naumov asked Jun 10, 2015 at 5:40 Georgi NaumovGeorgi Naumov 4,2114 gold badges43 silver badges62 bronze badges 3-
2
Where is the
isPresent
method defined? CucumberJS or Chai? – Greg Burghardt Commented Jun 10, 2015 at 14:03 - isPresent is method from protractor API. – Georgi Naumov Commented Jun 11, 2015 at 6:26
- According to the isPresent documentation, it only tests whether or not the element exists in the document tree. Are you trying to detect whether the element is visible instead? An element can be invisible, but still "present" in the document tree. – Greg Burghardt Commented Jun 11, 2015 at 12:17
1 Answer
Reset to default 10Almost 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 remend 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
版权声明:本文标题:javascript - cucumber-js and Chai how to expect if element with given selector exist in DOM - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741331099a2372768.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论