0

Using TestNG framework : How to call other class of the methods

I have created one class for login and another class for add customer details.

My scenario is:

  • Once user login after add customer details class method call and add the details [Using DDT framework and data provider].
  • Could you clarify the scenario in atomic steps? "I do this, and this happens; then I do this, and this happens". – João Farias Mar 2 at 15:59
1

My understanding is that we don't have any work regarding TestNG nor Data Providers, just plain old Java coding:

@Test
public void addDetailsTest(Details details) {

  LoginPage loginPage = new LoginPage();
  AddDetailsPage addDetailsPage = loginPage.login("user", "password");
  addDetailsPage.addDetails(details);
  ...

}

// LoginPage file

public AddDetailsPage login(String username, String password) {
  // Do the login
  return new AddDetailsPage();
}

This is an example of the Page Object pattern.

  • Yeah, totally agree, you could even skip the object references and go with new LoginPage().login("user", "password").addDetails(details); – Moro May 2 at 14:25
0

I think you can achieve this in two ways:

1) Instead of adding the second class to the TestNG.xml, simply import it into the first test class and invoke its method (add customer details) from the first class @test method. The advantage here is that you can easily check if the login succeeds or not, decide to call the 2nd class method or not and even pass some data as parameters.

Or

2) Mention two classes as a part of the single test cases, check below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Simple Test Suite" verbose="1">
  <test name="Testing Part1">
    <classes>
      <class name="com.techbeamers.testng.LoginPage" />
      <class name="com.techbeamers.testng.addCustomerDetails" />
    </classes>
  </test>
</suite>

Here, the test methods from each class will get executed one after the other. And it may get fulfilled what you wish to achieve.

Ref: https://www.techbeamers.com/testng-parameters-and-dataprovider-annotations/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.