Selenium For Beginners

Share this post

User's avatar
Selenium For Beginners
Do not use dependent tests
Tests

Do not use dependent tests

Alex Siminiuc's avatar
Alex Siminiuc
May 16, 2023
∙ Paid

Share this post

User's avatar
Selenium For Beginners
Do not use dependent tests
Share

The following tests are focused on verifying that results can be sorted in a specific way:

@Test
public void canSearchByKeywordTest() {
   HomePage homePage = new HomePage(driver);

   homePage.open();
   Assert.assertTrue(homePage.isDisplayed(), “home page is not displayed!”);

   ResultsPage resultsPage = homePage.search(keyword);

   Assert.assertTrue(resultsPage.isDisplayed(), 
        “results page is not displayed!”);
}

@Test(dependsOnMethods = {"canSearchByKeywordTest"})
public void canSortResultsByAuthorTest() {
   resultsPage.sortResultsByAuthor();

   Assert.assertTrue(resultsPage.url().contains("sort=author"));
   Assert.assertTrue(resultsPage.areResultsSortedByAuthor());
}

@Test(dependsOnMethods = {"canSearchByKeywordTest"})
public void canSortResultsByTitleTest() {
   resultsPage.sortResultsByTitle();

   Assert.assertTrue(resultsPage.url().contains("sort=title"));
   Assert.assertTrue(resultsPage.areResultsSortedByTitle());
}

@Test(dependsOnMethods = {"canSearchByKeywordTest"})
public void canSortResultsByPublicationDateTest() {
   resultsPage.sortResultsByPublicationDate();

   Assert.assertTrue(resultsPage.url().contains("sort=published_date"));
   Assert.assertTrue(resultsPage.areResultsSortedByPublicationDate());
}

All tests are short and focused on verifying one thing only.

They are all easy to understand.

There is no code duplication.

They are fast.

And, they are all incorrect.

Keep reading with a 7-day free trial

Subscribe to Selenium For Beginners to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Alex Siminiuc
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share