dusk: Can't run dusk tests on ubuntu 16.04
I am trying laravel dusk on a fresh installation laravel 5.4.x-dev
This is what I get when I run php artisan dusk
PHPUnit 5.7.5 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.13-0ubuntu0.16.04.1 with Xdebug 2.4.0
Configuration: /var/www/html/dusk/phpunit.dusk.xml
E 1 / 1 (100%)
Time: 2.5 minutes, Memory: 10.00MB
There was 1 error:
1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}
Operation timed out after 30000 milliseconds with 0 bytes received
/var/www/html/dusk/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:287
/var/www/html/dusk/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121
/var/www/html/dusk/tests/DuskTestCase.php:32
/var/www/html/dusk/vendor/laravel/dusk/src/TestCase.php:176
/var/www/html/dusk/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639
/var/www/html/dusk/vendor/laravel/dusk/src/TestCase.php:177
/var/www/html/dusk/vendor/laravel/dusk/src/TestCase.php:107
/var/www/html/dusk/vendor/laravel/dusk/src/TestCase.php:81
/var/www/html/dusk/tests/Browser/ExampleTest.php:21
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 26
- Comments: 76 (26 by maintainers)
This problem also exists on Linux Mint (which is unsurprising as it is built on top of Ubuntu).
The problem can be alleviated by running a separate instance of ChromeDriver in a second terminal window and supplying a valid port number (I used chromedriver --port 8888) and then modifying DuskTestCase with:
(Thanks to @abalozz)
Whilst this is ok as a work around it removes one of Dusk’s most appealing features (ie. not having to run a separate selenium server in order to run tests).
I initially assumed that this must be a port conflict with the default (9515) and so tried changing the port without running the separate instance of ChromeDriver but this returns a different error (saying that ChromeDriver can’t be opened on that port).
Running this (with PR #33 included) from within the Homestead vm (vagrant ssh) still gives me
`1) Tests\Browser\ExampleTest::testBasicExample Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {“desiredCapabilities”:{“browserName”:“chrome”,“platform”:“ANY”}}
Failed to connect to localhost port 9515: Connection refused`
Running it from the host takes ~13 seconds every single time. Anybody has an idea what this could cause?
This is my setup
NB: at the moment i didn’t implement a deploy stage and in my test stage i’ve to implement mySQL service. But the core to work with Laravel Dusk is all in there 😃
.gitlab-ci.yml
composer_build.sh
dusk_tests.sh
DuskTestCase.php
I also use Dusk in GitLab CI. With a few adjustments it works fine. Basically, these are:
scriptto emulate a tty--no-sandboxProvide tty
GitLab CI does not provide a tty in its docker runners, so I had to wrap the dusk command into the
scriptcommand:Use Xvfb
I use my own DuskCommand class. It starts Xvfb once for the whole test suite, not for each single test:
It is registered in
AppServiceProvider:Apply
--no-sandboxThis is needed because GitLab CI runs your build script as
rootinside the Docker container. I did this by configuringDuskTestCaseas follows:You might have noticed that I introduced
config('app.env_docker'), so add the following toconfig/app.php:And your
.envfile in GitLab CI should contain:APP_ENV_DOCKER=trueThis ensures that you use--no-sandboxonly as part of your CI pipeline where everything runs in a container, and not on your local machine where this might be a potential security issue.I was generating the same error, but that was why
$browser->resize(1024, 768); // Width and Heightchange it in:and it worked ok
After getting
chrome not reachable, I researched it on the internet and the first link was http://stackoverflow.com/questions/28364012/webdriver-exception-chrome-not-reachable. The accepted answer suggestsno-sandbox.I read about it and it is related to web safety. Google suggests it’s better to use another browser than to use Chrome without sandbox (when talking about regular usage). Without sandbox, the browser is more free to access operating system and user files without any restriction, which explains the lack of security. Given the nature of automated tests on a closed environment and a specific web project, the lack of security doesn’t worry me right now. I still don’t understand why I was able to run Dusk 2 days ago without any issue and now I’m having this problem, but at least I can come back to this some other time.
Increasing timeout to 150 seconds allowed me to gather more information on the problem.
With that, I started getting
And the only solution I have for it so far is to run chrome with
no-sandboxoption.With the
no-sandboxflag I am able to use Dusk successfully.Any clue how to make it available to run Dusk in fresh Linux installation? It works fine in Homestead, but when I try to do the same on fresh Ubuntu installation (Docker), I run first:
and then
but it still doesn’t work. I’m getting:
Yeah, the same for me. I tried ‘–no-sandbox’, because Chrome suggested me to do so. I think it would be good to have the setting in Dusk.
My 2 cents here. I tried the followings and it seems that it is a step closer to running successfully. Yes, it is still not working in my machine. But perhaps it can run on yours.
I tried to execute chromedriver-linux directly, which tells me something like “libnss3.so” is missing. So I run “apt-get install libnss3”. Then it tells me “error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory”. I install “apt-get install libgconf-2-4” as well.
At this point, I can finally run the chromedriver-linux directly. Then I kill the shit that is using port 9515. (That shit is probably the chromedriver-linux.)
I run “php artisan dusk” again. Now it shows this error.
There was 1 error:
[PROJECT_PATH]/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114 [PROJECT_PATH]/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:322 [PROJECT_PATH]/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121 [PROJECT_PATH]/tests/DuskTestCase.php:33 [PROJECT_PATH]/vendor/laravel/dusk/src/TestCase.php:180 [PROJECT_PATH]/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639 [PROJECT_PATH]/vendor/laravel/dusk/src/TestCase.php:181 [PROJECT_PATH]/vendor/laravel/dusk/src/TestCase.php:111 [PROJECT_PATH]/vendor/laravel/dusk/src/TestCase.php:85 [PROJECT_PATH]/tests/Browser/BackendLoginTest.php:16
Time to sleep now. Hope that someone continue figuring out what is going on 😃
P.S. I am running it in Ubuntu 14.04 Server.
SOLVED!!!
In DuskTestCase.php File
Old Code of driver():
Just Add ‘–no-sandbox’ flag
New Code:
On Ubuntu Linux 16.04, I got this to work:
Install Chromium & dependencies for headless testing
sudo apt-get -y install chromium-browser xvfb gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable imagemagick x11-appsCreate a custom
DuskCommandWhich extends the original, with thishandlemethod:@deleugpn i replace the docker/image with this one:
shincoder/homesteadit’s the copy/paste environment of vagrant but in docker.
It works ! i will post my solution as soon as i clean a bit my CI scripts. see you soon and thx all.
Yeah Im working on Xvfb atm think there is the problem in the docker file…
I think they should add an error output and autoexit in chrome with “not allowed to run as root in sandbox mode” this it at least what most of my package managers do (for example yaourt in archlinux), and that way they often stop me from doing more harm than good.
However the generell rule in linux is try to do as little as possible with root, especially if youre working with webapps and scripting languages such as php…
@mrdevries Works fine on my host too, but I’m not experiencing much lag, might be a hardware thing. There should be a note in the docs that Dusk isn’t compatible with Homestead.
All of my previous tests are now failing and impossible to run on my Homestead and continous-integration servers. Good thing there’s the new
laravel/browser-kit-testingpackage, which supports the my tests. Learn more here: https://laravel.com/docs/5.4/upgrade#upgrade-5.4.0