Thursday, March 16, 2017

Laravel Dusk not running behing proxy

Overview of the problem

I am trying to get started with Laravel Dusk, however, I cannot get it to run at all. Based on the feedback from when I run it in the console and some google searches and the fact I'd experienced the same issues with a similar package before Dusk was released I am guessing the issue is down to being behind a proxy at my work-place. I could of course be wrong about it being about the proxy but it's the only thing I have to go on for now. If I'm honest I don't even understand why it needs to know my proxy settings for running local tests locally?

Set up

  • Windows 7 64bit
  • Laravel 5.4.15
  • Dev env: Laragon
  • PHP 7

Dusk Installation

I did the following to install dusk:

  • composer require laravel/dusk
  • Set the following in .env: APP_URL=http://ticket.dev
  • Added the following to my AppServiceProvider register() method:

app/Providers/AppServiceProviders.php

use Laravel\Dusk\DuskServiceProvider;

//...

public function register()
{
    if ($this->app->environment('local', 'testing')) {
        $this->app->register(DuskServiceProvider::class);
    }
}

Running Dusk

When I run php artisan dusk, I get the following in my console:

1) Tests\Browser\ExampleTest::testBasicExample                                           
Facebook\WebDriver\Exception\WebDriverException: JSON decoding of remote response failed.
Error code: 4                                                                            
The response: '<!DOCTYPE html>                                                           
<html>                                                                                   
    <head>                                                                               
        <title>Laragon</title>                                                           
// the rest of the output is what http://localhost produces

Attempted solutions

I found this github wiki page and after browsing through the vendor folders related to Dusk I tried setting the proxy when the driver is set up in the driver() function in the file tests/DuskTestCase.php.

I've tried the following, but I get the same console output as mentioned before:

protected function driver()
{
    // same as DesiredCapabilities::chrome() except with proxy info
    $capabilities = new DesiredCapabilities([
        WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::CHROME,
        WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
        WebDriverCapabilityType::PROXY => [
            'proxyType' => 'manual',
            'httpProxy' => 'http://proxy:8080',
            'sslProxy' => 'http://proxy:8080',
        ],
    ]);

    return RemoteWebDriver::create(
        'http://localhost:9515',
        $capabilities,
    );

    // original code after installation
    // return RemoteWebDriver::create('http://localhost:9515', DesiredCapabilities::chrome());
}

and ...

protected function driver()
{
    $capabilities = new DesiredCapabilities([
        WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::CHROME,
        WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
        WebDriverCapabilityType::PROXY => [
            'proxyType' => 'manual',
            'httpProxy' => 'http://proxy:8080', // have also tried without specifying http://
            'sslProxy' => 'http://proxy:8080', // have also tried without specifying http://
        ],
    ]);

    return RemoteWebDriver::create(
        'http://localhost:9515',
        $capabilities,
        null,
        null,
        $http_proxy = 'http://proxy', // have also tried without specifying http://
        $http_proxy_port = '8080',
        null
    );
}

Any help on getting this working would be appreciated, thank you!



via haakym

Advertisement