opnform/tests/DuskTestCase.php

62 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2022-09-20 19:59:52 +00:00
<?php
namespace Tests;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Laravel\Dusk\Page;
use Laravel\Dusk\TestCase as BaseTestCase;
Browser::macro('assertPageIs', function ($page) {
if (! $page instanceof Page) {
2024-02-23 10:54:12 +00:00
$page = new $page();
2022-09-20 19:59:52 +00:00
}
2024-02-23 10:54:12 +00:00
2022-09-20 19:59:52 +00:00
// waiting for location before asserting, because window.location.pathname may be updated asynchronously
return $this->waitForLocation($page->url())->assertPathIs($page->url());
});
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
2024-02-23 10:54:12 +00:00
use DatabaseMigrations;
2022-09-20 19:59:52 +00:00
use TestHelpers;
/**
* Prepare for Dusk test execution.
*
* @beforeClass
2024-02-23 10:54:12 +00:00
*
2022-09-20 19:59:52 +00:00
* @return void
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
2024-02-23 10:54:12 +00:00
$options = (new ChromeOptions())->addArguments([
2022-09-20 19:59:52 +00:00
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
]);
return RemoteWebDriver::create(
2024-02-23 10:54:12 +00:00
'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY,
$options
2022-09-20 19:59:52 +00:00
)
);
}
}