Usually the pages under test have dynamic content. For example we are testing news page and assert that first news title is “Puppetry 3 is out”. But as soon as anybody adds a new story our tests are to fail. What we can do is to use
page.assignVar method to extract actual content (e.g. news title) from the page and make assertions on it. Consider the following example:
News page has search filtering by tags. If one click on a tag the news listing gets filtered for the stories associated with the tag. So we create a variable
VAR_ARTICLE1_TITLE, which takes-in HTML of
ARTICLE1_TITLE target that corresponds to the element representing title of the first story.
We send click on a tag, waiting until the request for listing update complete and assert that the first story title (
ARTICLE1_TITLE) changed, meaning the news list updated.
Similarly you can make your test case waiting until a particular image fully loaded. So you extract image URL from
src attribute and wait for response including that URL.
If the endpoint has redirections, the response will have URL different from one set with src attribute and therefore the approach won’t work.