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, 2019 in Selenium by Nitesh
• 3,030 points
78 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, 2019 by Shuvodip

Related Questions In Selenium

0 votes
3 answers

How to install TestNG in eclipse?

Installing TestNG in Eclipse Step 1) Launch Eclipse. On the ...READ MORE

answered Dec 11, 2020 in Selenium by Gitika
• 65,850 points
17,988 views
0 votes
2 answers

How does prioritization helps in testing?

Hi , Lets consider a scenario u have ...READ MORE

answered Sep 1, 2020 in Selenium by Sri
• 3,010 points
121 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, 2019 in Selenium by Abha
• 28,000 points
965 views
0 votes
2 answers

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,520 points
4,326 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,010 points
5,248 views
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,890 points
3,129 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,010 points
3,630 views
0 votes
1 answer
0 votes
1 answer

How to skip a method or a code block in TestNG?

If you want to skip a particular test ...READ MORE

answered Feb 8, 2019 in Selenium by Frankie
• 9,810 points
619 views