6

I have a project which came from laravel 5.1, we have upgraded it accordingly up until 5.6, everything on the application works perfectly fine. When I install dusk and run this on ExampleTest.php:

$this->browse(function (Browser $browser) {
    $browser->visit('/');
    $browser->dump();
});

I am getting this empty html document which I don't know where it comes from:

"<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>"

I am using laravel homestead and I know dusk works fine because if I install a fresh laravel application (laravel.local) it works perfectly fine and ExampleTest assertions return green.

I have searched everywhere for possible causes but I have run out of resources or even clues, please help.

Diego Ponciano
  • 453
  • 5
  • 12

2 Answers2

2

Ok this was a simple fix, homestead was not able to reach the application FROM WITHIN, I debugged this using a simple curl get command to my app and it could not reach it, so I simply added the application to my hosts (/etc/hosts) file using the homestead ip address like this:

192.168.10.10 appname.local

I ran again the curl request and all good, after this all tests ran nicely :)

brnd0
  • 338
  • 6
  • 15
Diego Ponciano
  • 453
  • 5
  • 12
  • 1
    Brilliant! I encountered this problem after switching from Vagrant to Hyper-V and simply added `127.0.0.1 app.site` to `/etc/hosts` on the VM, after finding your post. While using the machine's actual IP address works, as shown in your Answer, it seems simpler just to use the localhost address, which will never change when the networking configuration changes. I'm curious where from that unhelpful and inaccurate HTML string originates. Does that come from Chrome Driver? Dusk? I would expect something more along the lines of `No address associated with hostname`... it feels like a bug. – Ben Johnson Dec 17 '18 at 16:27
  • You are right! localhost should do a better job. I remember that when I debugged it all made sense, when reached from outside, vagrant resolves and maps to the correct folder and virtual host. But vagrant is not designed to reach the app from within or at least seems you have to configure that. I will research on vagrant docs about this... Glad the post helped! :) – Diego Ponciano Dec 17 '18 at 23:09
1

I had the same problem and the previous solution was not working for me.

The error was probably due to invalid SSL certificates.
I solved changing in the Dusk .env file the application address from https:// to http://

For example:

APP_URL=http://dusk.myapp.com
BASE_URL=http://dusk.myapp.com

As an alternative, if you are running Chrome 65+ and Chrome Driver 2.35+ you can add the following in DuskTestCase:

->setCapability('acceptInsecureCerts', true)

I found the answer and full discussion about this in an issue on the laravel/dusk GitHub page:
https://github.com/laravel/dusk/issues/480

Davide Casiraghi
  • 15,591
  • 9
  • 34
  • 56
  • If you want to retain existing capabilities, see my answer here: https://stackoverflow.com/a/72662659/2047725 – w5m Jun 17 '22 at 17:04