Using Laravel 5+ with Vagrant.
I have selenium running using:
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.firefox.bin="/usr/bin/firefox"
using a headless display:
sudo Xvfb :10 -ac
However when i run codeception:
./vendor/bin/codecept run selenium --steps
I get the following error:
[Facebook\WebDriver\Exception\UnknownServerException] Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: GDK_BACKEND does not match available displays
I am confused with server and ports that i should be using.
Currently i access site through http://localhost:8000
however that is outside vagrant.
I observe $url = 'http://localhost:4444/wd/hub', inside api\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php
As the error outputs :
127.0.0.1 on port 7055.
Actually you should download latest geckodriver from here and set property Dwebdriver.gecko.driver with downloaded geckodriver path from your system when you run the selenium-server-standalone.jar as below :
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.firefox.bin="/usr/bin/firefox" -Dwebdriver.gecko.driver = "path/to/downloaded geckodriver
Note : Just like the other drivers available to Selenium from other browser vendors, Mozilla has released an executable geckodriver that will run alongside with the latest firefox browser. For more information you should follow this link.
Now you need to set capability with marionette to true during initialisation of RemoteWebDriver inside api\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php as :
$capabilities->setCapability('marionette', true);
Full example code :
$host = 'http://localhost:4444/wd/hub';
$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability('marionette', true);
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
Switched to chrome web driver, was less complicated, more compatible and works fine for me.
Download chrome webdriver or composer require
Setup environment
nohup sudo Xvfb :10 -ac &
export DISPLAY=:10
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.chrome.bin="/usr/bin/google-chrome" -Dwebdriver.chrome.driver="vendor/bin/chromedriver"
Related
I've executed selenium-server-standalone-3.141.59.jar in my local machine and when I tried to 'Create Session' below mentioened error shows up in the Chrome browser.
And here's how I launched selenium-server-standalone-3.141.59.jar in CMD
You need to download the latest binary of chromedriver.exe Chrome Driver Download
Once your hub is started then you have start your node using below command where you need to provide file path of your chromedriver.exe [Windows]
java -Dwebdriver.chrome.driver=<file path of your chromedriver.exe> -jar <file path of your selenium standalone jar file> -role node -hub <url of your hub>
I am trying to get Protactor.js unit testing up and running with Jenkins on a windows server but I am having trouble getting it to run.
Currently this is the steps I have so far:
#install protractor via package.json
cd ./src/My\ Editor/WebApp/Scripts/protractor && D:Jenkins/nodesjs/npm install
[other build steps here]
#start webdriver-manager
./src/My\ Editor/WebApp/Scripts/protractor/node_modules/protractor/bin/webdriver-manager start > /dev/null 2>&1 &
#wait until selenium up
while ! curl http://localhost:4444/wd/hub/status &>/dev/null
do
true
done
#run protractor
cd ./src/My\ Editor/WebApp/Scripts/protractor/node_modules/protractor/bin/
./protractor ../../../conf.js
#stop selenium
curl -s -L http://localhost:4444/selenium-server/driver?cmd-shutDownSeleniumServer > /dev/null 2>&1
everything works well until the command 'protractor conf.js'. I get this output:
[21:12:34] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[21:12:34] I/launcher - Running 1 instances of WebDriver
[21:12:34] E/launcher - Error forwarding the new session empty pool of VM for setup capabilities [{count=1, browserName=chrome}]
Any help for what I am doing wrong is appreciated, thank you.
Is there a specific need to start a Selenium Server/hub?
If you dont have a plan to setup a Selenium GRID and you just need to run protractor test scripts stand-alone you can skip the part where you are starting server.
Can you leave the remove seleniumAddress option in Protractor.conf.js. This will enable Protractor to start its own selenium server & wait till server is completely up and execute and will shutdown the server once execution is done
More information here
/**
* The address of a running Selenium Server. If specified, Protractor will
* connect to an already running instance of Selenium. This usually looks like
* seleniumAddress: 'http://localhost:4444/wd/hub'
*/
seleniumAddress?: string;
just have the step #run protractor and rest is taken care by Protractor
I face with Error: no display specified error when running play framework tests in Jenkins at FreeBSD server.
So every time I face with timeout
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox
Jenkins has:
1) Xvfb plugin installed
2) Play Framework installed
Tests are written using selenide library and selenide module for play framework.
Xvfb configured and enabled in job configuration.
Job console output is:
Checking out Revision 3f485bd2e3dbcfa058fc19f89ab18020e36707d8 (origin/trunk)
...
Xvfb starting$ /usr/local/bin//Xvfb :1 -screen 0 -fbdir /usr/local/jenkins/xvfb-9-786185694297443042.fbdir
...
Command detected: clean
Command detected: deps --sync
Command detected: precompile
Command detected: auto-test
[YalsTests] $ /srv/java/play/play clean
...
~ using java version "1.8.0_72"
[YalsTests] $ /srv/java/play/play auto-test
~ 14 tests to run:
~
~ selenium/front/CorrectInput... org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:113)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
Job configuration:
[X] Start Xvfb before the build, and shut it down after.
Xvfb specific display name 1
Xvfb display name offset 0
Invoke Play Framework
Command set Play 1.x
Goals
Clean project [clean]
Custom parameter
Custom command deps --sync
Precompile all Java sources and templates [precompile]
Automatically run all application tests [auto-test]
The selenium tasks needs to know the DISPLAY that it shall connect to.
You can set it e.g. as an environment variable (don't forget to export it, if you do that in .profile)
export DISPLAY=:10
This is for bash, other shells might need a 2 step process:
DISPLAY=:10
export DISPLAY
You can also specify the variable at the command line before the command:
DISPLAY=:10 java -jar mySelenium.jar
You could avoid all these issues by using Selenoid project which starts headless browsers in parallel in Docker containers. Container images are created by considering compatible version of webdriver and browser. They also include fonts, flashplayer and so on. Just choose one of already existing images and run your tests. No need to install Java to run Selenium tests.
I tend to supply this if I'm running my tests via Jenkins:
xvfb-run --server-args="-screen 0, 1920x1080x16" mvn clean install...
One thing that has tripped me up in the past is that while xvfb-run will create a virtual display, it can really screw up your screenshots and web interactions if it isn't sized correctly, so it's usually advisable to supply a resolution size which will suitably display your browser.
Can somebody tell me how to use the Chrome driver in Selenium for Linux platform?
I have my chrome driver location at username/home/chromedriver.
My code is:
System.setProperty("webdriver.chrome.driver", "/home/username/ChromeDriver/chromedriver");
driver = new ChromeDriver();
driver.get("facebook.com");
The error I am getting is:
org.openqa.selenium.WebDriverException: Unable to either launch or
connect to Chrome. Please check that ChromeDriver is up-to-date.
Using Chrome binary at: /opt/google/chrome/google-chrome
(WARNING: The server did not provide any stacktrace information)
From [the official documentation](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver:
Requirements
The ChromeDriver controls the browser using Chrome's automation proxy
framework.
The server expects you to have Chrome installed in the default
location for each system:
OS Expected Location of Chrome
-------------------------------------
Linux /usr/bin/google-chrome
Mac /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary. See also the section on overriding the Chrome binary location.
Getting Started
To get set up, first
download the
appropriate prebuilt server. Make sure the server can be located on
your PATH or specify its location via the webdriver.chrome.driver
system property. Finally, all you need to do is create a new
ChromeDriver instance:
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
Therefore, download the version of chromedriver you need, unzip it somewhere on your PATH (or specify the path to it via a system property), then run the driver.
We have installed Successfully
sudo apt-get install unzip
wget -N http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip -P ~/Downloads
unzip ~/Downloads/chromedriver_linux64.zip -d ~/Downloads
chmod +x ~/Downloads/chromedriver
sudo mv -f ~/Downloads/chromedriver /usr/local/share/chromedriver
Change the directory to /usr/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
Now run the script and add the following in the environment file.
Capybara.register_driver :chrome do |app| client = Selenium::WebDriver::Remote::Http::Default.new Capybara::Selenium::Driver.new(app, :browser => :chrome, :http_client => client) end
Capybara.javascript_driver = :chrome
Note : Change the chrome driver version according to your operating system type like 32 bit or 64 bit.
Here is a complete script for Linux 18.04 to install Google Chrome and the chrome driver. It should automatically adjust to collect the correct chrome driver for the browser.
#!/usr/bin/env bash
# install the latest version of Chrome and the Chrome Driver
apt-get update && apt-get install -y libnss3-dev
version=$(curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE)
wget -N http://chromedriver.storage.googleapis.com/${version}/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin
chmod +x /usr/local/bin/chromedriver
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
For me worked with these commands:
Unziped the file -> unzip -q chromedriver_linux64.zip
Force the copy to the directory 'usr/bin' -> sudo mv -f chromedriver /usr/bin
The selenium code was something like that.
System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://mvnrepository.com");
driver.close();
You can see small example from this example
For linux, i downlaod chrome driver and keep as system path variable(or put in exist path folder). And from code i use following ways (add property and initiate with path of chrome driver)
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("/usr/local/bin/chromedriver"))
.usingAnyFreePort()
.build();
try {
service.start();
} catch (IOException e) {
e.printStackTrace();
}
return new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
I'm using Selenium RC in a Ubuntu system.
I want to automate the tests, and I need to start Selenium-server.jar on startup of the machine.
I created seleniumServer.conf in /ect/init/ with:
start on startup
start on runlevel 3
respawn
exec xvfb-run java -jar /home/condde/selenium-server-1.0.3/selenium-server.jar -port 4444
When I reboot the machine, it works fine, the process is running.
But when I execute a test, the result is:
PHPUnit_Framework_Exception: Could not connect to the Selenium RC server.
Any ideas?
Thanks!
I have the same problem, my process can not connect the selenium server sometimes. After dig into debug log and selenium source code, I found that's because java's SecureRandom hangs if /dev/random hangs when selenium try generate random number. So I replace /dev/random with /dev/urandom, then selenium server works fine:
sudo mv /dev/random /dev/random.real
sudo ln -s /dev/urandom /dev/random
Or you can modify $JAVA_HOME/jre/lib/security/java.security file and changing the property:
securerandom.source=file:/dev/random
to:
securerandom.source=file:/dev/urandom
Maybe it works, but not for me.
Use -debug to start Selenium with debug log to see if any error.
java -jar selenium-server.jar -debug > /var/log/selenium-server.log 2>&1
I did this on ubuntu 14 using npm.
First, install the selenium-standalone via npm.
sudo npm install selenium-standalone -g
sudo selenium-standalone install
Then create a symbolic link in /etc/init.d, and configure it to run.
sudo ln -s /usr/local/bin/selenium-standalone /etc/init.d/
sudo update-rc.d selenium-standalone defaults
Another very simple and good solution is to install selenium via docker. I have used the chrome image and it's easy as:
sudo docker run -d -p 4444:4444 selenium/standalone-chrome
The -d option makes is a daemon that will be restarted every time you start your computer. The -p option forwards the webdriver port (4444) from the docker instance to the host.
Well, it's not phantomjs, but I like chrome better anyway. There is also a firefox image! Checkout https://github.com/SeleniumHQ/docker-selenium for more info.
I would start the selenium server process with -log parameter to get info from the process first and all and see if it actually get any kind of connections, errors etc..
A few ideas to troubleshoot:
Do you get any response if you enter http://localhost:4444
It should render a 403 error by the Jetty engine.
If this does not work I would try with your actual IP:4444, that might indicate problem with localhost variable, proxy settings etc..
Could the firewall settings be blocking the the 4444 port? Maybe the Selenium Server process is not allowed to start the browser.