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

Firefox support #612

Closed
fwang-laralabs opened this issue Feb 21, 2019 · 6 comments
Closed

Firefox support #612

fwang-laralabs opened this issue Feb 21, 2019 · 6 comments

Comments

@fwang-laralabs
Copy link

Please also support firefox driver.
I have encountered a problem that mouseover does not work.

#353

@fwang-laralabs
Copy link
Author

https://medium.com/@melihovv/how-to-use-laravel-dusk-with-selenium-and-firefox-9c12cdf92c94

This document will be used as a reference.
If you have a firefox driver, you're more comfortable.

@driesvints driesvints changed the title Please also support firefox driver. Please also support firefox driver Apr 14, 2020
@derekmd
Copy link
Contributor

derekmd commented May 15, 2020

Laravel Dusk supporting Geckodriver

I created a branch that allows Laravel Dusk to support geckodriver (formerly Firefox Driver) without additional configuration: 6.x...derekmd:firefox-support

php artisan dusk:install --firefox

will copy a tests/DuskTestCase.php into your application that will open Firefox via Geckodriver running at http://localhost:4444/. No Selenium installation is required.

Geckodriver doesn't support GET_LOG

Firefox doesn't implement the WebDriver API to retrieve console.log output for JavaScript debugging. $driver->manage()->getLog('browser') can't return output so Dusk wouldn't be able to a store an individual tests/Browser/console/*.log file for each browser run.

However it is possible to awkwardly get the console output via the geckodriver server's stdout. This .log file will cover all browsers run during a single test.

RemoteWebDriver::create(
    'http://localhost:4444',
    tap(DesiredCapabilities::firefox(), function ($caps) {
        $caps->getCapability(FirefoxDriver::PROFILE)
            ->setPreference('devtools.console.stdout.content', true);
    })
);

A ProvidersBrowser::afterClass() hook can then store the stdout string returned by SupportsFirefox::$firefoxProcess->getOutput(). This requires a significant refactor of Browser::$storeConsoleLogAt that would likely be a breaking change.

Additional installation instructions on Windows

As seen in https://github.com/mozilla/geckodriver/releases notes, there are known issues with automating installations. Windows also needs "Microsoft Visual Studio redistributable runtime" to be manually installed separately. The new php artisan dusk:firefox-driver command has these instructions added.

Geckodriver on Windows requires installing Microsoft Visual Studio redistributable runtime.
Download binaries at https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

Submitting Pull Request

Until the JavaScript console log issue can be cleared up, I don't think this will make it into Dusk.

@driesvints
Copy link
Member

@derekmd thank you so much for looking into this. First of all I want to say that I think it's best that we stop shipping the executables with dusk as they tend to increase the package size by quite a lot. I'm actually thinking of removing the chrome executables in a next major version as well which will require people to always install them with the driver commands.

As for the rest of the PR, I agree that we might best wait until the JavaScript console log issue is resolved. I'll keep this open for the time being but for now it's best that we wait.

@derekmd
Copy link
Contributor

derekmd commented May 21, 2020

wait until the JavaScript console log issue is resolved

@driesvints: Investigating further, according to Mozilla developer comments in 2018 and 2019, it's a "hard no" on Firefox supporting $driver->manage()->getLog('browser') that Laravel Dusk calls when Chrome or PhantomJS browsers are used. This is considered a Selenium spec, outside the scope of the W3C Webdriver API.

References:

With no active W3C spec discussions or Firefox dev work being done to add commands.GetLog to the WebDriver API, the only mechanism Geckodriver consumers are left with is stdout logging.

Possible Laravel Dusk paths

To support Firefox, I see these three options with escalating implementation complexity:

  1. Happy path: ignore Firefox browsers ever supporting JavaScript console logging. https://laravel.com/docs/7.x/dusk doesn't even mention this feature so it seems a nice-to-have.
  2. Add a SupportsFirefox trait method that exposes the SupportsFirefox::$firefoxProcess->getOutput() returned string for userland debuggers to call dump($this->getFirefoxOutput()) after a $this->browse() Closure.
  3. As mentioned in my previous comment, make Laravel Dusk support two log-fetching paths and both write .log files to the filesystem. I tried this and disliked the final code so much I wiped the commits. Laravel\Dusk\TestCase sibling traits need to share state through static methods and it's very ugly.

@driesvints
Copy link
Member

Thanks for all the research @derekmd. We've decided to not support Firefox for the time being. I'll pin this issue for anyone who wants to know the reasoning.

@driesvints driesvints pinned this issue May 22, 2020
@driesvints driesvints changed the title Please also support firefox driver Firefox support May 22, 2020
@derekmd
Copy link
Contributor

derekmd commented Jun 1, 2020

I've published that "laravel/dusk" dev branch as a standalone package: https://github.com/derekmd/laravel-dusk-firefox

Run these commands to start using Firefox instead of Google Chrome:

composer require --dev derekmd/laravel-dusk-firefox
php artisan dusk:install-firefox
php artisan dusk

It's also possible to run tests in either browser. See the package's Github docs for more details.

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

No branches or pull requests

3 participants