How does dependency work in testNG?

0 votes
Dependency in testNG is good when I have to make a test case dependent on some other test case.

Can someone explain me with an example as how it works?
Jan 3 in Selenium by Nitesh
• 2,910 points
25 views

1 answer to this question.

0 votes

There are times when you need to run a test case when some other test case has executed. This scenario is attained by using dependency in testNG.

TestNG allows you to specify dependencies either with annotations or in XML.

TestNG allows you to specify dependencies either with:

  • Using attribute dependsOnMethods in @Test annotations.
  • Using attribute dependsOnGroups in @Test annotations.
Here is a brief example:-
package testNG;
import org.testng.annotations.Test;
public class Test 
{
  @Test (dependsOnMethods = {"h2"})
  public void h1() 
  {
  System.out.println("test case 1");
  }
  @Test
  public void h2() 
  {
  System.out.println("test case 2");
  }
}



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="softwaretestingmaterial">
<test name="testngTest">
<classes>
<class name="testNG.Test" />
</classes>
</test>
</suite>

Hope this helps.

answered Jan 3 by Shuvodip

Related Questions In Selenium

0 votes
1 answer

How to install TestNG in eclipse?

Its very simple @user,  Simply open your eclipse ...READ MORE

answered Dec 26, 2018 in Selenium by Nabarupa
88 views
0 votes
1 answer

How does prioritization helps in testing?

Prioritizing is used for providing priorities to ...READ MORE

answered Dec 26, 2018 in Selenium by Trisha
34 views
0 votes
1 answer

How to import TestNG in Eclipse for Selenium?

Hi Charu, to install TestNG framework in ...READ MORE

answered May 17 in Selenium by Abha
• 22,870 points
52 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
551 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
887 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
550 views
0 votes
1 answer
0 votes
1 answer