Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Guide to Generate Extent Report in Kotlin

57 views

Published on

Kotlin is a general-purpose, open-source, statically typed programming language that combines object-oriented and functional programming features. So, it is a strong and powerful language that helps the automation engineers to write their automation scripts and also develop the Extent Report. This article helps the automation engineers to up skill and develop the extent reports using a different language like Kotlin.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Guide to Generate Extent Report in Kotlin

  1. 1. Guide to Generate Extent Report in Kotlin
  2. 2. Guide to Generate Extent Report in Kotlin © RapidValue Solutions 2 Extent Report Generation with Kotlin  Pre-requisites Following are the pre-requisites to generate Extent reports with Kotlin:  Install Java SDK 8 and above.  Install Eclipse or IntelliJ IDEA IDEs.  Install the Kotlin plugin in IDEs. Here, we are using Eclipse as IDE and Kotlin plugin for Eclipse downloaded from https://marketplace.eclipse.org/content/kotlin-plugin-eclipse.  The latest version of following maven dependencies: o testng o selenium-java o selenium-server o kotlin-test o kotlin-stdlib-jdk8 o extentreports  Step-by-step Procedure Step 1: Create a maven project and add the above dependencies in pom.xml of the project. Step 2: Create a Kotlin class to keep the logic to generate the Extent Report. Let say the class name is AutomationReport. Here, we are using ITestListener interface of TestNG to control the executions and results. Below is the code snippet of the AutomationReport class to implement the ITestListener and declare the objects for ExtentSparkReporter, ExtentReports, and ExtentTest, class AutomationReport : ITestListener { public lateinit var sparkReporter: ExtentSparkReporter public lateinit var extentReport: ExtentReports public lateinit var extentTest: ExtentTest …} Step 3: Create an override method onStart() with logic to generate an HTML template for the test report, override fun onStart(testContext: ITestContext) { try { sparkReporter = ExtentSparkReporter(System.getProperty(“user.dir”) + “/AutomationReport/”) sparkReporter.config().setDocumentTitle(“Kotlin Automation”) sparkReporter.config().setReportName(“Automation Execution Report”) sparkReporter.config().setTheme(com.aventstack.extentreports.reporter.configuration.Theme.DARK) extentReport = ExtentReports() extentReport.attachReporter(sparkReporter) extentReport.setSystemInfo(“Application Name”, “Kotlin Report Demo”)
  3. 3. Guide to Generate Extent Report in Kotlin © RapidValue Solutions 3 extentReport.setSystemInfo(“Platform”, System.getProperty(“os.name”)) extentReport.setSystemInfo(“Environment”, “QA”) } catch (e: Exception) { e.printStackTrace() } } Step 4: Create an override method onTestStart() with logic to collect current test case name and add it to the report, override fun onTestStart(result: ITestResult) { var testName: String = result.getMethod().getMethodName() extentTest = extentReport.createTest(testName) } Step 5: Create an override method onTestSuccess() with logic to add pass status to the report, override fun onTestSuccess(result: ITestResult) { var testName: String = result.getMethod().getMethodName() try { extentTest.log( Status.PASS, MarkupHelper.createLabel(testName + ” Test Case PASSED”, ExtentColor.GREEN) ) } catch (e: Exception) { e.printStackTrace() } } Step 6: Create an override method onTestSkipped() with logic to add skip status to the report, override fun onTestSkipped(result: ITestResult) { var testName: String = result.getMethod().getMethodName() try { extentTest.log( Status.SKIP, MarkupHelper.createLabel(testName + ” Test Case SKIPPED”, ExtentColor.ORANGE) ) } catch (e: Exception) { e.printStackTrace() } } Step 7: Create an override method onTestFailure() with logic to add fail status to the report, override fun onTestFailure(result: ITestResult) { var driver: WebDriver var currentClass = result.getInstance() var testName: String = result.getMethod().getMethodName()
  4. 4. Guide to Generate Extent Report in Kotlin © RapidValue Solutions 4 try { driver = (currentClass as AutomationBase).getDriverInstance() var screenshotPath = Utilities().screenshotCapture(driver, result.getName()) extentTest.log( Status.FAIL, MarkupHelper.createLabel(testName + ” Test Case FAILED”, ExtentColor.RED) ) extentTest.log( Status.FAIL, MarkupHelper.createLabel(“Reason for Failure: ” + result.getThrowable().toString(), ExtentColor.RED) ) extentTest.addScreenCaptureFromPath(screenshotPath) } catch (e: Exception) { e.printStackTrace() } } Step 8: Create an override method onFinish() with logic to store HTML report to the specified path and flush extent report instance, override fun onFinish(testContext: ITestContext) { try { extentReport.flush() val dateFormat = SimpleDateFormat(“dd-MMM-yyyy_HH-mm-ss”) val date = Date() val filePathdate: String = dateFormat.format(date).toString() var actualReportPath: String = System.getProperty(“user.dir”) + “/AutomationReport/” + “index.html” File(actualReportPath).renameTo( File( System.getProperty(“user.dir”) + “/AutomationReport/” + “Automation_Report_” + filePathdate + “.html” ) ) } catch (e: Exception) { e.printStackTrace() } } Step 9: Create another class called Utilities to keep common utility functions required for automation. Here, we just added one utility to capture the screenshot. In onTestFailure() method, we already used a method called screenshotCapture(). Below is the code snippet to capture the screenshot, fun screenshotCapture(driver: WebDriver, fileName: String): String { var destination: String = “” try { var scrFile = (driver as TakesScreenshot).getScreenshotAs(OutputType.FILE) var dateFormat = SimpleDateFormat(“yyyyMMddHHmmss”) var cal = Calendar.getInstance() var path = File(“Failure_Screenshots”).getAbsolutePath()
  5. 5. Guide to Generate Extent Report in Kotlin © RapidValue Solutions 5 destination = path + “/” + fileName + dateFormat.format(cal.getTime()) + “.png” scrFile.copyTo(File(destination)) } catch (e: Exception) { e.printStackTrace() } return destination } Step 10: Prior to starting the automation execution, you have to map the AutomationReport class to your test runner class (the class which starting your driver instance within TestNG annotation). You can represent AutomationReport class in test runner class as below, @Listeners(AutomationReport::class) Step 11: Now, you can run your test cases using testng.xml and once execution complete the HTML report will generate inside the AutomationReport folder in the project structure. Following are some excerpts of the Extent Report: We hope you got an idea of the Extent Report implementation using Kotlin language. Try to use the above step-by-step procedure in your automation world and explore it.
  6. 6. Guide to Generate Extent Report in Kotlin © RapidValue Solutions 6 Conclusion Kotlin is a general-purpose, open-source, statically typed programming language that combines object- oriented and functional programming features. So, it is a strong and powerful language that helps the automation engineers to write their automation scripts and also develop the Extent Report. This article helps the automation engineers to up skill and develop the extent reports using a different language like Kotlin. By, Sanoj S, Test Architect, RapidValue
  7. 7. Guide to Generate Extent Report in Kotlin © RapidValue Solutions 7 About RapidValue RapidValue is a global leader in digital product engineering solutions including mobility, omni-channel, IoT, AI, RPA and cloud to enterprises worldwide. RapidValue offers its digital services to the world’s top brands, Fortune 1000 companies and innovative emerging start-ups. With offices in the United States, the United Kingdom, Germany and India and operations spread across the Middle-East, Europe and Canada, RapidValue delivers enterprise services and solutions across various industry verticals. Disclaimer: This document contains information that is confidential and proprietary to RapidValue Solutions Inc. No part of it may be used, circulated, quoted, or reproduced for distribution outside RapidValue. If you are not the intended recipient of this report, you are hereby notified that the use, circulation, quoting, or reproducing of this report is strictly prohibited and may be unlawful. www.rapidvaluesolutions.com/blogwww.rapidvaluesolutions.com +1 877.643.1850 contactus@rapidvaluesolutions.com

×