Laravel Dusk hitting Laragon splash page/localhost?


  • | 4248 points

    Overview of the problem

    I am using Laragon for local development and I am trying to get started with Laravel Dusk, however, I cannot get it to run correctly. It appears to be hitting http://localhost instead of http://ticket.dev

    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 and .env.dusk.local: 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
    // i.e. the Laragon splash page
    

    So it appears to be hitting http://localhost and not my APP_URL, i.e. http://ticket.dev?

    Attempted solutions

    After googling the first few lines of the console output:

    1) Tests\Browser\ExampleTest::testBasicExample                                           
    Facebook\WebDriver\Exception\WebDriverException: JSON decoding of remote response failed.
    Error code: 4                                                                            
    

    https://www.google.co.uk/search?q=Facebook\WebDriver\Exception\WebDriverException%3A+JSON+decoding+of+remote+response+failed.+Error+code%3A+4&oq=Facebook\WebDriver\Exception\WebDriverException%3A+JSON+decoding+of+remote+response+failed.+Error+code%3A+4&aqs=chrome..69i57j69i58.911j0j1&sourceid=chrome&ie=UTF-8

    I find users of webdriver putting the errror down to proxy related issues. I am behind a proxy at my work place so I thought this might be the issue. However, I'm not 100% certain if it's a proxy issue, regardless, I have tried the following assuming it might be...

    I found this github wiki page https://github.com/facebook/php-webdriver/wiki/HowTo-Work-with-proxy 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
        );
    }
    

    But I still face the same issue.

    After creating an issue on the Laravel Dusk repo, I have also tried stopping Laragon, setting APP_UL=http://127.0.0.1:8000 in env.dusk.local and ran php artisan serve --env=dusk.local, but I still had the same issue of the Laragon splash page/localhost being hit in the test.

    Also, to ensure that I was hitting http://ticket.dev and not http://localhost I also added dd(Browser::$baseUrl) to the propagateScaffoldingToBrowser method in Laravel\Dusk\TestCase.php, but it returned http://ticket.dev.

    Could it be something to do with the windows host file? As http://ticket.dev is currently wired up to 127.0.0.1 in C:\Windows\System32\drivers\etc\hosts:

    127.0.0.1      ticket.dev           #laragon magic!
    

    Any ideas on what's going on?


  • administrators
    | 46947 points

    @haakym: I suggest you to you Ngork url (Menu > Ngork > share -> ticket.dev) for debugging. If the issue gone, it's definitely your proxy is the root cause.


  • | 34 points

    Got the same problem, exactly this "So it appears to be hitting http://localhost and not my APP_URL, i.e. http://ticket.dev?" or it seems.

    Edit: Ok, I fixed it. In your .env.dusk.local add your route with port. i.e. APP_URL=http://ticket.dev:8000 now run php artisan serve and php artisan dusk. Rudimentary but it works.


  • | 4248 points

    @leokhoa Thanks, I will give this a try!


  • | 4248 points

    This post is deleted!

  • | 4248 points

    @leokhoa I have tried Menu > Ngork > share -> ticket.dev

    With ngrok, I am getting the same issue with the Laragon splash page displaying instead of http://ticket.dev. I am guessing it is down to my proxy again. Any workarounds for this?

    Here's a screen shot of the result after running Ngrok

    0_1490000844912_ngrok proxy issue.png


  • administrators
    | 46947 points

    @haakym: Did you change your Dusk's env to Ngrok url also?


  • | 4248 points

    @leokhoa I didn't try that because it didn't appear ngrok was functioning correctly so why try Dusk. I just tried it anyway and dusk is still returning error and outputting the Laragon splash page.

    Anytime I run dusk, even when I remove the Laravel app from C:/laragon/www/ticket to some other folder and use php artisan serve, dusk always returns the Laragon splash page. Any idea why this happens?


  • administrators
    | 46947 points

    @haakym: You need to change the env of Dusk:
    APP_URL=http://ticket.dev:3000

    or:
    APP_URL=http://localhost:3000

    or:
    If you use Ngrok, change it to ngrok url:
    APP_URL=https://xxx.ngrok.io

    I believe it will work.


  • | 4248 points

    @leokhoa Still no change, sorry! See screenshot below...

    0_1490009541157_ngrok running dusk.png

    I don't think Ngrok is running properly to be honest, see the error "Could not detect Ngrok tunnel link".

    I think I am going to give up on this now. Thanks a lot for your help and assistance it's really appreciated.


  • administrators
    | 46947 points

    @haakym: You're welcome! Cheer


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.