This repository was archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathTestCase.php
More file actions
94 lines (78 loc) · 2.78 KB
/
TestCase.php
File metadata and controls
94 lines (78 loc) · 2.78 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
<?php
namespace BeyondCode\DuskDashboard\Testing;
use Closure;
use Throwable;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use BeyondCode\DuskDashboard\Dusk\Browser;
use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use BeyondCode\DuskDashboard\BrowserActionCollector;
use BeyondCode\DuskDashboard\BrowserReportCollector;
use BeyondCode\DuskDashboard\Console\StartDashboardCommand;
abstract class TestCase extends BaseTestCase
{
/**
* Create a new Browser instance.
*
* @param \Facebook\WebDriver\Remote\RemoteWebDriver $driver
* @return \BeyondCode\DuskDashboard\Dusk\Browser
*/
protected function newBrowser($driver)
{
return new Browser($driver);
}
/**
* Create the browser instances needed for the given callback.
*
* @param \Closure $callback
* @return array
* @throws \ReflectionException
*/
protected function createBrowsersFor(Closure $callback)
{
$browsers = parent::createBrowsersFor($callback);
foreach ($browsers as $browser) {
$browser->setActionCollector(new BrowserActionCollector($this->getTestName()));
$browser->setReportCollector(new BrowserReportCollector($this->getTestName()));
}
static::$browsers = $browsers;
return static::$browsers;
}
protected function getTestName()
{
return class_basename(static::class).'::'.$this->getName();
}
protected function enableNetworkLogging(DesiredCapabilities $capabilities): DesiredCapabilities
{
$chromeOptions = $capabilities->getCapability(ChromeOptions::CAPABILITY);
$perfLoggingPrefs = new \stdClass();
$perfLoggingPrefs->enableNetwork = true;
$chromeOptions->setExperimentalOption('perfLoggingPrefs', $perfLoggingPrefs);
$capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
$loggingPrefs = new \stdClass();
$loggingPrefs->browser = 'ALL';
$loggingPrefs->performance = 'ALL';
$capabilities->setCapability('loggingPrefs', $loggingPrefs);
return $capabilities;
}
protected function onNotSuccessfulTest(Throwable $t): void
{
try {
(new Client())->post('http://127.0.0.1:'.StartDashboardCommand::PORT.'/events', [
RequestOptions::JSON => [
'channel' => 'dusk-dashboard',
'name' => 'dusk-failure',
'data' => [
'message' => $t->getMessage(),
],
],
]);
} catch (\Exception $e) {
// Dashboard is offline
} finally {
parent::onNotSuccessfulTest($t);
}
}
}