How to use TestNG Listeners with Cucumber

瘦欲@ 提交于 2019-12-24 00:49:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!