Skip to content

Commit d8d2fa6

Browse files
authored
Merge pull request #1 from RutvikChandla/selenium-4
selenium-4 changes
2 parents bb70ba3 + 10bed2a commit d8d2fa6

File tree

7 files changed

+439
-0
lines changed

7 files changed

+439
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
/composer.phar

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1+
# php-selenium-browserstack
12

3+
## Prerequisites
4+
1. `php` and `composer` should be installed in your system
5+
2. Go to the directory where you have your test scripts and run the command below:
6+
```
7+
composer require php-webdriver/webdriver
8+
```
9+
10+
## Steps to run test sessions
11+
1. Install dependencies
12+
```
13+
# If you don't already use Composer, you can download the composer.phar binary:
14+
curl -sS https://getcomposer.org/installer | php
15+
16+
# Include the binding:
17+
php composer.phar require browserstack/local:dev-master
18+
19+
# Install all the dependencies:
20+
php composer.phar install
21+
22+
# Test the installation by running a simple test file, check out example.php in the main repository.
23+
```
24+
2. Configure test capabilities
25+
(To run single test, navigate to ./scripts/single.php)
26+
27+
```php
28+
$caps = array(
29+
'bstack:options' => array(
30+
"os" => "OS X",
31+
"osVersion" => "Sierra",
32+
"buildName" => "Final-Snippet-Test",
33+
"sessionName" => "Selenium-4 PHP snippet test",
34+
"local" => "false",
35+
"seleniumVersion" => "4.0.0",
36+
),
37+
"browserName" => "Chrome",
38+
"browserVersion" => "latest",
39+
);
40+
41+
// Set you credentails
42+
$BROWSERSTACK_USERNAME = "BROWSERSTACK_USERNAME";
43+
$BROWSERSTACK_ACCESS_KEY = "BROWSERSTACK_ACCESS_KEY";
44+
```
45+
46+
## To run tests
47+
### Single test
48+
Run single test session by running.
49+
```
50+
php single.php
51+
```
52+
### Local test
53+
Run local test session by running.
54+
```php
55+
# Update "BROWSERSTACK_ACCESS_KEY" in bs_local.
56+
$bs_local_args = array("key" => "ACCESS_KEY");
57+
```
58+
```
59+
php local.php
60+
```

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require": {
3+
"browserstack/browserstack-local": "^1.1",
4+
"php-webdriver/webdriver": "^1.12"
5+
}
6+
}

composer.lock

Lines changed: 276 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.phar

2.25 MB
Binary file not shown.

scripts/local.php

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

0 commit comments

Comments
 (0)