Self-Verifying pages in Selenium 1.0

Reading Time: 4  min

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.

Stay Updated
Please enable JavaScript in your browser to complete this form.
LinkedIn
Share
Copy link
URL has been copied successfully!

Other stories you may enjoy...

Healthcare Apps and the Need for Security

One of the most exciting areas in tech right now promises to be “the most personal” ever. A key aspect of making wearable devices like the Apple Watch personal is through...

Developing an App for the 2020 General Election?

Here is a thought: With the UK General Election having just finished, could the next one in 2020 be the first to use a mobile app to allow people to vote? The polling...

Be honest. Describe the state of your test cases.

“There’s some dead wood in there.” “Hmmm…. Someone really needs to clean them up.” “A little outdated.” For those reading this in the northern hemisphere,...