-1

Step1: Created a class A with two methods:

@Test(dataProvider="testdata")
InputToForm()

@DataProvider(name="testdata")
readDataFromExcel()

Step2: Created a class B, where I need to call the method InputToForm() with the data.

hering
  • 1,956
  • 4
  • 28
  • 43
rht 73
  • 1
  • 2

1 Answers1

0

Please read about inheritance and more about core java in general before you jump into automation, else you will be stuck at every small issue.

You can resolve your issue by simply using inheritance, as mentioned below.

Your data provider in a different class

public class DataLibrary {
    @DataProvider(name="loginData")
    public Object[][] loginData(){
        return new Object[][]{
                {"username", "password"}
        };
    }
}

And here goes your login class.

public class Login extends DataLibrary {
    @Test(dataProvider = "loginData")
    public void login(String username, String password){
        System.out.println("username="+username+" password="+password);
    }
} 
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
  • Thanks for response Gaurang. But, my question is how do I use these username and password data into another method which is in another class. – rht 73 Mar 14 '17 at 12:56
  • you mean another method or another test ?? if you are talking about another test, that's what exactly this code does. if you are talking about another method, why not just call that function ?? – Gaurang Shah Mar 14 '17 at 13:34