Closed SaeedPrez closed 7 years ago
Me too on latest Homestead. Doesn't work on Windows 10 either.
Try this fork https://github.com/spyric/dusk/tree/windows In alpha there was no compability with Windows. This fork should fix this issue, but it still not merged
Thanks @spyric I tried that yesterday and even though it didn't help the problem mentioned in the first post, I was able to run Dusk from Windows command prompt.
Finally got it working in Vagrant on Ubuntu 14.04 (not a Homestead image though). My host OS is Windows 10.
First of all, google-chrome
is requried to be installed in guest OS:
$ wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
$ sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
$ sudo apt-get update && sudo apt-get install -y google-chrome-stable
Next thing is xvfb
:
$ sudo apt-get install -y xvfb
Try to start ./vendor/laravel/dusk/bin/chromedriver-linux --port=8888
. If you have some errors about loading libraries (libnss3.so
, libgconf-2.so.4
), try this:
$ sudo apt-get install -y libnss3-dev libxi6 libgconf-2-4
When you see
$ ./vendor/laravel/dusk/bin/chromedriver-linux --port=8888
Starting ChromeDriver 2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e) on port 8888
Only local connections are allowed.
this means ChromeDriver can be started (so SupportsChrome
trait should be able to start it too). You can stop this process for now (Ctrl+C).
Run
$ Xvfb :0 -screen 0 1280x960x24 &
in a separate terminal window.
Also you may want to add your dev domain in guest's /etc/hosts
file:
127.0.0.1 domain.dev
.
And finally run
$ php artisan dusk
PHPUnit 5.7.6 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 3.15 seconds, Memory: 10.00MB
OK (1 test, 1 assertion)
I didn't try more complex tests for now, but assume they should work. The only thing I've noticed not working is a screenshot feature. I have blank white screen instead of actual browser window.
Edit: screenshots feature is working, just don't load Google Fonts.
I'm having issues running on Homestead as well, but I'm running my Vagrant box on Linux Mint. I have updated Homestead to latest, and tried using a new test site. Also, tried the various methods listed above which didn't work.
If I follow the Dusk setup exactly, I get the following:
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"}}
Failed to connect to localhost port 9515: Connection refused
/home/vagrant/test/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:287
/home/vagrant/test/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121
/home/vagrant/test/tests/DuskTestCase.php:32
/home/vagrant/test/vendor/laravel/dusk/src/TestCase.php:180
/home/vagrant/test/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639
/home/vagrant/test/vendor/laravel/dusk/src/TestCase.php:181
/home/vagrant/test/vendor/laravel/dusk/src/TestCase.php:111
/home/vagrant/test/vendor/laravel/dusk/src/TestCase.php:85
/home/vagrant/test/tests/Browser/ExampleTest.php:21
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
EDIT
I have gotten a little farther by marking the /vendor/laravel/dusk/bin/chromedriver-linux executable:
chmod a+x ./vendor/laravel/dusk/bin/chromedriver-linux
After making this edit, I now get a timeout error:
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
/home/vagrant/test/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:287
/home/vagrant/test/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121
/home/vagrant/test/tests/DuskTestCase.php:32
/home/vagrant/test/vendor/laravel/dusk/src/TestCase.php:180
/home/vagrant/test/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639
/home/vagrant/test/vendor/laravel/dusk/src/TestCase.php:181
/home/vagrant/test/vendor/laravel/dusk/src/TestCase.php:111
/home/vagrant/test/vendor/laravel/dusk/src/TestCase.php:85
/home/vagrant/test/tests/Browser/ExampleTest.php:21
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
I tried another solution from @abalozz (#10).
apt-get install xvfb
static::$chromeProcess = new Process('xvfb-run ./chromedriver-linux', realpath(__DIR__.'/../bin'), null, null, null);
Unfortunately, this solution seems to be buggy since the tests are sometimes very slow to run.
The following, (taken from here) worked for me:
# makes sure all your repos are up to date
sudo apt-get update
# chrome dependencies I think
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
# chromium is what I had success with on Codeship, so seemed a good option
sudo apt-get install chromium-browser
# XVFB for headless applications
sudo apt-get -y install xvfb gtk2-engines-pixbuf
# fonts for the browser
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
# support for screenshot capturing
sudo apt-get -y install imagemagick x11-apps
# Once all this has run through, you need to fire up xvfb on your homestead box. If you’re planning to # do this on a regular basis, you’ll want to get this setup on boot, but for the sake of testing things out:
Xvfb -ac :0 -screen 0 1280x1024x16 &
@SaeedPrez Have you solved the sisue from 1st post? I'm getting exactly same on docker - displayed content of vendor/bin/phpunit instead of executing it. Bare phpunit is working without any problem
@mnabialek Sorry, I have no solution. It was consuming a lot of my time so I decided to continue development in 5.3 and in a few weeks, maybe when 5.4 is a bit less rough around the edges try once again.
@SaeedPrez On my end https://github.com/laravel/dusk/pull/70 fixed this (but haven't run full Dusk test yet because of further connection problems that I need to solve in free time that were mentioned also in this thread)
@mnabialek awesome, great job! I'll close this issue since the original issue is fixed and merged.
is this fixing it for other people? I am still having issues on the current v1.0.5
@browner12
No, I get a timeout:
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}
Operation timed out after 30001 milliseconds with 0 bytes received
I am still having issues on the current v1.0.5, too.
Yah, for me the issue was the chromedriver
was not actually executable. updating the permissions allowed me to finally run Dusk.
see #81
@tzurbaev thanks for your comment. Saved my butt.
I get the same issue, ubuntu 16.04, laravel v5.4.15, dusk v1.0.10. Making excecutable the file, or more extreme giving chmod 777 on entire folder
Again, dowloading the crhomedriver latest version and replacing, don't work!
But mi error is Failed to connect to localhost port xxxx: Connection refused
But running $ vendor/laravel/dusk/bin/crhomedriver-linux on another terminal i get this work fin, but that isn't the idea.
@tzurbaev Thank you! Works like a charm now.
Lots of solutions floating around but this here is the official solution that will be included in the next vagrant homestead box. I've tried it and it works good
https://github.com/laravel/homestead/pull/528/files#diff-6c17dd8d21b8b745850a87b9d0de77c7
basically run
sudo apt-get update
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
sudo apt-get -y install chromium-browser
sudo apt-get -y install xvfb gtk2-engines-pixbuf
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
sudo apt-get -y install imagemagick x11-apps
and then update your aliases with the latest ones which includes this new function
function dusk() {
pids=$(pidof /usr/bin/Xvfb)
if [ ! -n "$pids" ]; then
Xvfb :0 -screen 0 1280x960x24 &
fi
php artisan dusk "$@"
}
You can also alternatively use this release candidate homestead box which has the fix in it https://atlas.hashicorp.com/Svpernova09/boxes/nothomestead
just to clarify I had the same problem - I did:
sudo apt-get update sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 sudo apt-get -y install chromium-browser sudo apt-get -y install xvfb gtk2-engines-pixbuf sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable sudo apt-get -y install imagemagick x11-apps
and then
chmod a+x ./vendor/laravel/dusk/bin/chromedriver-linux
and it seemed to have solved the problem
@tzurbaev solution worked for me except for screenshots. How do I get screenshots to work? I am running Ubuntu 16.04.2 LTS, Release: 16.04, Codename: xenial
Thank you, @tzurbaev ! (https://github.com/laravel/dusk/issues/50#issuecomment-275155974)
If anyone has problems with displaying remote fonts (for example from Google) this package might be useful - https://github.com/mnabialek/laravel-test-css
But what command should be done on the windows host ? Should I run "php artisan dusk" on windows OR on the homestead ?
@vesper8 : where do I add the alias ? Do I run "php artisan dusk" on the homestead ssh ? I'm using windows with homestead. "php artisan dusk" does not even open the windows chrome browser.
Dusk is by default "headless" now, which means it will not open a chrome browser in your OS.
@tzurbaev : I do exactly what you say, but the chrome browser does not even open. I'm using windows 10 and homestead. Xvfb is started on the homestead vm. On another homestead terminal, I run "php artisan homestead". No chrome browser pops up.
@browner12 : So it's impossible today to test with a real browser ? (e.g. seeing Dusk typing in a form and submit it)
nope, just comment out the --headless
line on the driver()
method in DuskTestCase
@browner12 : Ok, I see the browser popping up. But I have to run "php artisan dusk" on windows. I cannot run the command on the homestead vm ? Also, for "php artisan dusk" on windows, it works even without the "Xvfb" process.
i'm not sure how you're setup, but Homestead really only exists in the terminal, so it doesn't have a GUI to popup a Chrome window.
Run the command in your host OS if you want to popup the browser and see what's going on. If you want to go faster, just run it in Homestead with headless turned on. (you still get screenshots on errors I believe)
I only live in Linux world, though, so maybe Windows is different.
Ok but what is Xvfb for then ? Xvfb -ac :0 -screen 0 1280x1024x16 &
: This is running on the headless homestead VM ? How does the graphical chrome on host gets fired then ?
not really sure. might be legacy hack from before Chrome had a true "headless" mode.
seeing as Chrome "headless" was released in June of this year, this seems most likely.
OK... I thought "Xvfb" was used to send the chrome browser graphical output from the homestead VM to the physical Windows host.
OK! My answer here : https://developers.google.com/web/updates/2017/04/headless-chrome :
So I still need Xvfb?
No. Headless Chrome doesn't use a window so a display server like Xvfb is no longer needed. You can happily run your automated tests without it.
What is Xvfb? Xvfb is an in-memory display server for Unix-like systems that enables you to run graphical applications (like Chrome) without an attached physical display. Many people use Xvfb to run earlier versions of Chrome to do "headless" testing.
For me the easiest solution was to simply migrate to Laravel 5.5 where Dusk works natively on Win 10. ...now Dusk actually works, but incredibly slowly, so yet another problem, yay.
@browner12 Thanks. If i disabled --headless, it works as expected but if I turn on, I got error and error screenshots become blank. not sure why. looks like I will have to stick with --headless for the time being.
@webcrazy same issue here (Laravel 5.5, Win10, Homestead).
What makes me said, is that, it was working fine, at least for last couple of months.
For me, one issue is that, screenshots are blank/white.
The other one, I am facing, is getting failed tests, when I use assertPathIs()
after redirect.
It happens only, if I run chromedriver in headless mode. With windowed mode, all tests pass green.
What is intriguing, that my tests pass green in my gitlab CI.
So this issue is even more confusing...
BTW I've tried chromedriver 2.33 and 2.35, same result.
@tzurbaev I'm crazy with my Laravel 5.4 and your solution help me a lot. Especially this mention Also you may want to add your dev domain in guest's /etc/hosts file, I wrong when creating it on local instead of the virtual machine.
Thanks so much!
As it was mentioned by tzurbaev, adding your domain to /etc/hosts
was helpful.
Before that, I got just white screenshots, all tests were failing.
P. S. Ubuntu 18.04, Homestead, Virtualbox.
Hello,
So I just installed a new Laravel 5.4 project and thought I'd give Dusk a try..
Followed the installation steps in the documentation:
composer require laravel/dusk
AppServiceProvider.php
php artisan dusk:install
But when I run
php artisan dusk
I get the following output:It seems to be outputting the script instead of executing it.
I'm running latest Homestead on Windows 10 with
PHP 7.1.0-2+deb.sury.org~xenial+1 (cli) ( NTS )
PS. PHPUnit works as expected.