On 27 Nov 2024, at 20:37, Zach Thomas <mrdis...@gmail.com> wrote:
My company has adopted a somewhat non-standard regression testing approach using testng and selenium. We call it "generic testing," and the concept is that a single, centrally defined test method is responsible for broad patterns accross our application and takes in more specific testing instructions from Page Object Models as it goes. Individual test cases are defined via testng.xml files. The downside is that no test has full knowledge of what is under test until runtime. That is we often cannot know at the source code, or xml level, what pages a given test will encounter. There are several cases in which one of these tests will encounter something marked in one of our Page Object Models that necessitate breaking the test into seperate sub-tests to isolate the different paths the test should cover. We have handled these situations by running a programatic TestNG inside the outer TestNG, and then injecting the results into the parent suite via some listeners. This worked fine with reportNG, but does not function in tandem with Report Portal, which we are switching too. The problem lies in the fact that ReportNG builds its output based on the end state of the testNG object, but reportNG builds the test/suite structure via API calls onstart of the suite. I need a way to take a currently executing testContext and make that the context used by a new testNG object to attach its xml tests and suites to.
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/testng-users/d39dd730-dbba-4a33-bdb5-74ed81bd9442n%40googlegroups.com.
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.testng.BaseTestNGListener;
import com.epam.reportportal.testng.ITestNGService;
import com.epam.reportportal.testng.TestNGService;
import org.testng.*;
import org.testng.annotations.Test;
import org.testng.xml.XmlSuite;
import java.util.List;
public class SampleTestCase {
@Test
public final void test(ITestContext transferToContext) {
XmlSuite synthSuite = new XmlSuite();
// build up parameters, listeners, settings, and XmlTests...
TestNG tng = new TestNG();
tng.setXmlSuites(List.of(synthSuite));
tng.addListener(addContextListener(transferToContext));
tng.addListener(reportPortalListener(transferToContext));
tng.initializeSuitesAndJarFile();
tng.run();
}
private static BaseTestNGListener reportPortalListener(ITestContext transferToContext) {
ITestNGService service = new TestNGService(ReportPortal.builder().build());
return new BaseTestNGListener(service) {
public void onStart(ITestContext ignored) {
service.startTest(transferToContext);
}
@Override
public void onFinish(ITestContext ignored) {
service.finishTest(transferToContext);
}
};
}
private static TestListenerAdapter addContextListener(ITestContext transferToContext) {
return new TestListenerAdapter() {
@Override
public void onFinish(ITestContext ignored) {
add(ignored.getPassedTests(), transferToContext.getPassedTests());
add(ignored.getSkippedTests(), transferToContext.getSkippedTests());
add(ignored.getFailedTests(), transferToContext.getFailedTests());
add(ignored.getPassedConfigurations(), transferToContext.getPassedConfigurations());
add(ignored.getSkippedConfigurations(), transferToContext.getSkippedConfigurations());
add(ignored.getFailedConfigurations(), transferToContext.getFailedConfigurations());
}
};
}
private static void add(IResultMap from, IResultMap to) {
from.getAllResults().forEach(to::addResult);
}
}
<BaseTestNGListener_snippet.png>
I currently have no API supported way to "graft" the inner TestNG run into the outer one's context, which is causing unwanted results in Report Portal. If I could make the ITestContext instance from the executing outer TestNG run the context for the inner programmatic TestNG run, then I could effectively relate the results of the inner run to the outer run regardless of reporting architecture.Zach ThomasOn Wednesday, November 27, 2024 at 10:11:09 AM UTC-5 Krishnan Mahadevan wrote:Zach,It would be good if you could please help explain your use case with some sample code.Its not clear to me as to what the issue is.
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/My Technical Scribblings @ https://rationaleemotions.com/On 27 Nov 2024, at 20:37, Zach Thomas <mrdis...@gmail.com> wrote:My company has adopted a somewhat non-standard regression testing approach using testng and selenium. We call it "generic testing," and the concept is that a single, centrally defined test method is responsible for broad patterns accross our application and takes in more specific testing instructions from Page Object Models as it goes. Individual test cases are defined via testng.xml files. The downside is that no test has full knowledge of what is under test until runtime. That is we often cannot know at the source code, or xml level, what pages a given test will encounter. There are several cases in which one of these tests will encounter something marked in one of our Page Object Models that necessitate breaking the test into seperate sub-tests to isolate the different paths the test should cover. We have handled these situations by running a programatic TestNG inside the outer TestNG, and then injecting the results into the parent suite via some listeners. This worked fine with reportNG, but does not function in tandem with Report Portal, which we are switching too. The problem lies in the fact that ReportNG builds its output based on the end state of the testNG object, but reportNG builds the test/suite structure via API calls onstart of the suite. I need a way to take a currently executing testContext and make that the context used by a new testNG object to attach its xml tests and suites to.--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/testng-users/d39dd730-dbba-4a33-bdb5-74ed81bd9442n%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/testng-users/c427347b-1d75-44ea-b7ab-70962e88b912n%40googlegroups.com.
<BaseTestNGListener_snippet.png>