Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify the part of text using protractor

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!

like image 311
Swati Khandelwal Avatar asked Dec 04 '15 10:12

Swati Khandelwal


People also ask

How do you compare text in a protractor?

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.

How do you make a protractor text?

WebElement. prototype. getText. Get the visible innerText of this element, including sub-elements, without any leading or trailing whitespace.


1 Answers

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.

like image 56
alecxe Avatar answered Sep 17 '22 09:09

alecxe