Deepak Suyal
Deepak Suyal

Reputation: 90

Getting a java class object created in a testng class in testng listener

I have a java class called DataReadHelper and i am creating a object of the mentioned class in my testng class

import DataReadHelper

public class testclass{

@BeforeSuite
public void initiate{
    DataReadHelper dataread = new DataReadHelper("D:\\Test.xlsx");
}

Now i have a testng listener class which is implementing iTestResult listener and i want to verify whether the object for this class is created or not in the testng listener class

I have already tried many things but with no success, How can i achieve it? Thanks in advance for help

Upvotes: 0

Views: 217

Answers (1)

juherr
juherr

Reputation: 5740

Yu can use ITestContext in order to store the object:

  1. Pass it as a parameter of @BeforeSuite method and save your object into it: context.setAttribute("dataread", dataread)
  2. Restore the object from the listener: DataReadHelper dataread = result.getTestContext().getAttribute("dataread")

Upvotes: 1

Related Questions