Check a piece of text with a protractor

I want to check if any text exists in a string or not (using a protractor).

In my case, the following code:

element(by.css('h1.text-center')).getText();

will result in:

ArrowGrey Slim Fit Formal Trouser -1 (Size - X)

Now I want to check if the string is ArrowGrey Slim Fit Formal Trouserin the above text or not.

Please suggest!

+4
source share
3 answers

There are several ways to partially match strings with 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()comes fromjasmine-matchers .

+7
source

Thanks @winlinuz for your help. I myself found a solution. Using toContain will work.

expect(element(by.css('h1.text-center')).getText()).toContain('ArrowGrey Slim Fit Formal Trouser');

Above code works fine!

+1

:

expect(element(by.css('h1.text-center')).getText()).toEqual('ArrowGrey Slim Fit Formal Trouser');
0

Source: https://habr.com/ru/post/1618566/


All Articles