Skip to content

Commit

Permalink
BrowserStack: Support specifying session status
Browse files Browse the repository at this point in the history
  • Loading branch information
chibimagic committed Mar 20, 2015
1 parent 50d8a40 commit eebb2cc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions WebDriver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eebb2cc

Please sign in to comment.