Laravel Dusk returns empty html document when dumping browser, assertions therefore fail
Asked Answered
T

2

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.

Thicket answered 3/6, 2018 at 17:46 Comment(7)
Are you using the same Homestead instance for both projects?Absent
Are the sites using HTTPS?Absent
The sites are not using HTTPS and yes is the same Homestead installation, I'm dumping the URL on the dusk Browser.php:128 on the visit($url) method and the url is fine also.Thicket
Are all Composer packages updated?Absent
Yes I ran composer update recently since the upgrade to L5.6 was recent, I performed the upgrade from 5.5 thinking that would fix the issue actually so I could use Dusk version 3 but it did not fix itThicket
Is really weird it works on external sites like http://google.com and any other but it does not even work with full path to the local app which is like this appname.localThicket
Let us continue this discussion in chat.Absent
T
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 :)

Thicket answered 4/6, 2018 at 18:35 Comment(2)
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.Matrass
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! :)Thicket
B
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

Baron answered 23/2, 2022 at 7:0 Comment(1)
If you want to retain existing capabilities, see my answer here: https://mcmap.net/q/1915082/-dusk-test-fails-when-chrome-headless-enabledGallnut

© 2022 - 2024 — McMap. All rights reserved.