Automation In Scala: Allure Reporting
Tags: automation, report, scala
Published: 2021-05-18 06:34:19

## Reporting in automation
 
I shared the basic examples of UI in the [previous blog post](https://alexromanov.github.io/2021/05/11/selenium-scala-basic/) tests in Scala. Now it's time to get to reporting. 
 
Implementation and maintenance of the automated tests is a hard thing. But if the test results are not presented simply and understandably - the value from automation tests can be dramatically decreased.  
 
Reports are a huge thing not only for managers. The test reports can be used by the whole team. A good report can show which areas have been tested, which user stories and features are covered, and what are the reasons for failure in a particular case. 
 
[Allure](https://docs.qameta.io/allure/) reporting is a widely used open-source library for test reporting. It allows you to get a full-featured report containing a lot of useful data in a few clicks. 
Allure also can be customized a bit in case you want some additional information displayed in the reports.  
 
There plenty of [examples](https://github.com/allure-examples) on how to integrate Allure reports to test automation projects: in Java, Python, JS, and other languages.  
 
Today I will show you how to integrate it into your Scala-based solution.  
 
## Adding Allure to Scala test project
 
**For test project I am using [Scala](https://www.scala-lang.org/) 2.13.5 and [sbt](https://www.scala-sbt.org/) 1.4.9**
 
* Add necessary libraries to build.sbt
 
```
    val allureScalaTestVersion = "2.13.3"
 
    resolvers +=
        "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
    
    libraryDependencies += "io.qameta.allure" % "allure-scalatest_2.13" % allureScalaTestVersion % Test
 
    testOptions in Test ++= Seq(
        Tests.Argument(TestFrameworks.ScalaTest, "-oD"),
        Tests.Argument(TestFrameworks.ScalaTest, "-C", "io.qameta.allure.scalatest.AllureScalatest")
        )
```
 
* Modify the test classes and add a **new AllureScalatestcontext** for each test
 
``` scala
  "User" should "be able to view latest blog post" in new AllureScalatestContext {
    val homePage = new HomePage
    go to homePage
    val posts = findAll(CssSelectorQuery("div.post-preview")).toList
    posts should have size 5
    val latestPost = posts.head
    latestPost.text should not be empty
  }
```
 
* Run tests via **"sbt test"** command  
 
    As a result - you should get test results from the test run inside **allure-results** folder. 
 
* If you want to generate reports locally - install [Allure command line](https://docs.qameta.io/allure/#_commandline) tool  
 
* For generating report, execute:

``` bash
    $ allure generate
    Report successfully generated to allure-report
```    
 
* For opening generated report in a default browser - use:

``` bash
    $ allure open
    Starting web server...
    2021-05-17 14:50:08.203:INFO::main: Logging initialized @258ms to org.eclipse.jetty.util.log.StdErrLog
    Server started at <http://172.20.160.1:52209/>. Press <Ctrl+C> to exit
```   
 
* In the end you get the report:
 
    ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ul13hi67ocdyf0d2jpu.png)
 
   ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53a9n9ijl7mnesrd8h7w.png)
 
## Conclusion
 
Allure reporting is a great tool for visualizing test results and trends. It is easy to integrate and use. 
 
In most cases, it is more than needed for status reports.  Of course, if you need a completely different report, you can customize HTML sources.  
 
The next logical step is to add Allure report to your CI.  
 
Full code samples can be found in [repository](https://github.com/alexromanov/scala-automation-samples).