From eebb2cc0ff141fcfda888d3cb136705b59b0ebcf Mon Sep 17 00:00:00 2001 From: chibimagic Date: Fri, 20 Mar 2015 15:09:15 -0700 Subject: [PATCH] BrowserStack: Support specifying session status --- WebDriver/Driver.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/WebDriver/Driver.php b/WebDriver/Driver.php index d6215b2..b15e460 100644 --- a/WebDriver/Driver.php +++ b/WebDriver/Driver.php @@ -121,6 +121,10 @@ public function get_browser() { public function running_at_sauce() { return (strpos($this->server_url, "saucelabs.com") !== false); } + + public function running_at_browserstack() { + return (strpos($this->server_url, "browserstack.com") !== false); + } public function sauce_url() { if ($this->running_at_sauce()) { @@ -795,6 +799,21 @@ public function set_sauce_context($field, $value) { WebDriver::Curl("PUT", "http://" . $url_parts['user'] . ":" . $url_parts['pass'] . "@saucelabs.com/rest/v1/" . $url_parts['user'] . "/jobs/" . $this->session_id, $payload); } } + + // See https://www.browserstack.com/automate/rest-api#rest-api-sessions + public function set_browserstack_status($status, $reason = "") { + if (!in_array($status, array("completed", "error"))) { + throw new Exception("Status must be 'completed' or 'error', not '$status'"); + } + if($this->running_at_browserstack()) { + $payload = json_encode(array( + 'status' => $status, + 'reason' => $reason + )); + $url_parts = parse_url($this->server_url); + WebDriver::Curl("PUT", "https://" . $url_parts['user'] . ":" . $url_parts['pass'] . "@www.browserstack.com/automate/sessions/" . $this->session_id . ".json", $payload); + } + } /******************************************************************** * Asserters