Selenium 服务器启动时
我在 Ubuntu 系统中使用 Selenium RC。 我想自动化测试,并且需要在机器启动时启动 Selenium-server.jar 。
我在 /ect/init/ 中创建了 seleniumServer.conf:
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
当我重新启动机器时,它工作正常,进程正在运行。 但当我执行测试时,结果是:
PHPUnit_Framework_Exception: Could not connect to the Selenium RC server.
有什么想法吗? 谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我有同样的问题,我的进程有时无法连接 selenium 服务器。在深入研究调试日志和selenium源代码后,我发现这是因为当selenium尝试生成随机数时,如果/dev/random挂起,java的SecureRandom就会挂起。因此,我将 /dev/random 替换为 /dev/urandom,然后 selenium 服务器工作正常:
或者您可以修改 $JAVA_HOME/jre/lib/security/java.security 文件并将属性更改
为:
也许它有效,但不适合我。
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:
Or you can modify
$JAVA_HOME/jre/lib/security/java.security
file and changing the property:to:
Maybe it works, but not for me.
使用-debug启动Selenium并带有调试日志以查看是否有任何错误。
Use -debug to start Selenium with debug log to see if any error.
我在 ubuntu 14 上使用 npm 完成了此操作。
首先,通过 npm 安装 selenium-standalone。
然后在/etc/init.d中创建一个符号链接,并将其配置为运行。
I did this on ubuntu 14 using npm.
First, install the selenium-standalone via npm.
Then create a symbolic link in /etc/init.d, and configure it to run.
另一个非常简单又好的解决方案是通过docker安装selenium。我使用了 chrome 图像,它很简单:
-d
选项使它成为一个守护进程,每次启动计算机时都会重新启动。-p
选项将 webdriver 端口 (4444) 从 docker 实例转发到主机。好吧,它不是 phantomjs,但无论如何我更喜欢 chrome。还有一个火狐图像!查看 https://github.com/SeleniumHQ/docker-selenium 了解更多信息。
Another very simple and good solution is to install selenium via docker. I have used the chrome image and it's easy as:
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.
我将使用 -log 参数启动 selenium 服务器进程,首先从进程中获取信息,然后查看它是否确实获得任何类型的连接、错误等。
一些故障排除的想法:
如果您输入 http://localhost:4444
Jetty 引擎应该会呈现 403 错误。
如果这不起作用,我会尝试使用您的实际 IP:4444,这可能表明本地主机变量、代理设置等存在问题。
防火墙设置是否会阻止 4444 端口?也许 Selenium Server 进程不允许启动浏览器。
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.