15
votes

I've been trying to integrate Laravel Dusk into my testing scheme for a week and can't get any test to actually deliver expected results. Here's the situation:

  • I'm running Laravel 55 on Homestead (per Project install) with php 7.1.*
  • I installed Dusk following the installation steps in the docs.

Out of the box the tests didn't work

However now when I run the tests I just can't get the expected output. This is what I am doing. I add an input field in my home page ('/') view file as such: <input id="dusk-test" value="1234">

I run this test which is a mod of the original example test and is the only test:

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;

class ExampleTest extends DuskTestCase
{
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser)
        {
            $browser->visit('/')->refresh()
                ->assertValue('#dusk-test', '1234')
            ;
        });
    }
}

...by running php artisan dusk and this is my output EVERY time

PHPUnit 6.4.3 by Sebastian Bergmann and contributors.

E                                                                   1 
/ 1 (100%)

Time: 1.07 seconds, Memory: 12.00MB

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\NoSuchElementException: no such element: 
Unable to locate element: {"method":"id","selector":"dusk-test"}
  (Session info: headless chrome=62.0.3202.62)
  (Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 4.4.0-92-generic x86_64)


  /home/vagrant/landing/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:102 /home/vagrant/landing/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:320
  /home/vagrant/landing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:535
  /home/vagrant/landing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:175
  /home/vagrant/landing/vendor/laravel/dusk/src/ElementResolver.php:281
  /home/vagrant/landing/vendor/laravel/dusk/src/ElementResolver.php:327
  /home/vagrant/landing/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:632
  /home/vagrant/landing/tests/Browser/ExampleTest.php:22
  /home/vagrant/landing/vendor/laravel/dusk/src/TestCase.php:92
  /home/vagrant/landing/tests/Browser/ExampleTest.php:24

  ERRORS!
  Tests: 1, Assertions: 0, Errors: 1.

To make this even more confusing, this is my output when I dump from the test. Here's how I dump

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;

class ExampleTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser)
        {
            $browser->visit('/')
                ->dump()
            ;
        });
    }
}

and my output after running php artisan dusk again is

PHPUnit 6.4.3 by Sebastian Bergmann and contributors.

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

Which is absolutely NOT my homepage. I also dumped the $url value from vendor/laravel/dusk/src/Browser.php and got my projects correct APP_URL.

I'm at a loss. Dusk is being sent the right location and the page definitely has the input and value. But, I can't get Dusk to give the expected output which would be that 12345 was retrieved from the element.

All help appreciated.

2
I have the exact same problem. I could even verify through chromedriver debugging, that chrome is directed to the correct endpoints and returns the correct data.Daniel Becker
Is it a HTTPS site? (BTW: You shouldn't need Selenium and Xvfb anymore.)Jonas Staudenmeir
It is not a https site. I'm currently not using Selenium, but am still starting up an Xvfb session. Is that not necessary anymore? As I mentioned before, everything from dusk instructing webdriver to chrome navigating and rendering pages is working. The content of the page is lost between webdriver and dusk.Daniel Becker
With headless Chrome you don't need it anymore. What do the logs say (console directory)? Does it work with a site like google.com?Jonas Staudenmeir
I'm having the exact same issue, someone has an update on this?Diego Ponciano

2 Answers

3
votes

maybe what i'm saying is wrong ... but Laravel dusk seems to need dusk instead of id: like dusk="dusk-test". also call it after : $browser->visit('/')>refresh() ->assertValue('@dusk-test', '1234') and it should be like the doc.

0
votes

On Github someone solved his problem by replacing https:// with http:// in the .env file.