Do you need a test case if you have a Selenium test for it?
In automation projects, everything starts with a test case:
open Home Page of the site
check that Home Page is displayed
search by keyword in Home Page
check that Results Page is displayed after searching
get pagination info from Results Page
check that pagination info contains "1 to 10"
The test case is short, clear and focused on 1 thing.
It verifies that the pagination label shows “1 to 10” after executing a search.
This test case can be automated as follows:
@Test
public void searchReturnsResults() {
HomePage homePage = openHomePage();
assertTrue(homePage.isDisplayed(), "home page is not displayed!");
ResultsPage resultsPage = homePage.searchBy(KEYWORD);
assertTrue(resultsPage.isDisplayed(), "results page is not displayed!");
assertContains(resultPage.paginationInfo(), "1 to 10",
"pagination info does not include 1 to 10!");
}
The automated test maps 1 to 1 to the test case.
It is also short, clear and focused on 1 thing.
It is written in a way that anyone can understand what it does.
We have now a manual test case that is implemented by an automated test.
Usually, the link between the 2 is done with an annotation as follows:
@Test
@TestCaseId("TC211")
public void searchReturnsResults() {
HomePage homePage = openHomePage();
assertTrue(homePage.isDisplayed(), "home page is not displayed!");
ResultsPage resultsPage = homePage.searchBy(KEYWORD);
assertTrue(resultsPage.isDisplayed(), "results page is not displayed!");
assertContains(resultPage.paginationInfo(), "1 to 10",
"pagination info does not include 1 to 10!");
}
After the automated test finishes to run, the automation framework updates the status of the test cases so that it matches the status of the automated test.
In time, the site functionality may change so changes will be required for the test case and for the automated test.
If the automated test is executed daily, it will fail as soon as the site is different.
At this moment, the automated test is updated so that it does not fail any longer.
Since the automated test is mapped to the test case, the test case should be updated as well.
But what is the benefit of doing this?
What is the benefit of having both the test case and the automated test when they basically says the same thing?
Since the test case is automated, no one is going to execute it manually any longer.
It also has to be modified to stay in sync with the automated test.
Isn’t it simpler to just not have the test case and only keep the automated test?
The reasons are simple:
the automated test is executed all the time (manual test case is not)
the automated test is kept updated all the time (manual test case may be not updated, the only reason to update it is to keep it in sync with the automated test)
having only the automated test removes the need of having framework code that updates the manual test case with the status of the automated test
What do you think?
Thanks for reading.