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].
João Farias
11.2k2 gold badges21 silver badges41 bronze badges
asked Mar 1, 2019 at 6:02
1
  • Could you clarify the scenario in atomic steps? "I do this, and this happens; then I do this, and this happens". Commented Mar 2, 2019 at 15:59

2 Answers 2

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.

answered Mar 2, 2019 at 16:04
1
  • Yeah, totally agree, you could even skip the object references and go with new LoginPage().login("user", "password").addDetails(details); Commented May 2, 2019 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/

answered Apr 2, 2019 at 13:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.