14

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?

Petar Vasilev
  • 4,281
  • 5
  • 40
  • 74

4 Answers4

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
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.

enter image description here

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