Skip to content

Commit d5a4ace

Browse files
RutvikChandlafrancisf
authored andcommitted
selenium 3 changes
1 parent bb70ba3 commit d5a4ace

File tree

7 files changed

+420
-0
lines changed

7 files changed

+420
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,57 @@
11

2+
# php-selenium-browserstack
3+
4+
## Prerequisites
5+
1. php and composer should be installed in your system
6+
2. Go to the directory where you have your test scripts and run the command below:
7+
```
8+
composer require php-webdriver/webdriver
9+
```
10+
11+
## Steps to run test sessions
12+
1. Install dependencies
13+
```
14+
# If you don't already use Composer, you can download the composer.phar binary:
15+
curl -sS https://getcomposer.org/installer | php
16+
17+
# Include the binding:
18+
php composer.phar require browserstack/local:dev-master
19+
20+
# Install all the dependencies:
21+
php composer.phar install
22+
23+
# Test the installation by running a simple test file, check out example.php in the main repository.
24+
```
25+
2. Configure test capabilities
26+
(To run single test, navigate to ./scripts/single/php)
27+
28+
```php
29+
$caps = array(
30+
"browserName" => "iPhone",
31+
"device" => "iPhone 11",
32+
"realMobile" => "true",
33+
"os_version" => "14.0",
34+
"name" => "BStack-[Php] Sample Test", // test name
35+
"build" => "BStack Build Number 1" // CI/CD job or build name
36+
);
37+
// IMP: Use your browserstack username and accesskey
38+
$web_driver = RemoteWebDriver::create("https://USERNAME:[email protected]/wd/hub",$caps);
39+
```
40+
41+
3. Run tests
42+
Single test
43+
```
44+
php single.php
45+
```
46+
47+
Local test
48+
Along with step-2 also use your Accesskey to bs_loca_args
49+
```php
50+
# In file ./scripts/local.php
51+
# You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
52+
$bs_local_args = array("key" => "ACCESS_KEY");
53+
```
54+
55+
```
56+
php single.php
57+
```

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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
# Creates an instance of Local
9+
$bs_local = new Local();
10+
11+
# You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
12+
$bs_local_args = array("key" => "ACCESS_KEY");
13+
# Starts the Local instance with the required arguments
14+
$bs_local->start($bs_local_args);
15+
16+
# Check if BrowserStack local instance is running
17+
echo $bs_local->isRunning();
18+
$caps = array(
19+
"browserName" => "iPhone",
20+
"device" => "iPhone 11",
21+
"realMobile" => "true",
22+
"os_version" => "14.0",
23+
"browserstack.local" => "true",
24+
"name" => "BStack-[Php] Sample Test", // test name
25+
"build" => "BStack Build Number 1" // CI/CD job or build name
26+
);
27+
$web_driver = RemoteWebDriver::create("https://USERNAME:[email protected]/wd/hub",$caps);
28+
try{
29+
$web_driver->get("http://bs-local.com:45691/check");
30+
$body_text = $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector("body")))->getText();
31+
# Setting the status of test as 'passed' or 'failed' based on the condition; if title of the web page starts with 'BrowserStack'
32+
if ($body_text == "Up and running"){
33+
$web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed", "reason": "Local test ran successfully"}}' );
34+
} else {
35+
$web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": "Failed to load local test"}}');
36+
}
37+
}
38+
catch(Exception $e){
39+
echo 'Message: ' .$e->getMessage();
40+
}
41+
$web_driver->quit();
42+
# Stop the Local instance
43+
$bs_local->stop();
44+
?>

0 commit comments

Comments
 (0)