0

Here is my Testng.xml Suite

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite1" verbose="1">
    <test name="LoginTest">
    <parameter name="ExcelPath" value="D:/DataExcel.xls" />
        <classes>
            <class name="com.idp.testcases.TestCaseDemoFlow" />
        </classes>
    </test>

Here is part of my TestCase Class

@Test(priority = 1, dataProvider = "SDLogin",dataProviderClass=ExampleDataProvider.class)
public static void testLogin(String myAccountName, String myAccountPassword)  
{
System.out.println("myAccountName="+myAccountName);
System.out.println("myAccountPassword="+myAccountPassword);\    
}

My Question is How do I pass the ExcelPath Parameter from xml suite to the Test along with the Dataprovider?

Or if not possible

Is it possible to pass the Excelpath in the Dataprovider without mentioning the TestCasedemo class within the DataProvider?

Naman
  • 27,789
  • 26
  • 218
  • 353
Fowad Hamza
  • 111
  • 1
  • 6

1 Answers1

0

You can try and use the ITestContext to get the xml for test :

DataProvider class :

@DataProvider(name = "SDLogin")
public static Object[][] dataProviderLogin(ITestContext context) throws Exception {
    String dataFile = context.getCurrentXmlTest().getLocalParameter(); //to get the params for *test*
}

Test class :

@Test(priority = 1, dataProvider = "SDLogin",dataProviderClass=ExampleDataProvider.class)
public static void testLogin(String myAccountName, String myAccountPassword, String param)  
{
Naman
  • 27,789
  • 26
  • 218
  • 353