Search code examples
javaseleniummavenjvmcucumber-jvm

selenium cucumber.io get the reports link in Java or Bash (if Bash, still console ouput), so it can be used else where (like slack)


When we run tests using Cucumber, we have the option to use an ENV variable and publish the results to cucumber.io, or even without an ENV variable eg:

View your Cucumber Report at:                                            
https://reports.cucumber.io/reports/some-uuid 
This report will self-destruct in 24h.                                   
Keep reports forever: https://reports.cucumber.io/profile               

This works great!!!! But I would like to grab that "some-uuid" and send it to slack (and other places) so others can use it

I can not see a way of getting this with Java using a Hook or Listeners (I think it gets sent back to maven)

I trigger the tests with a bash script, and I was hoping the uuid could be grabbed using something like:

mvn test -Dtest=jRunnerMyTest -Dcucumber.filter.tags="$TAGS" ...| tee log.txt

However, in this case, within the log.txt, the above does not capture that bit of text containing the reports url (I dont really know why), if it did, I could regex the output and grab that url

I have also tried using --log-file, eg:

mvn test --log-file log.txt -Dtest=jRunnerMyTest -Dcucumber.filter.tags="$TAGS" ...

In this case, within the log.txt, it DOES capture the uuid, However when the tests run, there is no command output. I really need that command output, since testers use it while running the tests.

How can I get the reports url (https://reports.cucumber.io/reports/some-uuid ) and keep the console output?


Solution

  • I have done this (a long time ago now) You can just get the response from a text file and strip it out in bash:

    cmd="mvn test --log-file log.txt -Dtest=x -Dcucumber.filter.tags='"$TAGS"'
    reportsUrl=$(grep -hr "reports.cucumber" log.txt | grep -v "profile" | grep -Eo 'http[^ \[U>]+'| sed 's/[^a-z0-9\.\/\-\:-]//g')
    testLine=$(grep -hr "Tests run" log.txt | grep -v "FAILURE" | grep -v "Time elapsed")