Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only first test finshes, chromedriver doesn't stop #341

Closed
rostockahoi opened this issue Aug 22, 2017 · 7 comments
Closed

Only first test finshes, chromedriver doesn't stop #341

rostockahoi opened this issue Aug 22, 2017 · 7 comments

Comments

@rostockahoi
Copy link

chromedriver-linux spawns when running artisan dusk but it doesn't stop after test execution, so every subsequent test will never finish because there cannot be multiple instances of chromedriver on the same port.

When I try to exec chromedriver manually it says:
[0,002][SEVERE]: bind() returned an error, errno=98: Die Adresse wird bereits verwendet which means "the address is already in use".

However if I kill chromedriver-linux manually it works again - once.

How can I fix the missing stop instruction?

@calebporzio
Copy link
Contributor

@rostockahoi - in your TestCase.php make sure your prepare method has the @beforeClass annotation like so:

/**
     * Prepare for Dusk test execution.
     *
     * @beforeClass
     * @return void
     */
    public static function prepare()
    {
        static::startChromeDriver();
    }

Let me know if that doesn't fix your issue.

@rostockahoi
Copy link
Author

Hi @calebporzio, thanks for the reply. The line exists. That's why the first test run works. But as soon as there's a process chromderiver-linux that is not terminated after the test has finished the next chromedriver-linux instance runs into an error.

Something regarding the chromedriver-linux termination seems to not work properly.

Btw: I didn't change Dusk's code.

@rostockahoi
Copy link
Author

I think I've come closer to the problem. It seems everything is working just fine in vendor/laravel/dusk/src/SupportsChrome.php. It starts and stops the chromedriver-linux process as expected. However, on my machine (Linux Mint 18.2) there are spawning 2 processes of which only one gets terminated after the test has finished. The other one remains running and is then blocking port 9515. The blocked port is preventing the next test to be finshed because chromedriver-linux then errors with the line seen in my first post above.

I did a screencast of the processes running a single test which works. Then again which doesn't work due to the blocking process. Then killing this process manually and running the test again successfully.

dusk 1

@ghost
Copy link

ghost commented Aug 30, 2017

I have the exact same problem. I need to keep killing the process to make dusk work again.

@glatzor
Copy link

glatzor commented Sep 3, 2017

ProcessBuilder doesn't use the exec command to run the chromedriver. You should switch to pure Process. See symfony/symfony#5759 for some background information.

I worte a small Trait to fix the issue in my project - you have to adapt the namespace and relative path to chromedriver:

<?php

namespace Tests\Helper\Traits;

use RuntimeException;
use Symfony\Component\Process\Process;

trait FixSupportsChrome
{
    /**
     * Build the process to run the Chromedriver.
     *
     * @throws \RuntimeException if the driver file path doesn't exist.
     *
     * @return \Symfony\Component\Process\Process
     */
    protected static function buildChromeProcess()
    {
        $driver = static::$chromeDriver
                ?: realpath(__DIR__.'/../../../vendor/laravel/dusk/bin/chromedriver-'.static::driverSuffix());

        if (realpath($driver) === false) {
            throw new RuntimeException("Invalid path to Chromedriver [{$driver}].");
        }

        return new Process([realpath($driver)], null, static::chromeEnvironment());
    }
}

@pratikid
Copy link

I had a similar issue in Windows. @rostockahoi
After executing command php artisan dusk pathToTestFile.php

capture

It opened the browser, executed the test case but didn't terminate the test case in the command prompt. So, I got to know from @rostockahoi post that my chromedriver-win.exe in vendor\laravel\dusk\bin\ wasn't getting terminated automatically.

Then I checked the path in My Computer->Properties->Advanced system settings->Environment Variables->Edit in User Variables and added C:\Windows\System32

Because there is a "TaskKill.exe" in this path.

capture

And after opening new command prompt
Finally it worked !!! .

capture

I think some similar way must be there in linux to solve the issue.

@rostockahoi
Copy link
Author

I updated to version ^2.0.0 and it is working for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants