diff --git a/composer.json b/composer.json index 6c290ff..497d1cb 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "php-webdriver/webdriver": "1.14.0" }, "scripts": { - "local": "CONFIG_FILE=config/test.conf.json TEST_FILE=tests/LocalTest.php /usr/bin/env php lib/runner.php", - "test": "CONFIG_FILE=config/test.conf.json TEST_FILE=tests/Test.php /usr/bin/env php lib/runner.php" + "local": "php triggertest.php LocalTest.php", + "test": "php triggertest.php Test.php" }, "autoload": { "classmap": ["lib/"] diff --git a/config/test.conf.json b/config/test.conf.json index 881100e..64ce683 100644 --- a/config/test.conf.json +++ b/config/test.conf.json @@ -5,31 +5,28 @@ "capabilities": [{ "browserName": "chrome", "browserVersion": "latest", - "bstack:options": { - "os": "OS X", - "osVersion": "Monterey", - "buildName": "browserstack-build-1", - "sessionName": "BStack phpunit chrome", - "local": true - } + "os": "OS X", + "os_version": "Monterey", + "build": "browserstack-build-1", + "name": "BStack phpunit chrome", + "browserstack.source": "phpunit:sample-selenium-3:v1.0", + "browserstack.local": true }, { "browserName": "edge", "browserVersion": "latest", - "bstack:options": { - "os": "Windows", - "osVersion": "11", - "buildName": "browserstack-build-1", - "sessionName": "BStack phpunit edge", - "local": true - } + "os": "Windows", + "os_version": "11", + "build": "browserstack-build-1", + "name": "BStack phpunit edge", + "browserstack.source": "phpunit:sample-selenium-3:v1.0", + "browserstack.local": true }, { "browserName": "chrome", - "bstack:options": { - "osVersion": "12.0", - "deviceName": "Samsung Galaxy S22 Ultra", - "buildName": "browserstack-build-1", - "sessionName": "BStack phpunit android", - "local": true - } + "os_version": "12.0", + "deviceName": "Samsung Galaxy S22 Ultra", + "build": "browserstack-build-1", + "name": "BStack phpunit android", + "browserstack.source": "phpunit:sample-selenium-3:v1.0", + "browserstack.local": true }] } diff --git a/lib/BrowserStackTest.php b/lib/BrowserStackTest.php index e06d06b..9e1baf5 100644 --- a/lib/BrowserStackTest.php +++ b/lib/BrowserStackTest.php @@ -13,7 +13,7 @@ public static function setUpBeforeClass(): void { $task_id = getenv('TASK_ID') ? getenv('TASK_ID') : 0; $url = "https://{$GLOBALS['BROWSERSTACK_USERNAME']}:{$GLOBALS['BROWSERSTACK_ACCESS_KEY']}@hub.browserstack.com/wd/hub"; - $caps = $CONFIG['capabilities'][$task_id]; + $caps = $CONFIG['capabilities'][(int)$task_id]; self::$driver = RemoteWebDriver::create($url, $caps); } diff --git a/lib/runner.php b/lib/runner.php index 6396a60..72ced81 100644 --- a/lib/runner.php +++ b/lib/runner.php @@ -13,8 +13,10 @@ try { // the following code starts local binary, comment out if local testing not needed - $bs_local_args = array("key" => $GLOBALS['BROWSERSTACK_ACCESS_KEY']); + // Local binary started with additional args "logfile" => "logs.txt", "v" => true to get the local not started logs for debugging. Please remove them if not needed and cleanup logs if becoming huge. + $bs_local_args = array("key" => $GLOBALS['BROWSERSTACK_ACCESS_KEY'], "logfile" => "logs.txt", "v" => true); $bs_local = new BrowserStack\Local(); + $currentOS = strtoupper(substr(PHP_OS, 0, 3)); print("\nStarting Local Binary...\n"); $bs_local->start($bs_local_args); if ($bs_local->isRunning()) { @@ -22,6 +24,9 @@ } foreach ($CONFIG['capabilities'] as $key => $value) { $cmd = "TASK_ID=$key vendor/bin/phpunit $test_file 2>&1\n"; + if ($currentOS == 'WIN') { + $cmd = "set TASK_ID=$key && vendor\bin\phpunit $test_file 2>&1\n"; + } print_r($cmd); $procs[$key] = popen($cmd, "r"); @@ -34,6 +39,7 @@ } } catch (Exception $e) { echo $e->getMessage(); + echo "Exception Trace:\n" . $e->getTraceAsString() . "\n"; } finally { if($bs_local) { print("\nStopping local binary..\n"); diff --git a/triggertest.php b/triggertest.php new file mode 100644 index 0000000..52ec2eb --- /dev/null +++ b/triggertest.php @@ -0,0 +1,11 @@ +