What do test automation and cooking have in common? Recipes

Alex Siminiuc
Jan 26 · 3 min read

Cooking and test automation are both about following recipes.

Let’s say that you want to prepare a delicious omelet for your family, similar to the one that you ate last Sunday at that fancy restaurant. You remember that it was made with eggs, cheese, red peppers, mushrooms and onions.

You have never done this type of omelet before.

You have 2 choices.

You can try it out by being creative.

Or follow a recipe such as this one:

  1. Whisk eggs, Cheddar cheese, Parmesan cheese, salt, black pepper, garlic powder, and red pepper flakes together in a bowl.
  2. Heat olive oil in a nonstick skillet over medium heat
  3. Cook and stir mushrooms and onion until tender, 4 to 5 minutes
  4. Add spinach
  5. Cook until spinach wilts, 3 to 4 minutes.
  6. Pour in egg mixture
  7. Swirl pan around to evenly distribute egg mixture.
  8. Cook until egg is fully cooked and set in the middle, 5 to 10 minutes.
  9. Cut into wedges.

I can almost taste it :)

Which one is better?

The second one, for sure.

It takes about 15 mins to prepare and another 15 mins to make but the result will be amazing.

And the secret is in following the recipe step by step, being patient and having good ingredients.

OK, before you get completely bored, how can this be similar to test automation?

It is useful to remember that recipe has synonyms such as method technique, formula, prescription, procedure, plan and blueprint.

And in Selenium test automation, we have these everywhere.

For example, an automated test should follow a recipe:

  • it should test 1 thing only
  • it should use page or component objects instead of API classes and objects
  • it should have 4 four phases: fixture setup, exercising the system under test, result verification, and fixture teardown
  • it should be independent of other tests, of the browser, of the environment

How about page objects?

Page objects have their own recipes:

  • have the locators defined in the page class
  • save the driver instance in a class member in the constructor
  • have public methods that implement user interactions
  • have private methods that are used by the public methods
  • rely on the classes of the automation framework for any common-sense functionality
public class LoginPage {  private WebDriver driver;  private By usernameLocator = By.name(“uid”);  private By passwordLocator = By.name(“password”);  private By titleLocator = By.className(“title”);  private By loginLocator = By.name(“btnLogin”);  
public Login(WebDriver driver){
this.driver = driver; }
public String title(){
return driver.findElement(titleLocator).getText();

public MainPage loginWith(String userName,String password){
driver.findElement(usernameLocator).sendKeys(userName); driver.findElement(passwordLocator).sendKeys(password); driver.findElement(loginLocator).click();
return new MainPage(driver);

How about synchronizing the automation code with the site?

There are a few procedures that can help here. For the Selenium Webdriver API, you could:

There are recipes for basically anything that you may need in your automation projects. Even for running your tests in CI/CD.

Test automation and development are mostly about following patterns, recipes, procedures than about creating your own. Creating your own recipes is rarely a better idea than using existing ones because the latter recipes are usually created by developers with more skill, experience and knowledge than you. The existing recipes are also still here because they stood the tests of many projects, developers, industries and time.

Test automation and development are also about using existing APIs, components, classes instead of creating your own for the same reasons from the previous paragraph.

Following recipes and reusing components/APIs is the correct thing to do. Stop re-inventing the wheel or being creative when there is no need for it.

But, what if a class of a library does not do exactly what you need? Should you create your own then?

No. Instead of creating your own class, you should extend the existing one and redefine the behaviour that does not apply for your case.

Alex Siminiuc

Written by

Blogs about Selenium and Java at https://seleniumjava.com.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade