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
660 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,770 points
38,043 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
1,019 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
3,095 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
13,776 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
9,190 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
7,266 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,903 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
2,177 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
4,336 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