Laravel Dusk, errors loading google-chrome
I am trying to run tests using Laravel Dusk on a Windows 10 subsystem, WSL2 running Ubuntu. I've followed the installation guides, and I'm stuck at the point after the google-chrome browser is loaded and renders the site:
This is my DuskTestCase.php driver method:
protected function driver()
{
$options = (new ChromeOptions)->addArguments(collect([
])->unless($this->hasHeadlessDisabled(), function ($items) {
return $items->merge([
'--disable-gpu',
// '--headless',
'--window-size=1920,1080'
]);
})->all());
return RemoteWebDriver::create(
$_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
Before running the test, I run chromedriver for linux
vendor/laravel/dusk/bin/chromedriver-linux
returns:
Starting ChromeDriver 99.0.4844.51 (d537ec02474b5afe23684e7963d538896c63ac77-refs/branch-heads/4844#{#875}) on port 9515
Next I run any test say AuthTest
php artisan dusk tests/Browser/AuthTest.php
The test cannot render the site: http://localhost:9515
Error in browser:
{"value":{"error":"unknown command","message":"unknown command: unknown command: login","stacktrace":"#0 0x55bf14b857d3 \u003Cunknown>\n#1 0x55bf148e1688 \u003Cunknown>\n#2 0x55bf14932e11 \u003Cunknown>\n#3 0x55bf14932b77 \u003Cunknown>\n#4 0x55bf148b81d4 \u003Cunknown>\n#5 0x55bf148b9020 \u003Cunknown>\n#6 0x55bf14bb649d \u003Cunknown>\n#7 0x55bf14bcf60c \u003Cunknown>\n#8 0x55bf14bb8205 \u003Cunknown>\n#9 0x55bf14bcfee5 \u003Cunknown>\n#10 0x55bf14bac070 \u003Cunknown>\n#11 0x55bf148b7d49 \u003Cunknown>\n#12 0x7f7d460390b3 \u003Cunknown>\n"}}
If I load google-chrome manually and try to go to the same address (http://127.0.0.1:9515/), the same error appears.
However if I close everything and run:
php artisan serve --port 9515
then
google-chrome
I am able to manually interact with the site, yet Laravel Dusk cannot load the browser.
The following error is thrown by Laravel Dusk
```bash
TypeError: Argument 1 passed to Facebook\WebDriver\Remote\DesiredCapabilities::__construct() must be of the type array, null given, called in /home/simon/sites/acquisitionboardgame_vue/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php o
n line 648
Can anyone point me in the right direction ?
Related
Running php artisan dusk get the error:
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: net::ERR_CONNECTION_REFUSED
(Session info: headless chrome=85.0.4183.83)
Versions:
OS: Windows 10 v1903 build 18362.1016
Chrome: 85.0.4183.83
Laravel: v6.18.37
Dusk: v5.11.0
Phpunit: v8.5.8
Tried:
Disable firewall
Set test website to use localhost (was myapp.local)
Can access all pages using Chrome browser
Check that vendor/laravel/dusk/bin/chromedriver-win.exe is executable (-rwxr-xr-x)
php artisan route:clear
php artisan cache:clear
php artisan config:clear
composer dump-autoload
google "Facebook\WebDriver\Exception\UnknownErrorException: unknown error: net::ERR_CONNECTION_REFUSED"
The server localhost:9515 appears to be running while tests executing as I get the following response in Chrome when trying it:
{
value: {
error: "unknown command",
message: "unknown command: unknown command: ",
stacktrace: "Backtrace: Ordinal0 [0x0037D383+3134339] Ordinal0 [0x0026A171+2007409] Ordinal0 [0x0010AEE8+569064] Ordinal0 [0x000AD12C+184620] Ordinal0 [0x000ACF0A+184074] Ordinal0 [0x00081FD7+8151] Ordinal0 [0x00082496+9366] Ordinal0 [0x00082B40+11072] Ordinal0 [0x00280CD9+2100441] GetHandleVerifier [0x004EB75A+1396954] GetHandleVerifier [0x004EB3D9+1396057] GetHandleVerifier [0x004F7126+1444518] GetHandleVerifier [0x004EBCE8+1398376] Ordinal0 [0x00277F51+2064209] Ordinal0 [0x00081D35+7477] Ordinal0 [0x00081991+6545] GetHandleVerifier [0x006BF31C+3312796] BaseThreadInitThunk [0x76986359+25] RtlGetAppContainerNamedObjectPath [0x771D7C24+228] RtlGetAppContainerNamedObjectPath [0x771D7BF4+180] (No symbol) [0x00000000] ",
}
}
DuskTestCase driver:
/**
* Create the RemoteWebDriver instance.
*
* #return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
Does anyone have any clues on what else to try? Or does anyone else know a resolution?
I faced the same issue and for me what worked was setting the APP_URL parameter in the .env file as:
APP_URL=http://127.0.0.1:8000
As that was the same port on which my php artisan serve would also serve the website i.e.
Laravel development server started: http://127.0.0.1:8000
I'm putting this out there for others that might face the same thing as me.
It turns out Laravel Dusk expects us to run php artisan serve before running php artisan dusk! The ERR_CONNECTION_REFUSED error refers to not being able to connect to the http://localhost:8000 URL of the application itself, because it's not running.
This does make sense, but I simply didn't know and the documentation was not clear on that (I had to deduce it). The ChromeDriver, however, is started automatically by Dusk at execution time.
The only thing that helped me with Laravel 9 is to set APP_URL=http://laravel.test in the .env.dusk.local file.
Fixed it by following these steps:
Remove vendor folder and remove composer.lock
php composer.phar install
Check your current Chrome Version - you can check it by going to https://www.whatismybrowser.com/detect/what-version-of-chrome-do-i-have
Download the WebDriver for Chrome that matches your current Chrome Version from http://chromedriver.chromium.org/downloads
Manually remove old chromedriver-win.exe version from vendor\laravel\dusk\bin and put the one you downloaded there. Note that you will have to rename the file.
After doing step 2 above the error message changed which prompted the remaining steps.
To fix this error you will need to update .env file APP_URL parameter to your local server url as below
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:XZoWMB3aWom/V3iZy870VSQjMsBdGCHYdWbRuNb6aY0=
APP_DEBUG=true
APP_URL=http://127.0.0.1:8000 #(This can be url to your local environment)
For me the error disappeared after setting .env APP_ENV=development and i keep .env.dusk.development also same.
I was trying to run the dusk after installing the new Laravel 8.77 and faced the following error and found the solution by creating new .env.dusk.local file. You have to create .env.dusk.{environment} as per your current environment.
In your newly created env file, you need to define proper URL for ex. http://testing-laravel.local by creating virtual host.
There was 1 error:
1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: net::ERR_CONNECTION_REFUSED
(Session info: headless chrome=96.0.4664.110)
I have created a number of selenium IDE files that I converted to phpunit format in Firefox IDE 2.9.1.1 (on a Windows box), using Options -> Format converter. Those converted files define a class "Example" that is derived from class PHPUnit_Extensions_SeleniumTestCase. I now know that this class needs to be changed to PHPUnit_Extensions_Selenium2TestCase. The problem is, I cannot get this to run with recent versions of phpunit.
I am running these tests on a Fedora 24 VM which is using php 5.6.30, java 1.8.0_121-b14, and firefox 51.0.1-2. I have tried to get these to run using selenium standalone server 3.0.1 (and now 3.1.0), and phpunit 5.7.13. I have the latest php facebook WebDriver installed. The error I keep getting is that the above mentioned class is not found. I did a grep on that class and this is what I found:
[root#localhost bin]# grep -r "PHPUnit_Extensions_Selenium2TestCase" .
Binary file ./phpunit/phpunit-4.6.7.phar matches
Binary file ./phpunit/phpunit-4.7.6.phar matches
So, it appears that this class does not exist in phpunit 5.7 and above (which are in that directory), nor does it exist in html-runner.phar, which is in the same directory. The seleniumhq.org site says to use html runner if you convert from IDE, but I can find no examples of how to use the html-runner.phar file (and no documentation).
Can someone please tell me what I should change the class name to, to get this test to work?
UPDATE:
I now know that if I want to use phpunit and selenium server to drive a firefox browser, I have to get selenium talking to geckodriver. I have installed:
geckodriver 0.14.0 at /usr/local/bin/geckodriver
selenium server 3.0.1 at /usr/local/bin/selenium
phpunit-5.7.13.phar installed at /usr/local/bin/phpunit
I used composer to add webdrivers (facebook 1.3.0 :
[root#localhost composer]# cat composer.json
{
"require": {
"facebook/webdriver": "^1.3",
"phpunit/phpunit": ">=3.7",
"phpunit/phpunit-selenium": ">=1.2"
}
}
php composer.phar install
They were added to the PATH:
[bjt#localhost projects]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/bin/selenium:/usr/local/bin/phpunit:/usr/local/bin/composer:/usr/local/bin/geckodriver
I have a small test file:
?php
require_once('/usr/local/bin/composer/vendor/autoload.php');
class test extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser("*firefox");
$this->setBrowserUrl("https://fakeurl.com/");
}
public function testMyTestCase()
{
$this->open("/");
}
}
Starting the selenium server:
java -jar /usr/local/bin/selenium/selenium-standalone-3.0.1.jar
When I run the test:
/usr/local/bin/phpunit/phpunit-5.7.13.phar --verbose test.php
Yields this error:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: The best matching driver provider Firefox/Marionette driver can't create a new driver instance for Capabilities [{browserName=*firefox}]
So, it appears that geckodriver is not talking to selenium server. If I try to force the issue by changing the execution of the server:
java -Dwebdriver.gecko.driver="/usr/local/bin/geckodriver/geckodriver" -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar
or
sudo java -Dwebdriver.gecko.driver="/usr/local/bin/geckodriver/geckodriver" -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar
It makes no difference. I'm hoping someone can point out what I am missing. I'm at a dead end.
I am currently working through the same process of getting this to work and would like to point out a few things:
htmlrunner is meant to run the test cases saved directly from the Selenium IDE in the default format, which is html.
Make sure you can run firefox from the terminal running the selenium server.
You added two different selenium php bindings. The facebook one and the phpunit-selenium. I currently have it working with only the facebook binding and phpunit extending the class PHPUnit_Framework_TestCase. I would recommend using the example provided within github for facebook/webdriver without phpunit to verify that your selenium config is working, then add phpunit.
I am trying to setup functional tests on my Centos Server using Selenium Web Server and Phpunit.
When I run the tests, I get an error in the command line :
PHPUnit_Extensions_Selenium2TestCase_WebDriverException:
Unable to connect to host vmdev-pando-56 on port 7055 after 45000 ms.
Firefox console output: Error: no display specified
I've been doing research for more than three days and I couldn't find a solution. I read many posts, including SOverflow. As per my understanding, everything is properly set up, and yet I am experiencing the same problem as many other people, and the solutions that work for them seem to be not working for me.
This is my setup:
OS: Centos 6.5 x86 in command line (no GUI)
PHP: 5.6
Phpunit: 3.7, although I also tried with 5.3
Selenium standalone web server: 2.53, downloaded from here, although I also tried with 2.9
Xvfb system: xorg-x11-server-Xvfb
Firefox: 38.0.1, although I also tried with 38.7
I also set the DISPLAY to :99 in my bash profile:
This is what I do to set up the environment:
First, I launch the Xvfb system: /usr/bin/Xvfb :99 -ac -screen 0 1280x1024x24 &
Then I launch the Selenium server: /usr/bin/java -jar /usr/lib/selenium/selenium-server-standalone-2.53.0.jar &
I launch Firefox: firefox & (although I know this is not necessary, but just in case)
All of the three processes are running in background.
At this point, I know that Firefox is operative, as well as the X buffer. I can run the command firefox http://www.stackoverflow.com & and then take an snapshot of the buffer by executing import -window root /tmp/buffer_snapshot.png, which happens to be something like this:
I of course received a warning on the terminal: Xlib: extension "RANDR" missing on display ":99", but I read countless of times that this is not a problem.
Anyway, the problem begins just now.
I've written a rather simple functional test (please notice that other tests I've written other than functional, they work just fine, so the environment in that respect seem to be properly configured):
<?php
namespace My\APP\BUNDLE\Tests\Functional\MyTest;
use PHPUnit_Extensions_Selenium2TestCase;
class HelloWorldTest extends PHPUnit_Extensions_Selenium2TestCase {
protected function setUp() {
$this->setBrowser('firefox');
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowserUrl('http://www.stackoverflow.com');
}
public function testTitle() {
$this->url('/');
$this->assertEquals("1", "1");
}
}
And when I run the test by issuing phpunit HelloWorldTest.php, I get the following error:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException:
Unable to connect to host vmdev-pando-56 on port 7055
after 45000 ms. Firefox console output:
Error: no display specified
Checking the log file generated by selenium, I found the following (interesting) lines:
21:55:46.135 INFO - Creating a new session for Capabilities [{browserName=firefox}]
[...]
java.util.concurrent.ExecutionException:
org.openqa.selenium.WebDriverException:
java.lang.reflect.InvocationTargetException
Build info: version: '2.53.0',
revision: '35ae25b',
time: '2016-03-15 17:00:58'
System info: host: 'vmdev-pando-56',
ip: '127.0.0.1',
os.name: 'Linux',
os.arch: 'i386',
os.version: '2.6.32-431.el6.i686',
java.version: '1.7.0_99'
Driver info: driver.version: unknown
[...]
(The file contains the complete stack trace dump, and the original message of no display specified)
No errors in the Xvfb log file.
At this point I have no clue of what I am doing wrong.
Can anyone help?
Thanks a lot
A reason for the Unable to connect error is that the version of Selenium Server does not know how to work with the version of Firefox you have installed. Selenium standalone web server 2.53 is the latest and greatest. selenium-firefox-driver is also 2.53. Firefox version 38 is old. I am running firefox 45.0.1 with selenium 2.53.
I start grid service - java -jar selenium-server-standalone-2.42.1.jar -role hub
I start phantomjs - phantomjs --webdriver= --webdriver-selenium-grid-hub={hubip/port}
I run phpunit and the output is:
RuntimeException: Invalid response while accessing the Selenium Server at 'http://{hubip/port}/selenium-server/driver/'
org.openqa.grid.common.exception.GridException: Error forwarding the new session The server returned an error : Unknown Command -
{"headers":
{"Accept":"*/*","Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"67","Content-Type":"application/x-www-form-urlencoded; charset=utf-8","Host":"","User-Agent":"Apache-HttpClient/4.3.2 (java 1.5)"},
"httpVersion":"1.1","method":"POST","post":"cmd=getNewBrowserSession&1=phantomjs&2=;","url":"/","urlParsed":
{"anchor":"","query":"","file":"","directory":"/","path":"/","relative":"/","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/","queryKey":{},"chunks":[""]}
}
I can get firefox to work correctly, so I would assume that the top two commands would work just fine.
Also phantomjs version is 1.9.7
I'm using Selenium server (2.39.0) on centOs server 6.5 (redhat)
developing tests in PHP, using phpUnit (i installed phpunit by pear as well)
but everytime i get this error:
Invalid response while accessing the Selenium Server at 'http://localhost:4444/selenium-server/driver/':
Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException:
Error while launching browser
Caused by
RuntimeException:
Invalid response while accessing the Selenium Server at 'http://localhost:4444/selenium-server/driver/':
Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException:
Error while launching browser
this is the test that i'm trying to execute:
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
function setUp()
{
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://www.google.com/");
}
function testMyTestCase()
{
$this->open("/");
$this->type("q", "selenium rc");
$this->click("btnG");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isTextPresent("Results * for selenium rc"));
}
}
?>
i'm trying also to run the script using :
phpunit --configuration conf.xml example.php
where in conf.xml i've got:
<browser name="Firefox" browser="*firefox" host="IPHOST" port="4444" timeout="30000" />
but i receive the same error
and the door 4444 is free:
netstat -anp | grep 4444
gives:
tcp 0 0 :::4444 :::* LISTEN
what am i doing wrong?
EDIT:
#sircapsalot: do you mean to change the script?
anyway i don't know if i'm going to the right direction but i changed something:
first of all the script is different:
<?php
class Example extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->url('http://www.example.com/');
$this->assertEquals('Example WWW page', $this->title());
}
}
?>
and i installed Xvfb
so now i don't have the error that selenium has failed to start new browser session,
but i'm having another error
PHPUnit_Extensions_Selenium2TestCase_WebDriverException:
Unable to connect to host 127.0.0.1 on port 7055 after 45000ms.
Firefox console output:
Error: no display specified
and i already tried with:
Xvfb :99 -ac -screen 0 1280x1024x24 &
and:
export DISPLAY=:99
i've fixed the "no display specified" error, the mistake was that selenium server was already running when i was starting Xvfb,
so this are the steps (after Xvfb and selenium installation):
run Xvfb ( Xvfb :99 -ac -screen 0 1280x1024x24 & )
export display ( export DISPLAY=:99 )
run selenium ( java -jar selenium-server-standalone-versionNumber.jar )
run script ( phpunit namefile.php )
if selenium is already running you can stop it by:
localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
now the script works