Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:17:05+00:00 2026-06-15T15:17:05+00:00

I want to use the Sauce Labs Java REST API to send Pass/Fail status

  • 0

I want to use the Sauce Labs Java REST API to send Pass/Fail status back to the Sauce Labs dashboard. I am using Geb+Spock, and my Gradle build creates a test results directory where results are output in XML. My problem is that the results XML file doesn’t seem to be generated until after the Spock specification’s cleanupSpec() exits. This causes my code to report the results of the previous test run, rather than the current one. Clearly not what I want!

Is there some way to get to the results from within cleanupSpec() without relying on the XML? Or a way to get the results to file earlier? Or some alternative that will be much better than either of those?

Some code:

In build.gradle, I specify the testResultsDir. This is where the XML file is written after the Spock specifications exit:

drivers.each { driver ->
    task "${driver}Test"(type: Test) {
        cleanTest
        systemProperty "geb.env", driver    
        testResultsDir = file("$buildDir/test-results/${driver}")
        systemProperty "proj.test.resultsDir", testResultsDir
    }
}

Here is the setupSpec() and cleanupSpec() in my LoginSpec class:

class LoginSpec extends GebSpec {
    @Shared def SauceREST client = new SauceREST("redactedName", "redactedKey")
    @Shared def sauceJobID
    @Shared def allSpecsPass = true

    def setupSpec() {
        sauceJobID = driver.getSessionId().toString()
    }

    def cleanupSpec() {
        def String specResultsDir = System.getProperty("proj.test.resultsDir") ?: "./build/test-results"
        def String specResultsFile = this.getClass().getName()
        def String specResultsXML = "${specResultsDir}/TEST-${specResultsFile}.xml"
        def testsuiteResults = new XmlSlurper().parse( new File( specResultsXML ))

        // read error and failure counts from the XML       
        def errors = testsuiteResults.@errors.text()?.toInteger()
        def failures = testsuiteResults.@failures.text()?.toInteger()

        if ( (errors + failures) > 0 ) { allSpecsPass = false }

        if ( allSpecsPass ) {
            client.jobPassed(sauceJobID)
        } else {
            client.jobFailed(sauceJobID)
        }
    }
}

The rest of this class contains login specifications that do not interact with SauceLabs. When I read the XML, it turns out that it was written at the end of the previous LoginSpec run. I need a way to get to the values of the current run.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:17:06+00:00Added an answer on June 15, 2026 at 3:17 pm

    Test reports are generated after a Specification has finished execution and the generation is performed by the build system, so in your case by Gradle. Spock has no knowledge of that so you are unable to get that information from within the test.

    You can on the other hand quite easily get that information from Gradle. Test task has two methods that might be of interest to you here: addTestListener() and afterSuite(). It seems that the cleaner solution here would be to use the first method, implement a test listener and put your logic in afterSuite() of the listener (and not the task configuration). You would probably need to put that listener implementation in buildSrc as it looks like you have a dependency on SauceREST and you would need to build and compile your listener class before being able to use it as an argument to addTestListener() in build.gradle of your project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use this 1 for using Bar code or QR code scanner. I
I use Selenium and Sauce Labs for testing. Is there a Selenium property to
i want use XmlSampleGenerator API in my project. i don't know how to add
I want use MySQL database in R environment. I am using Ubuntu OS. To
I want use WPF on Windows version of my java application. I found it
I want use fiddler check the https request send by Azure Powershell, but when
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use javascript setInterval function to achieve a box rotate animate effect, I
I want use a single php file to handle all of my voting requests.
I want use groovy findAll with my param to filtering closure filterClosure = {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.