当前位置: 动力学知识库 > 问答 > 编程问答 >

Selenium Server on startup

问题描述:

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.

网友答案:

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.

网友答案:

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 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: