How to create dependency between testcases in Selenium

I am sure you must be confused with Title like How to create a dependency between test cases in Selenium but in this post we will see this through example.

In real time, you will come across many situation where you have to create test cases which are dependent on the previous test case.

Take an example I have 3 test case.

First one which verify login credential and start application
Second test case check some validation  or do some activity
Third test case simply just for log-out activity.

If my first test case does not work (failed) that it does not make any sense to run second and third test case so in these type of scenarios you can use dependency between test case.

How can I do this?

TestNG already comes with this features so you can use the same with @Test annotations

How to create dependency between test cases in Selenium


It means this test case name testAccount depends on test case whose name is loginTestCase so until loginTestCase will not execute successfully this test case won’t execute so if loginTestCase will pass this test case will execute and if loginTestCase will fail then this test case won’t execute and runner will skip this test cases and this test case will come under skip test cases.

Let’s implement the same


In the above scenario if testLogin will pass then only testAccount will execute and testLogout will only execute of testLogin and testAccount will  be executed

but if testLogin will fail due to some error or exception the testAccount will not be executed and this test case will skip and testLogout is dependent on testLogin and testAccount so now this will also come into skipped category

Let’s implement again



FAILED: testLogin
java.lang.AssertionError: expected [Selnium] but found [Selenium]
SKIPPED: testAccount
SKIPPED: testLogout

Default test
Tests run: 3, Failures: 1, Skips: 2

Default suite
Total tests run: 3, Failures: 1, Skips: 2


Skip Test


For More updates Learn Automation page

For any query join Selenium group- Selenium Group

Comment below for any clarification





  1. Rajesh Kabra
  2. Prashant