Skip to content

Commit 7900a5c

Browse files
hariharanbrowserstackfrancisf
authored andcommitted
Fixing Tests for Windows
1 parent 99119e0 commit 7900a5c

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
mv composer.phar /usr/local/bin/composer
2727
```
2828

29+
3. If php usage is different, for example, if php.exe is used instead of php in certain windows, please change that accordingly to run the tests.
30+
2931
## Setup
3032
* Clone the repo
3133
* Install dependencies using: `composer install`

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"php-webdriver/webdriver": "1.14.0"
66
},
77
"scripts": {
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"
8+
"local": "php triggerTest.php tests LocalTest.php",
9+
"test": "php triggerTest.php tests Test.php"
1010
},
1111
"autoload": {
1212
"classmap": ["lib/"]

lib/BrowserStackTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static function setUpBeforeClass(): void {
1313
$task_id = getenv('TASK_ID') ? getenv('TASK_ID') : 0;
1414

1515
$url = "https://{$GLOBALS['BROWSERSTACK_USERNAME']}:{$GLOBALS['BROWSERSTACK_ACCESS_KEY']}@hub.browserstack.com/wd/hub";
16-
$caps = $CONFIG['capabilities'][$task_id];
16+
$caps = $CONFIG['capabilities'][(int)$task_id];
1717

1818
self::$driver = RemoteWebDriver::create($url, $caps);
1919
}

lib/runner.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313

1414
try {
1515
// the following code starts local binary, comment out if local testing not needed
16+
// Start local binary with additional args "logfile" => "logs.txt", "v" => true to get the local not started logs for debugging.
1617
$bs_local_args = array("key" => $GLOBALS['BROWSERSTACK_ACCESS_KEY']);
1718
$bs_local = new BrowserStack\Local();
19+
$currentOS = strtoupper(substr(PHP_OS, 0, 3));
1820
print("\nStarting Local Binary...\n");
1921
$bs_local->start($bs_local_args);
2022
if ($bs_local->isRunning()) {
2123
print("Local binary successfuly started!\n\n");
2224
}
2325
foreach ($CONFIG['capabilities'] as $key => $value) {
2426
$cmd = "TASK_ID=$key vendor/bin/phpunit $test_file 2>&1\n";
27+
if ($currentOS == 'WIN') {
28+
$cmd = "set TASK_ID=$key && vendor\bin\phpunit $test_file 2>&1\n";
29+
}
2530
print_r($cmd);
2631

2732
$procs[$key] = popen($cmd, "r");
@@ -34,6 +39,7 @@
3439
}
3540
} catch (Exception $e) {
3641
echo $e->getMessage();
42+
echo "Exception Trace:\n" . $e->getTraceAsString() . "\n";
3743
} finally {
3844
if($bs_local) {
3945
print("\nStopping local binary..\n");

triggerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
// Check if an argument is provided for config_file
3+
$testFileArg = $argv[1] ?? 'Test.php';
4+
$testFile = "tests" . DIRECTORY_SEPARATOR . $var2;
5+
putenv("TEST_FILE=$testFile");
6+
putenv('CONFIG_FILE=config/test.conf.json');
7+
// Execute the PHP script with the dynamically retrieved value
8+
require 'lib/runner.php';
9+
10+
?>

0 commit comments

Comments
 (0)