Docker Laradock Browsertest with Dusk: default test returned empty page

  • Docker: 19.03.5, build 633a0ea
  • Laravel 6.*

I try to move my projects from Vbox to DOCKER. Currently it is a LARAVEL-Project. For this purpose I installed a test project following the instruction by laradock.

Seems working fine, but if I try to execute the default browser test, the response from the test is an empty page…

.en.dusk

...
APP_URL=http://localhost:8000
...

tests/Browser/ExampleTest.php

<?php

class ExampleTest extends DuskTestCase
{

    /**
     * @return FacebookWebDriverRemoteRemoteWebDriver
     */
    protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox',
        ]);

        return RemoteWebDriver::create(
            'http://localhost:9515',
            DesiredCapabilities::chrome()->setCapability(ChromeOptions::CAPABILITY, $options)
        );
    }

    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/');

            var_dump(
                $browser->driver->getCurrentURL(),
                $browser->driver->getPageSource()
            );
        });
    }
}

…and running the test:

[email protected]:/var/www/project_http# php artisan dusk
PHPUnit 8.5.0 by Sebastian Bergmann and contributors.

R                                                                   1 / 1 (100%)string(22) "http://localhost:8000/"
string(39) "<html><head></head><body></body></html>"


Time: 1.38 seconds, Memory: 16.00 MB

There was 1 risky test:

1) TestsBrowserExampleTest::testBasicExample
This test did not perform any assertions

/var/www/project_http/tests/Browser/ExampleTest.php:37

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.

Seems the issue is about the APP_URL in the .env.dusk file, but which url do I have to use, to run the test successfully?

If I call the page from the host, the page shows content like expected (the default page by laravel)

Source: StackOverflow