O'Reilly logo

Selenium 2 Testing Tools Beginner's Guide by David Burns

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – moving Selenium steps into private methods to make tests maintainable

Imagine that you just need to test one page on your site and you have quite a few tests for this page. A lot of the tests will be using the same code over and over again. This can be quite annoying to maintain if something changes on the page meaning we have to go through all the tests to fix this one issue. The way that we will fix this is to refactor the tests so they are simpler and therefore easier to read.

  1. Let us create a number of tests as follows:
     @Test public void shouldCheckButtonOnChapter2Page(){ selenium.get("http://book.theautomatedtester.co.uk"); selenium.findElement(By.link, "Chapter2").click(); Assert.assertEqual(selenium.findElements(By.id"but1").getSize(), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required