如何在黄瓜中使用TestNG侦听器 [英] How to use TestNG Listeners with Cucumber

查看:173
本文介绍了如何在黄瓜中使用TestNG侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正准备为我的测试项目Cucumber,Testng,Selenium和Java编写Testng侦听器.

I am triyng to write testng listeners for my testing project cucumber, testng, selenium and java.

我已经创建了侦听器,扩展了TestListenerAdapter并实现了所有方法,并包含在testng.xml中

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>  

此xml调用testrunner类RunCukesTest

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..");
        }


    } 

推荐答案

我建议您使用cucmber api的服务挂钩来实现您想从列表器类中实现的目标.他们可能会与黄瓜转轮引擎一起工作.

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.

这篇关于如何在黄瓜中使用TestNG侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆