简体   繁体   English

如何在黄瓜中使用TestNG侦听器

[英]How to use TestNG Listeners with Cucumber

I am triyng to write testng listeners for my testing project cucumber, testng, selenium and java. 我正在为我的测试项目Cucumber,Testng,Selenium和Java编写Testng侦听器。

I have created Listeners extends TestListenerAdapter and implemented all the methods and included in testng.xml 我创建了侦听器,扩展了TestListenerAdapter并实现了所有方法,并包含在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 此xml调用testrunner类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..");
        }


    } 

I would suggest rather use the service hooks of cucmber api to achieve what ever you want to achieve from listner classes. 我建议使用cucmber api的服务挂钩来实现您想从listner类中实现的目标。 They possibly wint work with the cucumber runner engine. 他们可能会与黄瓜转轮引擎一起工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM