Skip to content

Commit 7514264

Browse files
Ankit098francisf
authored andcommitted
update: local binary fixes
1 parent 2013cd2 commit 7514264

File tree

11 files changed

+60
-80
lines changed

11 files changed

+60
-80
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ local.log
33
vendor/
44
bin/
55
.DS_Store
6+
browserstack.err

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
"php-webdriver/webdriver": "1.14.0"
66
},
77
"scripts": {
8-
"single": "CONFIG_FILE=config/single.conf.json vendor/bin/phpunit tests/SingleTest.php",
9-
"local": "CONFIG_FILE=config/local.conf.json vendor/bin/phpunit tests/LocalTest.php",
10-
"parallel": "CONFIG_FILE=config/parallel.conf.json /usr/bin/env php lib/parallel.php"
8+
"local": "CONFIG_FILE=config/test.conf.json TEST_FILE=tests/LocalTest.php /usr/bin/env php lib/runner.php",
9+
"test": "CONFIG_FILE=config/test.conf.json TEST_FILE=tests/Test.php /usr/bin/env php lib/runner.php"
1110
},
1211
"autoload": {
1312
"classmap": ["lib/"]

config/local.conf.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

config/single.conf.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

config/parallel.conf.json renamed to config/test.conf.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"os": "OS X",
1010
"osVersion": "Monterey",
1111
"buildName": "browserstack-build-1",
12-
"sessionName": "BStack phpunit parallel chrome"
12+
"sessionName": "BStack phpunit chrome",
13+
"local": true
1314
}
1415
}, {
1516
"browserName": "edge",
@@ -18,15 +19,17 @@
1819
"os": "Windows",
1920
"osVersion": "11",
2021
"buildName": "browserstack-build-1",
21-
"sessionName": "BStack phpunit parallel edge"
22+
"sessionName": "BStack phpunit edge",
23+
"local": true
2224
}
2325
}, {
2426
"browserName": "chrome",
2527
"bstack:options": {
2628
"osVersion": "12.0",
2729
"deviceName": "Samsung Galaxy S22 Ultra",
2830
"buildName": "browserstack-build-1",
29-
"sessionName": "BStack phpunit parallel android"
31+
"sessionName": "BStack phpunit android",
32+
"local": true
3033
}
3134
}]
3235
}

lib/BrowserStackTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,11 @@ public static function setUpBeforeClass(): void {
1515
$url = "https://{$GLOBALS['BROWSERSTACK_USERNAME']}:{$GLOBALS['BROWSERSTACK_ACCESS_KEY']}@hub.browserstack.com/wd/hub";
1616
$caps = $CONFIG['capabilities'][$task_id];
1717

18-
if(array_key_exists("local", $caps["bstack:options"]) && $caps["bstack:options"])
19-
{
20-
$bs_local_args = array("key" => $GLOBALS['BROWSERSTACK_ACCESS_KEY']);
21-
self::$bs_local = new BrowserStack\Local();
22-
print("Starting Local Binary...\n");
23-
self::$bs_local->start($bs_local_args);
24-
if (self::$bs_local->isRunning()) {
25-
print("Local binary successfuly started!\n");
26-
}
27-
}
28-
2918
self::$driver = RemoteWebDriver::create($url, $caps);
3019
}
3120

3221
public static function tearDownAfterClass(): void {
3322
self::$driver->quit();
34-
if(self::$bs_local) {
35-
print("Stopping local binary..\n");
36-
self::$bs_local->stop();
37-
}
3823
}
3924
}
4025
?>

lib/globals.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
$config_file = getenv('CONFIG_FILE');
33
if (!$config_file) {
4-
$config_file = 'config/single.conf.json';
4+
$config_file = 'config/test.conf.json';
55
}
66
$GLOBALS['CONFIG'] = json_decode(file_get_contents($config_file), true);
77

lib/parallel.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/runner.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
require_once('vendor/autoload.php');
4+
require_once('lib/globals.php');
5+
6+
$CONFIG = $GLOBALS['CONFIG'];
7+
$procs = array();
8+
9+
$test_file = getenv('TEST_FILE');
10+
if (!$test_file) {
11+
$test_file = 'tests/Test.php';
12+
}
13+
14+
try {
15+
$bs_local_args = array("key" => $GLOBALS['BROWSERSTACK_ACCESS_KEY']);
16+
$bs_local = new BrowserStack\Local();
17+
print("\nStarting Local Binary...\n");
18+
$bs_local->start($bs_local_args);
19+
if ($bs_local->isRunning()) {
20+
print("Local binary successfuly started!\n\n");
21+
}
22+
foreach ($CONFIG['capabilities'] as $key => $value) {
23+
$cmd = "TASK_ID=$key vendor/bin/phpunit $test_file 2>&1\n";
24+
print_r($cmd);
25+
26+
$procs[$key] = popen($cmd, "r");
27+
}
28+
foreach ($procs as $key => $value) {
29+
while (!feof($value)) {
30+
print fgets($value, 4096);
31+
}
32+
pclose($value);
33+
}
34+
} catch (Exception $e) {
35+
echo $e->getMessage();
36+
} finally {
37+
if($bs_local) {
38+
print("\nStopping local binary..\n");
39+
$bs_local->stop();
40+
}
41+
}
42+
43+
?>

tests/LocalTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
require_once('vendor/autoload.php');
33

44
class LocalTest extends BrowserStackTest {
5-
public function testLocal() {
6-
self::$driver->get("http://bs-local.com:45454");
7-
$this->assertStringContainsString('BrowserStack Local', self::$driver->getTitle());
8-
}
5+
6+
public function testLocal() {
7+
self::$driver->get("http://bs-local.com:45454");
8+
$this->assertStringContainsString('BrowserStack Local', self::$driver->getTitle());
9+
}
10+
911
}
1012
?>

tests/Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ public function testBrowserstackDemo() {
1616
// assert item in cart is same as one that was added
1717
$this->assertEquals($item_to_add, $item_in_cart);
1818
}
19+
1920
}
2021
?>

0 commit comments

Comments
 (0)