Customize Annotations in TestNG

As everyone knows, we are using TestNG annotations like @Test,@Beforetest etc. on daily basis.But are you aware in the same way we can create our customised annotations as per our requirement and do some cool stuffs like

  1. To set author and category of testcases in Extent Report
  2. To set implicit/explicit wait timeout directly at test level
  3. To pass testcase id to test so that TC will pick automatically from Testrail/JIRA etc.

So lets see how we can achieve same in our automation framework:

Steps:

  1. In eclipse, we have to create one annotation.

No alt text provided for this image

2. As per your requirement,Put automation code inside the Annotation.

No alt text provided for this image

3. Put this annotation inside you test method

No alt text provided for this image

4. Now integrate this annotation methods like author() and category() with your Reporting code so that when Extent report will generate accordingly

No alt text provided for this image

5. Write your logic to get author and category from annotation and use it in onTestStart method.

No alt text provided for this image

6. Now trigger the automation

No alt text provided for this image

Hurray..We can see Author and Category tag inside the Extent Report.We can implement same using Custom Annotation.

Happy Learning..!!


Nisim Naim

Mobile & Web Automation Infrastructure Engineer

8 个月

Thanks for sharing

回复
Alok Kulkarni

SQA at Baker Hughes|Framework Development|Selenium Webdriver|Core Java|Appium|BDD|RPA|STB|Cucumber|REST API|Test complete|TestNG|JUnit|Agile Methodology

3 年

Thank you for sharing ??

回复
Atul Mahale

Integration Engineer | Mulesoft | Springboot | Apigee | Middleware

3 年

Thanks for posting

回复
Amuthan Sakthivel

Selenide Committer | Seasoned Test Automation & Devops Lead and Manager | Problem Solver | Tech Youtuber | Appium Conf 2024 Speaker

3 年

Glad to see my work. If someone is interested in video version,? https://youtu.be/8zD2ASUdLDg

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

Mayur Sapre的更多文章

  • Accessibility Testing Audit with Selenium Automation

    Accessibility Testing Audit with Selenium Automation

    What is Accessibility Testing? Accessibility testing is the practice of making your web and mobile apps usable to as…

    2 条评论
  • Dockerfile for Automation

    Dockerfile for Automation

    Please find below dockerfile which will be really helpful as part of automation, it will install below components as…

  • Selenium Testrail: Report Integration

    Selenium Testrail: Report Integration

    Problem Statement: When we are executing set of testcases like Smoke/Regression then everyone is curious to know the…

  • Selenium Testrail Integration

    Selenium Testrail Integration

    Create seperate package inside with below classes: /* ?*? ?*/ package com.gurock.

    1 条评论
  • Git Hooks In Automation

    Git Hooks In Automation

    As part of code repository maintenance we always face below problems: Someone commit code in your local repository…

社区洞察

其他会员也浏览了