Giter Club home page Giter Club logo

Comments (13)

ockle avatar ockle commented on May 13, 2024 6

@mnabialek I was running into similar problems and after playing around with it for ages, I got it to work, although it requires a change to SupportsChrome.php. Change:

->setPrefix(realpath(__DIR__.'/../bin/chromedriver-'.static::driverSuffix()))

to:

->setPrefix('xvfb-run')
->setArguments([realpath(__DIR__.'/../bin/chromedriver-'.static::driverSuffix())])

To anyone else reading this, note the prerequisite parts:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg –i google-chrome-stable_current_amd64.deb
apt-get install -y xvfb

from dusk.

vesper8 avatar vesper8 commented on May 13, 2024 3

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 canditate homestead box which has the fix in it
https://atlas.hashicorp.com/Svpernova09/boxes/nothomestead

from dusk.

mattkoch614 avatar mattkoch614 commented on May 13, 2024 1

@ockle This was the only thing that worked for me, and I've been trying to get Dusk running all morning in Laravel Homestead. I should mention that this was in addition to following install instructions here:

https://christopher.su/2015/selenium-chromedriver-ubuntu/

and then finally running:

chmod 755 vendor/laravel/dusk/bin

from dusk.

SebastianS90 avatar SebastianS90 commented on May 13, 2024 1

@alejandrorosas Yes, there has been some change to symfony process.
Remove the two lines ->add('exec') and it should work again.

from dusk.

mnabialek avatar mnabialek commented on May 13, 2024

Just to update, I've run Dusk tests for the same project without any problem on host machine (Windows). But when running tests on Windows, browser windows opens, so maybe that's the problem why tests on VM are failing?

from dusk.

harryatoms avatar harryatoms commented on May 13, 2024

Hi everyone, I'm having the same issue in a Docker container based off of php:7-apache which is debian jessie.

I tried installing chrome/xvfb and modifying the SupportsChrome trait in vendor/laravel/dusk/src without success.

I'm still stuck on Operation timed out after 30001 milliseconds with 0 bytes received.

Pretty frustrating lol, many people run tests as a part of CI inside a built docker image and this is a popular image to extend from.

There has been a lot of reports of this problem on here and laracasts but still no solid fix or documentation updates for Dusk.

Thanks!

from dusk.

SebastianS90 avatar SebastianS90 commented on May 13, 2024

@harryatoms I had some trouble because GitLab CI doesn't assign a tty to the docker container. But that could be solved by starting dusk using script -q -e -c 'php artisan dusk'

And for the xvfb part I just use my own DuskCommand class which overrrides the original one as follows:

    protected $xDisplay = 17;
    protected $xDisplayResolution = '1280x720x24';

    protected function withDuskEnvironment($callback)
    {
        return parent::withDuskEnvironment(function () use ($callback) {
            return $this->withChromeDriver($callback);
        });
    }

    protected function withChromeDriver($callback)
    {
        // Start a headless X server
        $xvfb = (new ProcessBuilder())
            ->setTimeout(null)
            // ->add('exec') remove this line for current Symfony\Component\Process version 
            ->add('/usr/bin/Xvfb')
            ->add(':' . $this->xDisplay)
            ->add('-screen')->add('0')->add($this->xDisplayResolution)
            ->getProcess();
        $xvfb->start();

        // Start the chromedriver
        $chrome = (new ProcessBuilder())
            ->setTimeout(null)
            // ->add('exec') remove this line for current Symfony\Component\Process version 
            ->add(base_path('vendor/laravel/dusk/bin/chromedriver-linux'))
            ->getProcess()
            ->setEnv(['DISPLAY' => ':' . $this->xDisplay]);
        $chrome->start();

        // Terminate both processes once we are done
        return tap($callback(), function () use ($chrome, $xvfb) {
            $chrome->stop();
            $xvfb->stop();
        });
    }

and then comment out the contents of the prepare function in DuskTestCase

Edit [2017-06-05]: as noted below the code stopped working after a symfony update. Remove the two ->add('exec') lines and it should work again.

from dusk.

harryatoms avatar harryatoms commented on May 13, 2024

@SebastianS90 very handy, thanks! I'll give this a try. I'm unable to run dusk tests even after starting Xvfb, so I'm still trying to get that to work.

For now, I switched to phantomjs and it's working, but that was more for a POC. I'll still be trying to use chrome through the methods mentioned above until I can put together a good configuration.

from dusk.

mydnic avatar mydnic commented on May 13, 2024

@ockle solution worked for me. I'm using Homestead on a windows machine.
This fix should be implemented asap in the package.

from dusk.

alejandrorosas avatar alejandrorosas commented on May 13, 2024

@SebastianS90 it seems that your code doesn't works with the latest symfony process :(

from dusk.

stephangroen avatar stephangroen commented on May 13, 2024

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

Create a customDuskCommand
Which extends the original, with this handle method:

    public function handle()
    {
        $xvfb = (new ProcessBuilder())
            ->setTimeout(null)
            ->setPrefix('/usr/bin/Xvfb')
            ->setArguments(['-ac',  ':0', '-screen', '0', '1280x1024x16'])
            ->getProcess();

        $xvfb->start();

        try {
            parent::handle();
        } finally {
            $xvfb->stop();
        }

        return;
    }

from dusk.

JackWH avatar JackWH commented on May 13, 2024

@vesper8 Thanks for your comment about running dusk directly within Homestead. This gets Dusk to work headlessly for me, but, the error screenshots being saved are 800x600px in size, despite having set the Xvfb arguments to 1280x960x24.

Is this expected behaviour, or am I doing something wrong? Thanks in advance.

from dusk.

JackWH avatar JackWH commented on May 13, 2024

@vesper8 Sorry, ignore that last message - figured it out - just needed to re-provision Homestead again for changes to the aliases file to take effect. Thanks!

from dusk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.