laravel / dusk

Laravel Dusk provides simple end-to-end testing and browser automation.
https://laravel.com/docs/dusk
MIT License
1.88k stars 322 forks source link

Problem running dusk on Homestead #50

Closed SaeedPrez closed 7 years ago

SaeedPrez commented 7 years ago

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:

  1. Ran composer require laravel/dusk
  2. Updated AppServiceProvider.php
  3. Ran php artisan dusk:install

But when I run php artisan dusk I get the following output:

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
        # Cygwin paths start with /cygdrive/ which will break windows PHP,
        # so we need to translate the dir path to windows format. However
        # we could be using cygwin PHP which does not require this, so we
        # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
        if [[ $(which php) == /cygdrive/* ]]; then
                dir=$(cygpath -m "$dir");
        fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/phpunit" "$@"

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.

tyler36 commented 7 years ago

Me too on latest Homestead. Doesn't work on Windows 10 either.

spyric commented 7 years ago

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

SaeedPrez commented 7 years ago

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.

tzurbaev commented 7 years ago

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.

rustymulvaney commented 7 years ago

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

Unfortunately, this solution seems to be buggy since the tests are sometimes very slow to run.

amochohan commented 7 years ago

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 &
mnabialek commented 7 years ago

@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

SaeedPrez commented 7 years ago

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

mnabialek commented 7 years ago

@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)

SaeedPrez commented 7 years ago

@mnabialek awesome, great job! I'll close this issue since the original issue is fixed and merged.

browner12 commented 7 years ago

is this fixing it for other people? I am still having issues on the current v1.0.5

johanvanhelden commented 7 years ago

@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
fukuball commented 7 years ago

I am still having issues on the current v1.0.5, too.

murribu commented 7 years ago

This was helpful to me

browner12 commented 7 years ago

Yah, for me the issue was the chromedriver was not actually executable. updating the permissions allowed me to finally run Dusk.

see #81

fukuball commented 7 years ago

@murribu Thank! This really help. I can run duck in Homestead.

driesvints commented 7 years ago

@tzurbaev thanks for your comment. Saved my butt.

nonDeath commented 7 years ago

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.

lgyaxx commented 7 years ago

@tzurbaev Thank you! Works like a charm now.

vesper8 commented 7 years ago

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

shez1983 commented 7 years ago

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

digitlimit commented 7 years ago

@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

ryancwalsh commented 7 years ago

Thank you, @tzurbaev ! (https://github.com/laravel/dusk/issues/50#issuecomment-275155974)

mnabialek commented 7 years ago

If anyone has problems with displaying remote fonts (for example from Google) this package might be useful - https://github.com/mnabialek/laravel-test-css

trogne commented 6 years ago

But what command should be done on the windows host ? Should I run "php artisan dusk" on windows OR on the homestead ?

trogne commented 6 years ago

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

browner12 commented 6 years ago

Dusk is by default "headless" now, which means it will not open a chrome browser in your OS.

trogne commented 6 years ago

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

trogne commented 6 years ago

@browner12 : So it's impossible today to test with a real browser ? (e.g. seeing Dusk typing in a form and submit it)

browner12 commented 6 years ago

nope, just comment out the --headless line on the driver() method in DuskTestCase

trogne commented 6 years ago

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

browner12 commented 6 years ago

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.

trogne commented 6 years ago

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 ?

browner12 commented 6 years ago

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.

trogne commented 6 years ago

OK... I thought "Xvfb" was used to send the chrome browser graphical output from the homestead VM to the physical Windows host.

trogne commented 6 years ago

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.

Ravaelles commented 6 years ago

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.

sithuaung commented 6 years ago

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

chilio commented 6 years ago

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

henryonsoftware commented 6 years ago

@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!

Tarasovych commented 5 years ago

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.