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!
Another way is to schedule the comparison at the protractor control flow so it will be executed after all values are available. var oldValue,newValue; element(by.id('foundNumber')). getText(). then(function(text){oldValue=text}) element(by.
WebElement. prototype. getText. Get the visible innerText of this element, including sub-elements, without any leading or trailing whitespace.
There 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With