Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit ba2062c

Browse files
committed
Add action collectors to scoped component browser instances
1 parent c12c31e commit ba2062c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Dusk/Browser.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace BeyondCode\DuskDashboard\Dusk;
44

5+
use Closure;
56
use BeyondCode\DuskDashboard\BrowserActionCollector;
67

78
class Browser extends \Laravel\Dusk\Browser
@@ -61,6 +62,30 @@ public function refresh()
6162
return $browser;
6263
}
6364

65+
/** {@inheritdoc} */
66+
public function with($selector, Closure $callback)
67+
{
68+
$action_collector_callback = function ($browser) use ($callback) {
69+
print 'Entering the wrapped callback...';
70+
$browser->setActionCollector($this->getActionCollector());
71+
72+
print 'Wrapped callback invoked & updated browser!';
73+
return $callback($browser);
74+
};
75+
76+
return parent::with($selector, $action_collector_callback);
77+
}
78+
79+
/** {@inheritDoc} */
80+
public function onComponent($component, $parentResolver)
81+
{
82+
if ($this->getActionCollector() === null) {
83+
$this->setActionCollector(new BrowserActionCollector('dog'));
84+
}
85+
86+
parent::onComponent($component, $parentResolver);
87+
}
88+
6489
public function getCurrentPageSource()
6590
{
6691
$this->ensurejQueryIsAvailable();

0 commit comments

Comments
 (0)