admin管理员组文章数量:1203808
I want to verify that whether certain text exists in a string or not (using protractor).
In my case, the following code:
element(by.css('h1.text-center')).getText();
will result to:
ArrowGrey Slim Fit Formal Trouser -1 (Size - X)
Now, I want to verify that whether the string ArrowGrey Slim Fit Formal Trouser
is contained in the above text or not.
Please suggest!
I want to verify that whether certain text exists in a string or not (using protractor).
In my case, the following code:
element(by.css('h1.text-center')).getText();
will result to:
ArrowGrey Slim Fit Formal Trouser -1 (Size - X)
Now, I want to verify that whether the string ArrowGrey Slim Fit Formal Trouser
is contained in the above text or not.
Please suggest!
Share Improve this question edited Dec 4, 2015 at 15:07 alecxe 474k126 gold badges1.1k silver badges1.2k bronze badges asked Dec 4, 2015 at 10:47 Swati KhandelwalSwati Khandelwal 1952 gold badges2 silver badges14 bronze badges3 Answers
Reset to default 14There are multiple ways to have a partial string match using jasmine
:
expect(text).toContain("ArrowGrey Slim Fit Formal Trouser");
expect(text).toMatch("ArrowGrey Slim Fit Formal Trouser");
expect(text).toStartWith("ArrowGrey Slim Fit Formal Trouser");
where toStartWith()
is coming from jasmine-matchers
.
Thanks @winlinuz for your help. I myself found the solution to it. Using toContain would work.
expect(element(by.css('h1.text-center')).getText()).toContain('ArrowGrey Slim Fit Formal Trouser');
Above code works perfectly!
You can assert this way:
expect(element(by.css('h1.text-center')).getText()).toEqual('ArrowGrey Slim Fit Formal Trouser');
本文标签: javascriptVerify the part of text using protractorStack Overflow
版权声明:本文标题:javascript - Verify the part of text using protractor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738664470a2105619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论