diff --git a/app/Traits/SupportsBrowserStack.php b/app/Traits/SupportsBrowserStack.php new file mode 100644 index 0000000000000000000000000000000000000000..8a54244e3e6010cad8067bb47ffd90320e4a2d4d --- /dev/null +++ b/app/Traits/SupportsBrowserStack.php @@ -0,0 +1,47 @@ +<?php +namespace App\Traits; + +use BrowserStack\Local; +use Facebook\WebDriver\Remote\RemoteWebDriver; + +/** + * Run BrowserStack from your tests. + */ +trait SupportsBrowserStack +{ + protected static $web_driver, $bs_local; + /** + * Create the BrowserStack WebDriver instance. + */ + public function createBrowserStackDriver(array $config = null): RemoteWebDriver + { + if ($config["capabilities"]["browserstack.local"] === "true") { + $this->bs_local = new Local(); + $bs_local_args = [ + "key" => $config["key"], + ]; + $this->bs_local->start($bs_local_args); + } + + $this->web_driver = RemoteWebDriver::create( + "https://$config[username]:$config[key]@hub-cloud.browserstack.com/wd/hub", + $config["capabilities"] + ); + + return $this->web_driver; + } + + /** + * @afterClass + */ + public static function shutdown() + { + if (static::$bs_local && static::$bs_local->isRunning()) { + static::$bs_local->stop(); + } + if (static::$web_driver) { + static::$web_driver->quit(); + } + } + +} diff --git a/composer.json b/composer.json index 49624c8e5efcbac6e71df921e7594df0e60b2cac..9355e6fc34eaa29601f2daeac6f4da7c30793eea 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,6 @@ "browserstack/browserstack-local": "^1.1", "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", - "galahad/dusk-browserstack": "^2.0", "laravel/dusk": "^5.0", "mockery/mockery": "^1.0", "nunomaduro/collision": "^3.0", @@ -71,4 +70,4 @@ "@php artisan key:generate --ansi" ] } -} +} \ No newline at end of file diff --git a/tests/Browser/console/browserstack.log b/tests/Browser/console/browserstack.log deleted file mode 100644 index 99fc21a16d5041097c562653b55a37547dce64cb..0000000000000000000000000000000000000000 --- a/tests/Browser/console/browserstack.log +++ /dev/null @@ -1,10 +0,0 @@ - - -/bin/sh: 1: ps: not found -/bin/sh: 1: ps: not found -Tue Aug 04 2020 12:39:58 GMT+0000 (UTC) -- [INFO] Started the BrowserStack Binary server on 45691, PID: 28 -Tue Aug 04 2020 12:39:58 GMT+0000 (UTC) -- [SUCCESS] You can now access your local server(s) in our remote browser - -Tue Aug 04 2020 12:39:59 GMT+0000 (UTC) -- Press Ctrl-C to exit - - diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php index 4121bf2cc2166009db266589869b2e6a609083f1..e22536cbfd9e21df44a3184d6f8550d0db90bbde 100644 --- a/tests/DuskTestCase.php +++ b/tests/DuskTestCase.php @@ -3,8 +3,8 @@ namespace Tests; use Facebook\WebDriver\Remote\RemoteWebDriver; -use Galahad\BrowserStack\SupportsBrowserStack; use Laravel\Dusk\TestCase as BaseTestCase; +use \App\Traits\SupportsBrowserStack; abstract class DuskTestCase extends BaseTestCase { @@ -51,9 +51,6 @@ abstract class DuskTestCase extends BaseTestCase "username" => env("WEBDRIVER_USER", ""), "key" => env("WEBDRIVER_KEY", ""), "capabilities" => $capabilities, - "local_config" => [ - "key" => env("WEBDRIVER_KEY", ""), - ], ]); } }