Getting attributes values and comparing the values from other attributes (values have line break in HTML) UseCase: Price comparison

Viewed 134

I am a big fan of Karate and exploring Karate UI for the end-to-end testing but stuck on one simple thing which is finding element by attribute where value has a line break in HTML and assertion always fails.

When I use And match attribute('#eg01SubmitId', 'type') == 'submit' And match text('.myClass') == 'Class Locator Test'

Use case: Comparing Prices (Getting price quotes from elements in one application and comparing it with price quotes in other applications) enter image description here

Like Car deals quotes enter image description here

enter image description here

What is the best strategy in this use case and how I can implement this in Karate?

1 Answers

Just call trim() on any string to remove leading and trailing white-space.

For example:

* def before = '  hello world\n  '
* def after = before.trim()
* match after == 'hello world'

Also note that waitForText() is designed to do a string "contains" match by default.

You can also find-and-replace line feeds. Any thing is possible, you just need to know the Java methods (on String) you can call.

* def before = 'hello\nworld'
* def after = before.replace('\n', ' ')
* match after == 'hello world'
Related