Skip to content

Commit

Permalink
[Review] Sauce labs results
Browse files Browse the repository at this point in the history
  • Loading branch information
garcanam committed Dec 12, 2024
1 parent adac7b7 commit c796f0f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
5 changes: 1 addition & 4 deletions e2e-spock-geb/Jenkinsfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ def stageTest(def context) {
case 0:
echo "All tests passed successfully"
break
case 1:
unstable "Some tests have failed"
break
default:
error "Something went wrong, when executing tests, exitCode ${status}"
unstable "Some tests have failed or encountered errors. Please check the logs for more details."
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ class DemoGebHomePageSpec extends GebReportingSpec {
// Verify that the browser is at the book page
at theBookOfGebPage
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class DemoMobileAppSpec extends GebReportingSpec {
// Shared driver instance for the AppiumDriver
@Shared
def static driver
// Shared result variable to track test success
// Shared variable to indicate the success of the test for Sauce Labs
@Shared
def static result = false
def static sauceLabsResult = false

def setupSpec() {
// Initialize the Appium driver
Expand All @@ -28,12 +28,19 @@ class DemoMobileAppSpec extends GebReportingSpec {
driver.quit()
}
def setup() {
// Set the job result to false
result = false
// Initialize the Sauce Labs result to false
sauceLabsResult = false
}
def cleanup() {
// Set the job result in Sauce Labs
driver.executeScript("sauce:job-result=$result")
// Set the job result in
driver.executeScript("sauce:job-result=$sauceLabsResult")
}

// This function sets the Sauce Labs result to true, indicating that the test passed successfully.
// We use this variable to inform Sauce Labs about the test results, storing whether there were any failures.
// By setting it to true at the end of each test, we ensure that Sauce Labs is updated with the correct test status.
def setTrueResultForSauceLabs() {
(sauceLabsResult = true) != null
}

// Add this @Tag to include this test in the 'test_mobile_app' group.
Expand All @@ -54,8 +61,8 @@ class DemoMobileAppSpec extends GebReportingSpec {
// Print evidence for the specific element
SpecHelper.printEvidenceForWebElement(this, 1, specificElements[0], "Cart-tab-item Element Evidence")

// Set the job result to true if the assertion passes
(result = true) != null
// Set the Sauce Labs result to true, indicating that the test passed successfully
setTrueResultForSauceLabs()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class DemoMobileGebHomePageSpec extends GebReportingSpec {
// Shared driver instance for the AppiumDriver
@Shared
def static driver
// Shared result variable to track test success
// Shared variable to indicate the success of the test for Sauce Labs
@Shared
def static result = false
def static sauceLabsResult = false

def setupSpec() {
// Initialize the Appium driver
Expand All @@ -27,12 +27,19 @@ class DemoMobileGebHomePageSpec extends GebReportingSpec {
driver.quit()
}
def setup() {
// Set the job result to false
result = false
// Initialize the Sauce Labs result to false
sauceLabsResult = false
}
def cleanup() {
// Set the job result in Sauce Labs
driver.executeScript("sauce:job-result=$result")
// Set the job result in
driver.executeScript("sauce:job-result=$sauceLabsResult")
}

// This function sets the Sauce Labs result to true, indicating that the test passed successfully.
// We use this variable to inform Sauce Labs about the test results, storing whether there were any failures.
// By setting it to true at the end of each test, we ensure that Sauce Labs is updated with the correct test status.
def setTrueResultForSauceLabs() {
(sauceLabsResult = true) != null
}

// Add this @Tag to include this test in the 'test_mobile_browser' group.
Expand All @@ -56,8 +63,8 @@ class DemoMobileGebHomePageSpec extends GebReportingSpec {
then: "The page title should be 'The Book Of Geb'"
// Verify the page title
assert title == "The Book Of Geb"
// Set the job result to true if the assertion passes
(result = true) != null
// Set the Sauce Labs result to true, indicating that the test passed successfully
setTrueResultForSauceLabs()
}

}

0 comments on commit c796f0f

Please sign in to comment.