-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathBrowserTestCase.php
More file actions
73 lines (61 loc) · 2.22 KB
/
BrowserTestCase.php
File metadata and controls
73 lines (61 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Tests;
use Exception;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;
use Laravel\Dusk\Browser;
use Laravel\Dusk\Dusk;
use Laravel\Dusk\TestCase as BaseTestCase;
abstract class BrowserTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* @throws Exception
*/
public function setUp(): void
{
// The APP_URL must be set prior to config initialization so we can correctly generate test URLs.
$env_contents = file_get_contents('/cdash/.env');
if ($env_contents === false) {
throw new Exception('Unable to read .env file.');
}
$env_after_substitution = str_replace('APP_URL=http://localhost:8080', 'APP_URL=http://website:8080', $env_contents);
file_put_contents('/cdash/.env', $env_after_substitution);
parent::setUp();
Dusk::selectorHtmlAttribute('data-test');
Browser::$baseUrl = 'http://website:8080';
Browser::$waitSeconds = 10;
}
public function tearDown(): void
{
parent::tearDown();
$env_contents = file_get_contents(base_path('.env'));
if ($env_contents === false) {
throw new Exception('Unable to read .env file.');
}
$env_after_substitution = str_replace('APP_URL=http://website:8080', 'APP_URL=http://localhost:8080', $env_contents);
file_put_contents(base_path('.env'), $env_after_substitution);
}
/**
* Create the RemoteWebDriver instance.
*/
protected function driver(): RemoteWebDriver
{
$options = (new ChromeOptions())->addArguments(collect([
'--window-size=1920,1080',
'--disable-search-engine-choice-screen',
])->unless($this->hasHeadlessDisabled(), fn (Collection $items) => $items->merge([
'--disable-gpu',
'--headless=new',
]))->all());
return RemoteWebDriver::create(
'http://selenium:4444/wd/hub',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
}