1
votes

I am testing my Laravel website using Dusk. The problem is that Dusk cant find a certain element. I have copied the element selector using Chrome developer tools and my code looks like this.

$browser->assertSeeIn('#content-container > div > div.table-responsive > table > tbody > tr > td:nth-child(1)', 'Test 1');

I have tried xpath as well. Fails also. I run my tests non-headless so I can see that the correct page is shown. There is something really wrong with Dusk that eventhough it's on the right page it cant find the lement. I have also tried:

$browser->assertSeeIn('table > tbody > tr > td:nth-child(1)', 'Test 1');

What am I missing???

2
Is this element included in the server 's HTML response or are you inserting it with JavaScript when the page is loaded?Jonas Staudenmeir
It is in the generated html. I don't add any html through Javascript. I used wget to get download the pure source code and the content-container is there. I notice for some reason that at the end of the test I see some json code of a user. The url is localhost:8080/_dusk/user. Apparently something done by duskMartijn Hiemstra

2 Answers

0
votes

Are you running your tests in headless mode by any chance? I had a similar problem (tests depending on selectors). Check your base class (DuskTestCase)'s driver method.

protected function driver()
{
    $options = (new ChromeOptions)->addArguments([
        '--disable-gpu',
        '--window-size=1024,768',
        // headless mode breaks every test that assert stuff about the url or use css/dusk selectors.
        // '--headless', 
        '--no-sandbox',
    ]);

    ...

}
0
votes

I found the answer. I was using assertAuthenticated() in my tests and that forces the browser to go to a json message of the logged in user. So if your just testing avoid assertAuthenticated() all together.