Created
June 19, 2018 09:31
-
-
Save pulse00/ca7ac8d84c37bb90527e14e2c4fd45c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package spock | |
import org.openqa.selenium.remote.RemoteWebDriver | |
@Singleton | |
class BrowserInstance { | |
def RemoteWebDriver driver | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BrowserStackListener extends AbstractRunListener { | |
void error(ErrorInfo error) { | |
if (!BrowserInstance.instance.driver) { | |
return | |
} | |
def username = getenv("BROWSERSTACK_USER") | |
def accessKey = getenv("BROWSERSTACK_ACCESSKEY") | |
def sessionId = BrowserInstance.instance.driver.getSessionId().toString() | |
def reportUrl = "https://${username}:${accessKey}@api.browserstack.com/automate/sessions/${sessionId}.json" | |
HttpPut putRequest = new HttpPut(new URI(reportUrl)) | |
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>() | |
nameValuePairs.add((new BasicNameValuePair("status", "failed"))) | |
nameValuePairs.add((new BasicNameValuePair("reason", error.error.toString()))) | |
putRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs)) | |
print "Reporting failed test to browserStack with sessionId ${sessionId}" | |
HttpClientBuilder.create().build().execute(putRequest) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// ... | |
browserStack { | |
driver = { | |
def driver = browserStackDriver() | |
BrowserInstance.instance.driver = driver | |
return driver | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment