Selenium 服务器启动时

发布于 2024-09-17 19:58:19 字数 455 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

故人如初 2024-09-24 19:58:19

我有同样的问题,我的进程有时无法连接 selenium 服务器。在深入研究调试日志和selenium源代码后,我发现这是因为当selenium尝试生成随机数时,如果/dev/random挂起,java的SecureRandom就会挂起。因此,我将 /dev/random 替换为 /dev/urandom,然后 selenium 服务器工作正常:

sudo mv /dev/random /dev/random.real
sudo ln -s /dev/urandom /dev/random

或者您可以修改 $JAVA_HOME/jre/lib/security/java.security 文件并将属性更改

securerandom.source=file:/dev/random

为:

securerandom.source=file:/dev/urandom

也许它有效,但不适合我。

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.

驱逐舰岛风号 2024-09-24 19:58:19

使用-debug启动Selenium并带有调试日志以查看是否有任何错误。

 java -jar selenium-server.jar -debug  > /var/log/selenium-server.log 2>&1

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
东风软 2024-09-24 19:58:19

我在 ubuntu 14 上使用 npm 完成了此操作。

首先,通过 npm 安装 selenium-standalone。

sudo npm install selenium-standalone -g
sudo selenium-standalone install

然后在/etc/init.d中创建一个符号链接,并将其配置为运行。

sudo ln -s /usr/local/bin/selenium-standalone /etc/init.d/
sudo update-rc.d selenium-standalone defaults

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
腻橙味 2024-09-24 19:58:19

另一个非常简单又好的解决方案是通过docker安装selenium。我使用了 chrome 图像,它很简单:

sudo docker run -d -p 4444:4444 selenium/standalone-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:

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.

油饼 2024-09-24 19:58:19

我将使用 -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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文