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,080 points
435 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,910 points
37,375 views
0 votes
2 answers

How does prioritization helps in testing?

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

answered Sep 2, 2020 in Selenium by Sri
• 3,190 points
624 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,140 points
2,698 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,500 points
12,712 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,190 points
8,608 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,910 points
6,680 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 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
0 votes
1 answer

How to disable a test case in testNG?

You can use the enable method to ...READ MORE

answered Jan 3, 2019 in Selenium by Nabarupa
1,855 views
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,830 points
3,800 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP