-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathDuskTestCase.php
More file actions
111 lines (100 loc) · 3.52 KB
/
DuskTestCase.php
File metadata and controls
111 lines (100 loc) · 3.52 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace Tests;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\TestCase as BaseTestCase;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Prepare for Dusk test execution.
*
* @beforeClass
* @return void
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
/**
* Run in a real browser. You can tunnel through vagrant by running
* ssh vagrant@192.168.10.10 -N -R 4444:localhost:4444
* Then start selenium standalone server on your host machine
* (Install it with `brew install selenium-server-standalone`)
*/
if (env('SELENIUM_SERVER')) {
$options = (new ChromeOptions)->addArguments([
'--ignore-ssl-errors',
'--window-size=1200,720',
]);
return RemoteWebDriver::create(
env('SELENIUM_SERVER'), // 'http://localhost:4444/wd/hub/',
DesiredCapabilities::chrome()
->setCapability(ChromeOptions::CAPABILITY, $options)
->setCapability('acceptInsecureCerts', true)
);
/**
* Run in Saucelabs. This is only use for CircleCI
*/
} elseif (env('SAUCELABS_BROWSER_TESTING')) {
return RemoteWebDriver::create(
'https://' . env('SAUCELABS_USERNAME') . ':' . env('SAUCELABS_ACCESS_KEY') . '@ondemand.saucelabs.com:443/wd/hub',
[
'platform' => env('SAUCELABS_PLATFORM', 'Windows 10'),
'browserName' => env('SAUCELABS_BROWSER', 'chrome'),
'version' => env('SAUCELABS_BROWSER_VERSION', '73'),
]
);
/**
* Run with default headless mode in the vagrant machine
*/
} else {
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--no-sandbox',
'--ignore-ssl-errors',
'--window-size=1200,720',
'--whitelisted-ips=""',
]);
return RemoteWebDriver::create(
'http://localhost:9515',
DesiredCapabilities::chrome()
->setCapability(ChromeOptions::CAPABILITY, $options)
->setCapability('acceptInsecureCerts', true)
);
}
}
protected function setUp(): void
{
parent::setUp();
$sqlFile = sys_get_temp_dir() . '/testDB.sql';
$arg = [
env('DB_HOSTNAME'),
env('DB_PORT'),
env('DB_USERNAME'),
env('DB_PASSWORD'),
env('DB_DATABASE'),
$sqlFile,
];
if (!file_exists($sqlFile) || env('CLEAN_DB', false) === true) {
$this->artisan('migrate:fresh', [
'--seed' => true,
'--force' => true,
]);
$cmd = base_path('tests/Browser/mysql_backup.sh') . ' ' . implode(' ', $arg);
exec($cmd, $out, $ret);
} else {
$cmd = base_path('tests/Browser/mysql_restore.sh') . ' ' . implode(' ', $arg) . ' 2>&1';
exec($cmd, $out, $ret);
}
}
}