问题
I am triyng to write testng listeners for my testing project cucumber, testng, selenium and java.
I have created Listeners extends TestListenerAdapter and implemented all the methods and included in testng.xml
`<listeners> <listener class-name="TestNGListeners.Listeners"></listener>
`<test name="Smoke">
`<packages> <package name="cucumber.runner.*"> </package>
`</test>
This xml calling a testrunner class RunCukesTest
`@CucumberOptions(features ="classpath:features",
`glue ="stepDefinitions",
tags="@tag_Login2",
plugin={"pretty", "html:target/cucumber-html-report",
"json:target/cucumber-report.json"}
)
`public class RunCukesTest {
`@Test()
`public void run_cukes () throws IOException {
`System.out.println("Run Cuke is started..");
`TestNGCucumberRunner tr = new TestNGCucumberRunner(getClass());
`tr.runCukes(); }
`}
which is responsible for running all cucumber tests.
After running it I am not getting any response from my listener methods. Please help me to find the solution.
Example -: Whenever I want to run suite or runner these method should work so that I can write my functionality :
public void onTestSuccess(ITestResult tr){
if( ITestResult.SUCCESS== tr.SUCCESS)
{
System.out.println("Test result PASS..");
}
}
回答1:
I would suggest rather use the service hooks of cucmber api to achieve what ever you want to achieve from listner classes. They possibly wint work with the cucumber runner engine.
来源:https://stackoverflow.com/questions/36397555/how-to-use-testng-listeners-with-cucumber