private void recordResult ( ITestResult result ) { // finalize our output file Reporter reporter = ( Reporter ) result . getAttribute ( REPORTER ) ; String htmlFilename = "" ; String pdfFilename = "" ; if ( reporter != null ) { // subtracting one from the status ordinal to map ITestResult to Success reporter . finalizeReporter ( result . getStatus ( ) - 1 ) ; htmlFilename = reporter . getFileName ( ) + ".html" ; if ( Property . generatePDF ( ) ) { pdfFilename = reporter . getFileName ( ) + ".pdf" ; } } // update our reporter logger String testName = getTestName ( result ) ; Browser browser = ( Browser ) result . getAttribute ( BROWSER ) ; if ( browser != null ) { // subtracting one from the status ordinal to map ITestResult to Success org . testng . Reporter . log ( Success . values ( ) [ result . getStatus ( ) - 1 ] + OUTPUT_BREAK + browser . getDetails ( ) + OUTPUT_BREAK + LINK_START + getFolderName ( result ) + "/" + htmlFilename + LINK_MIDDLE + testName + " HTML Report" + LINK_END ) ; if ( ! pdfFilename . isEmpty ( ) ) { org . testng . Reporter . log ( OUTPUT_BREAK + LINK_START + getFolderName ( result ) + "/" + pdfFilename + LINK_MIDDLE + testName + " PDF" + LINK_END ) ; } org . testng . Reporter . log ( OUTPUT_BREAK + ( result . getEndMillis ( ) - result . getStartMillis ( ) ) / 1000 + TIME_UNIT ) ; } // update sauce labs if ( Sauce . isSauce ( ) && result . getAttributeNames ( ) . contains ( SESSION_ID ) ) { String sessionId = result . getAttribute ( SESSION_ID ) . toString ( ) ; JsonObject json = new JsonObject ( ) ; json . addProperty ( "passed" , result . getStatus ( ) == 1 ) ; JsonArray tags = new JsonArray ( ) ; for ( String tag : result . getMethod ( ) . getGroups ( ) ) { tags . add ( tag ) ; } json . add ( "tags" , tags ) ; try { HTTP http = new HTTP ( null , "https://saucelabs.com/rest/v1/" + Sauce . getSauceUser ( ) + "/jobs/" , Sauce . getSauceUser ( ) , Sauce . getSauceKey ( ) ) ; http . put ( sessionId , new Request ( ) . setJsonPayload ( json ) , null ) ; } catch ( InvalidHubException e ) { log . error ( "Unable to connect to sauce, due to credential problems" ) ; } catch ( IOException e ) { log . error ( e ) ; } } }
Checks to see if the test execution was performed on SauceLabs or not . If it was this reaches out to Sauce in order to update the execution results