|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BeyondCode\DuskDashboard\Dusk; |
|
4
|
|
|
|
|
5
|
|
|
use BeyondCode\DuskDashboard\BrowserActionCollector; |
|
6
|
|
|
|
|
7
|
|
|
class Browser extends \Laravel\Dusk\Browser |
|
8
|
|
|
{ |
|
9
|
|
|
use Concerns\InteractsWithAuthentication, |
|
10
|
|
|
Concerns\InteractsWithCookies, |
|
11
|
|
|
Concerns\InteractsWithElements, |
|
12
|
|
|
Concerns\InteractsWithJavascript, |
|
13
|
|
|
Concerns\InteractsWithMouse, |
|
14
|
|
|
Concerns\MakesAssertions, |
|
15
|
|
|
Concerns\MakesUrlAssertions, |
|
16
|
|
|
Concerns\WaitsForElements; |
|
17
|
|
|
|
|
18
|
|
|
/** @var BrowserActionCollector */ |
|
19
|
|
|
protected $actionCollector; |
|
20
|
|
|
|
|
21
|
|
|
public function setActionCollector(BrowserActionCollector $collector) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->actionCollector = $collector; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return BrowserActionCollector|null |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getActionCollector() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->actionCollector; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** {@inheritdoc} */ |
|
35
|
|
|
public function visit($url) |
|
36
|
|
|
{ |
|
37
|
|
|
$browser = parent::visit($url); |
|
38
|
|
|
|
|
39
|
|
|
$this->actionCollector->collect(__FUNCTION__, func_get_args(), $this); |
|
40
|
|
|
|
|
41
|
|
|
return $browser; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** {@inheritdoc} */ |
|
45
|
|
|
public function visitRoute($route, $parameters = []) |
|
46
|
|
|
{ |
|
47
|
|
|
$browser = parent::visitRoute($route, $parameters); |
|
48
|
|
|
|
|
49
|
|
|
$this->actionCollector->collect(__FUNCTION__, func_get_args(), $this); |
|
50
|
|
|
|
|
51
|
|
|
return $browser; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** {@inheritdoc} */ |
|
55
|
|
|
public function refresh() |
|
56
|
|
|
{ |
|
57
|
|
|
$browser = parent::refresh(); |
|
58
|
|
|
|
|
59
|
|
|
$this->actionCollector->collect(__FUNCTION__, func_get_args(), $this); |
|
60
|
|
|
|
|
61
|
|
|
return $browser; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getCurrentPageSource() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->ensurejQueryIsAvailable(); |
|
67
|
|
|
|
|
68
|
|
|
$this->restoreHtml(); |
|
69
|
|
|
|
|
70
|
|
|
return $this->driver->executeScript('return document.documentElement.innerHTML;'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function restoreHtml() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->driver->executeScript("jQuery('input').attr('value', function() { return jQuery(this).val(); });"); |
|
76
|
|
|
|
|
77
|
|
|
$this->driver->executeScript("jQuery('input[type=checkbox]').each(function() { jQuery(this).attr('checked', jQuery(this).prop(\"checked\")); });"); |
|
78
|
|
|
|
|
79
|
|
|
$this->driver->executeScript("jQuery('textarea').each(function() { jQuery(this).html(jQuery(this).val()); });"); |
|
80
|
|
|
|
|
81
|
|
|
$this->driver->executeScript("jQuery('input[type=radio]').each(function() { jQuery(this).attr('checked', this.checked); });"); |
|
82
|
|
|
|
|
83
|
|
|
$this->driver->executeScript("jQuery('select option').each(function() { jQuery(this).attr('selected', this.selected); });"); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|