How do you go from manual test case to Selenium automated test?

Alex Siminiuc
Oct 6 · 6 min read
Photo by Markus Spiske on Unsplash

Assume that you are the manual tester for Vancouver Public Library.

The site to be tested is https://www.vpl.ca.

For your testing, you created a regression testing suite that covers all pages and features of the website.

One of the most important pages of the site is the home page. This is where people come first to check information about the library and search for materials to rent, books, magazines, dvds or cds.

The most important test case for the home page is about the search feature.

It validates if the search feature works as expected so people can use it.

The manual test case for the search feature may be as follows:

  1. open the site in the browser
  2. search for keyword
  3. check that results are displayed

The test case is pretty simple, just 3 steps to follow to complete it.


If you want to automate this test case with an automation framework (such as Selenium WebDriver) and a programming language (such as Java), how do you do it?

Where do you start?

What are the steps to go through?

This is what this article is about.

It explains the steps needed for changing the manual test case to a format that can be used right away for writing the automated testing code.


The first thing to do is to make the manual test case less vague:

  1. open the site in the browser
  2. search for keyword
  3. check that results are displayed

Which site is it about? Which browser? Which keyword?

We need to add this info to the test case:

  1. open the site (https://www.vpl.ca) in the browser (Chrome latest version)
  2. search for keyword (Windows)
  3. check that results are displayed

This is a step in the correct direction.

Next, we should keep in mind that the computer needs to be told what to do and how to do it in great detail.

The test case, as of now, is made from high level tasks such as searching for keyword and checking if results are displayed.

We need to breakdown the tasks in such detail so it is clear what the tasks do and how they do it.


This means determining

  1. the pages that the test case uses
  2. for each page
  3. what actions happen on the page
  4. what are the steps of each action
  5. what are the elements needed for each step
  6. what validations are needed for the page

Let’s start with the beginning.

Pages

The manual test case starts on the home page of the site. On this page, a search is done with a keyword. The outcome of the search is that the results page is displayed with results that match the keyword.

So, the manual test case uses 2 pages:

  1. Home Page
  2. Results Page

We can update the test case with the pages:

  1. open the home page of the site (https://www.vpl.ca) in the browser (Chrome latest version)
  2. in the home page, search for the keyword (Windows)
  3. in the results page, check that results are displayed

We have the pages in the manual test case.

Now, we should work on the actions that happen in each page.

Actions for each page

First, about the search in the home page.

What does it mean to search in the home page?

It means typing a keyword in the search text box, followed by clicking the search button and then waiting for the results page to be loaded.

For the results page, we do not have any actions but a verification (check that results are displayed).

So the manual test case becomes:

  1. open the home page of the site (https://www.vpl.ca) in the browser (Chrome latest version)
  2. in the home page, type the keyword (Windows) in the search text box
  3. in the home page, click the search button
  4. wait until the results page is displayed
  5. in the results page, check that results are displayed

The manual test case is more detailed than before.

Let’s continue with the actions that happen in the home page.

What are their steps?

Steps of each action

The first one is “type the keyword in the search text box”.

Before typing the keyword, we need to find the search text box. After the search text box is found, we can clear the existing value (if any) and then type the keyword in the text box.

Same for the second action, “click the search button”.

Before clicking the button, we need to find it first.

Great, lets update the manual test case:

  1. open the home page of the site (https://www.vpl.c.a) in the browser (Chrome latest version)
  2. in the home page, find the search text box
  3. clear the existing value from the search text box
  4. type the keyword (Windows) in the search text box
  5. in the home page, find the search button
  6. click the search button
  7. wait until the results page is displayed
  8. in the results page, check that results are displayed

The next action is on the results page, “wait until the results page is displayed”.

What does it mean that results page is displayed?

How do we know that results page is displayed?

Validations for each page

There are a few ways of doing this:

  1. we could check that the page url is correct after results page is loaded
  2. we could verify that the page title is correct
  3. we could validate that an element that is always in the results page is displayed

For simplicity, let’s go with option 2, verifying that the page title is correct.

The manual test case changes slightly with the latest information:

  1. open the home page of the site (https://www.vpl.c.a) in the browser (Chrome latest version)
  2. in the home page, find the search text box
  3. clear the existing value from the search text box
  4. type the keyword (Windows) in the search text box
  5. in the home page, find the search button
  6. click the search button
  7. check that the results page’s title is equal to “Search | Vancouver Public Library | BiblioCommons”
  8. in the results page, check that results are displayed

We can do the same title check for the home page.

  1. open the home page of the site (https://www.vpl.c.a) in the browser (Chrome latest version)
  2. check that the home page’s title is equal to “Vancouver Public Library”
  3. in the home page, find the search text box
  4. clear the existing value from the search text box
  5. type the keyword (Windows) in the search text box
  6. in the home page, find the search button
  7. click the search button
  8. check that the results page’s title is equal to “Search | Vancouver Public Library | BiblioCommons”
  9. in the results page, check that results are displayed

Steps 2, 8 and 9 of the manual test case are validations. In test automation language, they are called also assertions.

What’s next?

The validation from the results page.

To validate that there are results in the page, we have to find the element in the page that includes the result count.

Then, we extract the count from the value of this element.

And finally, we compare the count with 0:

  1. open the home page of the site (https://www.vpl.c.a) in the browser (Chrome latest version)
  2. check that the home page’s title is equal to “Vancouver Public Library”
  3. in the home page, find the search text box
  4. clear the existing value from the search text box
  5. type the keyword (Windows) in the search text box
  6. in the home page, find the search button
  7. click the search button
  8. check that the results page’s title is equal to “Search | Vancouver Public Library | BiblioCommons”
  9. in the results page, find the results count element
  10. get the value of the results count element
  11. extract the count from the results count element value
  12. check that the count is positive

What we have now is not the initial manual test case.

This is the automation test case that will be used as starting point for writing the code.

Because the automation test case explains what needs to be done in detail, the code should be not difficult to write.

How should the code look like?

openHomePage();

Assert.AreEqual(homePageTitle(), “Vancouver Public Library”);’

WebElement searchBox = findSearchBox();

searchBox.clear();

searchBox.sendKeys(“Windows”);

WebElement searchButton = findSearchButton();

searchButton.click();

Assert.AreEqual(resultsPageTitle(), “Search | Vancouver Public Library | BiblioCommons”);

WebElement resultsCountLabel = findResultsCountLabel();

String resultsCountText = resultsCountLabel.getText();

int count = getCount(resultsCountText);

Assert.IsTrue(count > 0);

It does not matter that this code does not work yet.

We just wanted to write the code in a way that matches the automation test case as much as possible.

We will focus on how each part of the code should be implemented next time.

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