How to display Test Cases details in Jenkins Console Output?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to display Test Cases details in Jenkins Console Output?



I want to display Excel(XLSX) Test cases id,description and status while running selenium testng execution in the Jenkins Console output,below is the format.


TC_ID|Test Cases Description|Status
TC01|Verify Login Home|PASS
TC02|Verify Login Screen|FAIL



In case any one did this type of model please help me to achieve this in Jenkins Output Console.





Just to get you right, you mean that the content would be displayed post test class execution ? @Rajesh Om
– AutomatedOwl
Aug 9 at 13:45






@AutomatedOwl Yes post test class execution,Can you please provide code
– Rajesh Om
Aug 9 at 16:24




2 Answers
2



If you are using TestNG in your project, anything you log using Reporter class will be also printed in Jenkins console output :


Reporter.log("This will be displayed in the TestNG report AND in Jenkins console");



Note : You need to add the following import :


import org.testng.Reporter;



Refer this link for steps to create a TestNG project in Jenkins. Alternatively, you can also as well create a Maven project where your pom file will execute your TestNG tests.



Now, if you want to get the data from an excel file, you can use Apache POI. Refer this link for an example to read data from excel.



If you want PASS, FAIL status to be printed beside your test case name, you can use ITestResult. Suppose you are printing the data in your @AfterMethod method, you would do something like -


ITestResult


@AfterMethod


@AfterMethod
public void afterSuite(ITestResult result)

if(result.getStatus() == ITestResult.SUCCESS)

//pass

else if(result.getStatus() == ITestResult.FAILURE)

//fail


else if(result.getStatus() == ITestResult.SKIP )

//skip




Now, you can store the each respective test method result along with the name you read from the excel file, store it in a Map and then print it one by one in your @AfterSuite method.


@AfterSuite





How can i print in TCId|Test Description|Test Cases Status format in jenkins output using Reporter.log();
– Rajesh Om
Aug 10 at 6:15





@RajeshOm Check my edited answer. Its one of the strategy you can use. If you face any difficulty in implementing it, ask me.
– Shivam Mishra
Aug 10 at 6:31



Maybe will be better to implement listener but you can use code below:


@AfterMethod(alwaysRun = true)
public void beforeMethod(Method test, ITestResult testResult) %s", name, description, result));






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS