forked from browserstack/php-selenium-browserstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal.php
More file actions
51 lines (46 loc) · 2.15 KB
/
local.php
File metadata and controls
51 lines (46 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require_once("vendor/autoload.php");
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;
use BrowserStack\Local;
$caps = array(
'bstack:options' => array(
"os" => "OS X",
"osVersion" => "Sierra",
"buildName" => "BStack Build Number 1",
"sessionName" => "BStack-[Php] Sample Test",
"local" => "true",
"seleniumVersion" => "4.0.0",
),
"browserName" => "Chrome",
"browserVersion" => "latest",
);
$BROWSERSTACK_USERNAME = "BROWSERSTACK_USERNAME";
$BROWSERSTACK_ACCESS_KEY = "BROWSERSTACK_ACCESS_KEY";
# Creates an instance of Local
$bs_local = new Local();
# You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
$bs_local_args = array("key" => $BROWSERSTACK_ACCESS_KEY);
# Starts the Local instance with the required arguments
$bs_local->start($bs_local_args);
# Check if BrowserStack local instance is running
echo $bs_local->isRunning();
$web_driver = RemoteWebDriver::create("https://$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",$caps);
try{
$web_driver->get("http://bs-local.com:45691/check");
$body_text = $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector("body")))->getText();
# Setting the status of test as 'passed' or 'failed' based on the condition; if title of the web page starts with 'BrowserStack'
if ($body_text == "Up and running"){
$web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed", "reason": "Local test ran successfully"}}' );
} else {
$web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": "Failed to load local test"}}');
}
}
catch(Exception $e){
echo 'Message: ' .$e->getMessage();
}
$web_driver->quit();
# Stop the Local instance
$bs_local->stop();
?>