longestdrive's avatar

Laravel Dusk - Fails test but how can I see what test sees?

Hi I'm getting started with Laravel Dusk (v2) with a Laravel 5.5 app

I'm starting small and want to test that a user can log in so have created this test:

public function test_user_can_browse_to_login_page_and_log_in()
    {
//        $this->logout();

        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                ->assertSee('You have arrived')
                ->click('@dashboard-link')
                ->assertSee('login')
                ->type('email', '[email protected]')
                ->type('password', 'password')
                ->click('@login-button') 
                ->assertPathIs('/dashboard')
                ->assertSee('seven days');

        });
    }

It all works fine until the last assertion - it doesn't see seven days which should be on the dashboard page.

So, to debug how can I see what the test is seeing? Is there a method to view the results?

Also, I don't see a browser opening (which I understand is correct) - I've followed another post and removed --headless from the DustTestCase.php but that then hangs completely. So I'm unable to watch the tests. (I have replaced the --headless option)

New to this so be kind!!

0 likes
5 replies
longestdrive's avatar

Hi @m-rk thanks for the link and suggestion

I've looked in the folder and can see a screenshot that shows exactly what I would expect to see and the expected text - so I would expect the test to pass :(

click's avatar

I've never used Dusk unfortunately but I've read some articles and I think you should use methods like waitForText() and pause() to give the server some time to respond.

See also the link mentioned earlier: https://laravel-news.com/testing-vue-components-with-laravel-dusk

Remember that you are dealing with javascript elements and asynchronous request so that you can use methods like waitForText('some text'), waitFor('.some-selector'), pause($ms = 500) to “pause” the execution until the backend response come back, and the DOM get’s updated by the Vue component.

longestdrive's avatar
longestdrive
OP
Best Answer
Level 4

Resolved - I hadn't appreciated the assertSee is case sensitive. All working now - thank you - on to my next problem!!!

giorg's avatar

Hi,

I am exactly in the same very situation, but I don't have any case sensitive wrong. Any further hint?

Thanks

Please or to participate in this conversation.