6

I am trying to run laravel dusk with vuejs and I got an error

1) Tests\Browser\UserCreateTest::testAdminCanCreateAnotherUser Facebook\WebDriver\Exception\TimeOutException: Waited 5 seconds for selector [.users].

This is my test

$this->browse(function (Browser $browser) {
            $user = User::find(1);
            $browser
                ->loginAs($user)
                ->visit('/users');

            $browser->waitFor('.users');

In Vue template, I have div with class users.

Does anybody know what's wrong with it?

peterh
  • 11,875
  • 18
  • 85
  • 108

4 Answers4

1

The reason of that exception was that I was using 'npm run hot' instead of 'npm run prod'

0

To check if the element is on the page, you have to do this:

$browser->assertSee('Connection')

The connection is an example.

I also have difficulties to do dusk test. I can't press a button etc.

Minerva
  • 157
  • 1
  • 3
  • 10
0

You can try adding dusk attribute to your HTML element, for example:

<div class="users" dusk="user-list">
...
</div>

In your test, use the following:

$browser
    ->waitFor('@user-list');

The dusk="" attribute works as a custom selector to be used by Laravel Dusk to interact with the HTML elements on the page.

Reference: Testing Vue components with Laravel Dusk

-1

That's just how waitFor method works.

From the docs:

The waitFor method may be used to pause the execution of the test until the element matching the given CSS selector is displayed on the page. By default, this will pause the test for a maximum of five seconds before throwing an exception.

So, it waits for .users to appear for 5 seconds and then throws an exception.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279