In the previous chapter, you learned how to automate a web page using basic Selenium WebDriver code. In this chapter, you will learn how to organize and structure your UI test code to make it easier to extend and easier to maintain.
Thus far we’ve explored the WebDriver API using very simple code samples. These examples work well to illustrate the various WebDriver methods, but you wouldn’t want to write code like this for real-world automated tests. For example, to log on to the Frequent Flyer website, you used the following code:
@When("he/she logs on with a valid username and password") public void logsOnWithAValidUsernameAndPassword() { WebDriver driver = WebTestSupport.currentDriver(); driver.get("http://localhost:3000"); driver.findElement(By.linkText("Login")).click(); driver.findElement(By.id("email")).sendKeys(frequentFlyer.email); driver.findElement(By.id("password")).sendKeys(frequentFlyer.password); driver.findElement(By.id("login-button")).click(); }