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
I added the steps found in this article on "Laravel Dusk on Homestead" and the gist found here in "setup-headless-selenium-xvfb.sh" this to my provisioning file. This removed a lot of the exceptions I was getting.
I also added all my existing environment vars to the php node of my
phpunit.dusk.xml
file exactly as they were done so in the already successfully running phpunit tests fromphpunit.xml
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.
console
directory)? Does it work with a site like google.com? – Jonas Staudenmeir