Chukky Nze
Chukky Nze

Reputation: 720

Get Laravel Dusk to Run Properly on Ubuntu 16 wt Laravel 5.5

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:

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.

Upvotes: 15

Views: 1547

Answers (2)

Jonas Staudenmeir
Jonas Staudenmeir

Reputation: 25906

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

Upvotes: 0

JeremyGi
JeremyGi

Reputation: 86

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.

Upvotes: 3

Related Questions