The inspiration for this post is Patrick Welsh’s original post as well as code about the Self-Verifying pages in Selenium RC. While the actual pattern is very well explained in Patrick’s post-I thought I might share some experience as well as changes that I did.I have been using the self-verifying page pattern since about 2 months now and it’s been working pretty well for me and the team.To give a brief primer-If you are using Selenium RC,you might be writing the testcase something like
login.setusername(“xxx”);
login.setpassword(“yyy”);
login.submit();
assertTrue(landingPage.isLoaded())
The above is correct but it makes the test code clunky as well it relies on the test case writer to verify for some pages vs others.Not exactly a scientific solution.This is where Patrick’s pattern comes to help,which abstracts out the expected Page logic to the Page instead of the test.So the above code will look like
login.setusername(“xxx”);
login.setpassword(“yyy”);
landingPage=login.submit();
The constructor for landingPage object takes care of waiting for the landingPage to load.So it’s all good upto here.It also helped me in mapping my Page classes to the application pages more effectively.
But it still has some drawbacks.
For e.g-If there is a scenario where entering incorrect password will just reload the login page.Now if you are in Java world-you will need to write two very similar methods which do the same action but return a different class depending on the intended behavior.Depending on your workflow this can get quite cumbersome and difficult in a environment where the folks who write the Page classes are different than the one who write Test Classes.
public LandingPage submit(){
//click button
}
public LoginPage submit(){
//click button
}
Another issue I have with this pattern is that you only set one verification level.For e.g I verify that the landing page has loaded by making sure that some locator is present for an element.There might be a case where this verification is not sufficient.I would want to verify presence of more than one locators.I am sure this can be achieved with some more code hacking.