Listeners in TestNG

If you want to add logs into your test script you can use listeners. Listeners work on action so have below methods.

OnTestStart : Invoked each time before a test will be invoked.

OnTestSuccess : Invoked each time a test succeeds.

OnTestFailure : Invoked each time a test fails

OnTestSkipped : Invoked each time a test is skipped.

OnTestFinish

How to use in your current project

Create Class 'ListenersClass.java'

code like

package com.example.logging;

import org.testng.IClass;

import org.testng.ITestResult;

import org.testng.TestListenerAdapter;

public class ListenerClass extends TestListenerAdapter {

@Override

public void onTestStart(ITestResult tr) {

log("Test Started....");

}

@Override

public void onTestSuccess(ITestResult tr) {

log("Test '" + tr.getName() + "' PASSED");

Use the above class in your exiting main test class by importing above class.

Add listners in to testng.xml as well

listeners>

<listener class-name="Tru.XXX.logging.ListenerClass" />

</listeners>

Enjoy longing so that you can have better understanding where test fails.







要查看或添加评论,请登录

Vivek Sharma的更多文章

  • LLM and Evaluation Methods

    LLM and Evaluation Methods

  • Hallucination In AI Models

    Hallucination In AI Models

    Hallucination in Natural Language Generation: Hallucination occurs when a language model generates text that fits a…

  • Python Cosine Similarity

    Python Cosine Similarity

    Cosine Similarity is used as a metric for measuring distance when the magnitude of vector** does not matter. Example -…

    1 条评论
  • Cypress Best Practices

    Cypress Best Practices

    Use data attribute when selecting the Elements, Automation QA can add data attribute in the code if not available that…

  • Robot Framework - Template usage in API automation

    Robot Framework - Template usage in API automation

    In Robot Framework the Test templates convert normal keyword driven test cases into data driven tests. Use Case : In…

    1 条评论

社区洞察

其他会员也浏览了