admin管理员组文章数量:1416322
I need to do something like:
expect(theElement.hasText()).toBe(true);
Do you know how can I do it?
I know that there is a "getText" function in protractor, but, how can I use it? Should I do?:
expect(theElement.getText().lenght > 0).toBe(true);
Thanks!
I need to do something like:
expect(theElement.hasText()).toBe(true);
Do you know how can I do it?
I know that there is a "getText" function in protractor, but, how can I use it? Should I do?:
expect(theElement.getText().lenght > 0).toBe(true);
Thanks!
Share Improve this question edited May 26, 2015 at 13:15 alecxe 475k127 gold badges1.1k silver badges1.2k bronze badges asked Apr 6, 2015 at 18:43 Broda NoelBroda Noel 2,0361 gold badge25 silver badges39 bronze badges2 Answers
Reset to default 7I find jasmine-matchers
library very helpful in terms of additional useful matchers. toBeNonEmptyString()
is a perfect fit here (also notice how readable it is):
expect(theElement.getText()).toBeNonEmptyString();
FYI, here is the underlying implementation:
matchers.toBeNonEmptyString = function() {
return matchers.toBeString.call(this) &&
this.actual.length > 0;
};
It is quite reliable: it checks the type and the length.
If you want to check length and don't want to use toBeNonEmpty, then check it in the callback
element(by.id('element_id')).getText().then(function (data) {
expect(data.length).toBeGreaterThan(0);
});
本文标签: javascriptHow to check if quotshould has textquot in JasmineStack Overflow
版权声明:本文标题:javascript - How to check if "should has text" in Jasmine? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745250471a2649794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论