I have tried using below syntax:
page.body.index('Name') < page.body.index('Phone')
But problem is that if there are multiple strings with same content on same page, then unable to check the index of particular string.
For ex. Page is having content 'Name' and 'Phone' 3 times, then how specific content's order can be verified.
Please suggest if we can use CSS syntax for the same or any other better way.
In feature spec, above issue of checking the sequence of elements on full page is solved as below:
Map all the elements on page, insert it into an array and match it with expected array of elements. In expected array, store elements in order as per the requirement.
Below is the solution for above:
expected_array = [ 'Name', 'Phone', 'Email' ]
page.all.map(&:text).should eq expected_array
Also, for particular elements like headers, it can be done using specific css class as below:
page.find('.h4').map(&:text).should eq expected_array
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