I am writing some tests and I want to see whether Dusk correctly fills in the input fields but Dusk doesn't show the browser while running the tests, is there any way to force it to do that?
Asked
Active
Viewed 7,362 times
14
-
Are you running from inside Homestead or Outside? If inside there will be no display for it to be viewed on. If outside it should fire up chrome for each test. – Andrew Bibby Apr 20 '18 at 13:42
-
Can you use screenshots for that? – Jonas Staudenmeir Apr 20 '18 at 13:56
-
@AndrewBibby I am not using Homestead/Vagrant – Petar Vasilev Apr 21 '18 at 10:16
-
@JonasStaudenmeir I guess I can do that but it would be easier if the browser was visible – Petar Vasilev Apr 21 '18 at 10:17
4 Answers
28
Disable the headless mode in tests\DuskTestCase.php
file driver()
function:
$options = (new ChromeOptions)->addArguments([
//'--disable-gpu',
//'--headless'
]);

mohammad asghari
- 1,817
- 1
- 16
- 23

Jonas Staudenmeir
- 24,815
- 6
- 63
- 109
-
1maybe something changed, but the tests just hang forever when I comment these lines, no window opens – MightyPork Jan 09 '19 at 10:58
-
-
1
-
-
geez it's you.. you already asked me this in that github issue lol *explains why this also doesn't work... – MightyPork Jan 11 '19 at 20:25
7
Updated (2021):
You can disable headless with 2 methods:
Method 1: Add this to your .env
DUSK_HEADLESS_DISABLED=true
Method 2: Add this to your special test case if you don't need to show the browser for all tests
protected function hasHeadlessDisabled(): bool
{
return true;
}
Btw, I don't know why these are not mentioned in the documentation. I found the above methods myself from DuskTestCase.php.

Tuan Ha
- 620
- 2
- 8
- 25
2
Answer for Laravel 8 & UP
You can use php artisan dusk --browse
to force showing the browser.

Tadeo Rod
- 574
- 5
- 11
1
Near the top of your tests/DuskTestCase.php
file, add:
use Facebook\WebDriver\Chrome\ChromeOptions;
In that same file, replace the entire driver()
function with:
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver() {
$options = (new ChromeOptions)->addArguments([
//'--disable-gpu',
//'--headless'//https://stackoverflow.com/q/49938673/470749
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}

Ryan
- 22,332
- 31
- 176
- 357
-
See also https://laracasts.com/discuss/channels/testing/dusk-works-without-opening-browser#reply=379532 and https://stackoverflow.com/a/47960068/470749 and https://laracasts.com/discuss/channels/testing/is-there-any-way-to-show-browser-window-when-running-dusk-tests-from-within-homestead – Ryan Dec 13 '18 at 02:39