A few months ago I wanted to generate a modern html report from my Cucumber json reports using GO. I tried to find something good for me already ready to use, but I couldn't. So I created Gocure.
Gocure is a library written in pure GO that offers the ability to generate html reports from Cucumber json reports.
After the first version, I decided to make something to help me to embed files into json reports, because this cannot be done with Cucumber in GO. So, in this new version of Gocure, it is also possible to embed any files in Cucumber json reports.
Another problem I faced was: OK! Gocure is very good, but only GO projects can use it. So I decided to create a Docker image to help everyone using Cucumber in any language to use Gocure. So if you are using Cocumber, but not in GO, you can simply start a Docker container and call a REST API or use a website to embed files in Cucumber reports or generate beautiful html reports.
Import in your project
If your project is in GO, you simple import Gocure to your project and start using all Gocure functionalities.
package main
import (
"fmt"
"gitlab.com/rodrigoodhin/gocure/embedded"
"gitlab.com/rodrigoodhin/gocure/models"
"gitlab.com/rodrigoodhin/gocure/pkg/gocure"
"gitlab.com/rodrigoodhin/gocure/report/html"
)
func main() {
// Set embedded options
emb := gocure.Embedded{
Config: embedded.Data{
InputJsonPath: "./example/report.json",
OutputJsonPath: "./example/newReport.json",
Files: []string{
"./example/video.mp4",
"./example/text.txt",
"https://i.ibb.co/LpRkTqf/gocure-small.png",
},
FeatureIndex: 0,
ScenarioIndex: 0,
StepIndex: 2,
},
}
err := emb.AddToFeature()
if err != nil {
fmt.Printf("error adding files to feature: %v", err)
}
err = emb.AddToScenario()
if err != nil {
fmt.Printf("error adding files to scenario: %v", err)
}
err = emb.AddToStep()
if err != nil {
fmt.Printf("error adding files to step: %v", err)
}
// Set html options
html := gocure.HTML{
Config: html.Data{
InputJsonPath: "./example/newReport.json",
OutputHtmlFolder: "./example/",
ShowEmbeddedFiles: true,
Metadata: models.Metadata{
AppVersion: "0.8.7",
TestEnvironment: "development",
Browser: "Google Chrome",
Platform: "Linux",
Parallel: "Scenarios",
Executed: "Remote",
},
},
}
// Generate HTML report
err = html.Generate()
if err != nil {
fmt.Printf("error generatig html report: %v", err)
}
}
Check out the oficial documentation for more information about of how to import Gocure in your GO project.
Execute the binary
If you simple want to execute the binary, you can go to the release page in gitlab, download the binary for your system version and execute.
./gocure -j /path/to/json/file.json
Options:
Tag | Type | Description | Default |
---|---|---|---|
-h, --html | String | HTML option | |
-e, --embedded | String | Embedded option |
Common tags:
Tag | Type | Description | Default |
---|---|---|---|
-j | String | Path of the Cucumber JSON report file |
Tags for html option:
Tag | Type | Description | Default |
---|---|---|---|
-f | String | Path of a directory with more than one Cucumber JSON report file This option will be ignored if option "-j" were used |
|
-m | Bool | Merge all Cucumber JSON report files into only one HTML report This option is only used if option "-f" were used |
false |
-i | Bool | Ignore bad Cucumber JSON report files This option is only used if option "-f" were used |
false |
-o | String | Path of the HTML report output folder | |
-t | String | Title of your report | GO Cucumber HTML Report |
-s | Bool | Show embedded files | false |
-AppVersion | String | Metadata - App Version | - |
-TestEnvironment | String | Metadata - Test Environment | - |
-Browser | String | Metadata - Browser | - |
-Platform | String | Metadata - Platform | - |
-Parallel | String | Metadata - Parallel | - |
-Executed | String | Metadata - Executed | - |
Tags for embedded option:
Tag | Type | Description | Default |
---|---|---|---|
-u | String | Output json path | |
-l | String | Embedded file path | |
-a | Int | Feature index | -1 |
-c | Int | Scenario index | -1 |
-p | Int | Step index | -1 |
Releases
Check out the oficial documentation for more information about of how to execute Gocure binary.
Docker container
If you are using Cucumber in another language than GO or you simple don't want to import Gocure to your project, you can start a Docker container.
To start a Docker container, follows this steps:
Create a file called docker-compose.yml
with this code:
version: '3'
services:
gocure:
container_name: gocure
image: rodrigoodhin/gocure
volumes:
- "$PWD/data:/data"
- "/Users:/Users"
ports:
- "8087:80"
- "7087:7087"
networks:
- my_network
networks:
my_network:
Then execute the command below to start your Docker container:
docker-compose up -d
REST API
You can use Gocure REST API, running the binary or starting a Gocure Docker container.
If you need to use GOcure, but do not use GO and still want to integrate Gocure to your project, you can use call the Gocure REST API.
If you start a Docker container like shown above, you can go to http://localhost:7087/swagger/
to check the REST API documentation.
The REST API will be available at http://localhost:7087/
.
Check out the oficial documentation for more informations about the REST API.
Website
Last but not least, after you start the Docker container, as shown above, you can use Gocure by visiting the website at http://localhost:8087/
. On this website you can use all the features of Gocure in a simple way.
Check out the oficial documentation for more information of how to use the Gocure Website.
If you encounter any errors, go to Gocure repository and open an issue.
If you have any suggestions, feel free to comment.
I hope you Enjoy this tool!
Top comments (1)
[[..PingBack..]]
This article was curated as a part of #48th Issue of Software Testing Notes Newsletter.