Laravel Dusk hitting Laragon splash page/localhost?
-
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
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 filetests/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 ranphp 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 thepropagateScaffoldingToBrowser
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?
-
@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.
-
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.
-
@leokhoa Thanks, I will give this a try!
-
This post is deleted!
-
@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
-
@haakym: Did you change your Dusk's env to Ngrok url also?
-
@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 usephp artisan serve
, dusk always returns the Laragon splash page. Any idea why this happens?
-
@haakym: You need to change the env of Dusk:
APP_URL=http://ticket.dev:3000or:
APP_URL=http://localhost:3000or:
If you use Ngrok, change it to ngrok url:
APP_URL=https://xxx.ngrok.ioI believe it will work.
-
@leokhoa Still no change, sorry! See screenshot below...
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.
-
@haakym: You're welcome! Cheer
-
This thread is old though, but I ran into same problem recently. The solution is to change the value of APP_URL in the .env file from http://localhost to your projects homepage e.g. APP_URL = blog.dev.
-
Cool, thanks @dreemer6
. Your information will definitely help others!