addArguments([ '--disable-gpu', '--headless', '--window-size=1920,1080', ]); return RemoteWebDriver::create( 'http://localhost:9515', DesiredCapabilities::chrome()->setCapability( ChromeOptions::CAPABILITY, $options ) ); } public function setUp(): void { $this->resetManagers(); parent::setUp(); // Ensure system is up to date if ($this->usingTestDatabase) { $this->runOctoberUpCommand(); } // Detect a plugin and autoload it, if necessary $this->detectPlugin(); // Disable mailer \Mail::pretend(); Browser::$baseUrl = $this->baseUrl(); Browser::$storeScreenshotsAt = base_path('tests/Browser/screenshots'); Browser::$storeConsoleLogAt = base_path('tests/Browser/console'); Browser::$userResolver = function () { return $this->user(); }; $this->setupMacros(); } public function tearDown(): void { if ($this->usingTestDatabase && isset($this->testDatabasePath)) { unlink($this->testDatabasePath); } parent::tearDown(); } /** * Defines October macros for use in browser tests * * @return void */ protected function setupMacros() { /** * Signs the user into the backend */ Browser::macro('signInToBackend', function (string $username = null, string $password = null) { $username = $username ?? env('DUSK_ADMIN_USER', 'admin'); $password = $password ?? env('DUSK_ADMIN_PASS', 'admin1234'); $this ->visit(new Login) ->pause(500) ->type('@loginField', $username) ->type('@passwordField', $password) ->click('@submitButton'); $this-> on(new Dashboard); return $this; }); Browser::macro('hasClass', function (string $selector, string $class) { $classes = preg_split('/\s+/', $this->attribute($selector, 'class'), -1, PREG_SPLIT_NO_EMPTY); if (empty($classes)) { return false; } return in_array($class, $classes); }); } /** * Similar to the native getConfirmation() function */ protected function getSweetConfirmation($expectedText = null, $clickOk = true) { $this->waitForElementPresent("xpath=(//div[@class='sweet-alert showSweetAlert visible'])[1]"); if ($expectedText) { $this->verifyText("//div[@class='sweet-alert showSweetAlert visible']//h4", $expectedText); } $this->verifyText("//div[@class='sweet-alert showSweetAlert visible']//button[@class='confirm btn btn-primary']", "OK"); if ($clickOk) { $this->click("xpath=(//div[@class='sweet-alert showSweetAlert visible']//button[@class='confirm btn btn-primary'])[1]"); } } }