以非 root 用户身份从 ruby​​ 在 Xvfb 中运行 Selenium::WebDriver::Firefox [英] Running Selenium::WebDriver::Firefox inside Xvfb from ruby as NON-root user

查看:96
本文介绍了以非 root 用户身份从 ruby​​ 在 Xvfb 中运行 Selenium::WebDriver::Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ruby​​ 脚本进行一些无头测试.本质上,我在显示器 :1 上执行 Xvfb,然后使用 watir-webdriver 启动 Watir::Browser.new(:firefox).

I'm trying to do some headless testing using a ruby script. Essentially I'm executing Xvfb on display :1, and then firing up Watir::Browser.new(:firefox) using watir-webdriver.

如果您以 root 身份运行脚本,这会很有效 - 我可以运行 x11vnc 并观察脚本执行浏览器并与之交互.

This works great if you run the script as root - I can run x11vnc and watch the script execute the browser and interact with it.

问题是,我需要能够从 Rails 应用程序调用这个 ruby​​ 脚本,而不是以 root 身份运行它...如果我尝试以普通用户的身份从命令行运行脚本,Xvfb 就会启动on :1 像往常一样,但 Watir 不会启动浏览器......它最终在 60 秒后超时.通过 VNC 连接会显示带有鼠标光标的黑屏.

The problem is, I need to be able to call this ruby script from a Rails app, and NOT run it as root... if I try to run the script from the command line as a regular user, Xvfb fires up on :1 as usual, but Watir won't start a browser... it eventually times out after 60 seconds. Connecting via VNC reveals a black screen with mouse cursor.

我可以从命令行做很多事情 - 启动 Xvfb,然后启动 firefox --display=:1 并且浏览器启动,所以它一定是 Selenium 的问题,对吧?

I can do the whole lot from the command line - start Xvfb, then start firefox --display=:1 and the browser starts up, so it must be a Selenium issue, right?

Nutshell:除非我以 root 身份运行脚本,否则 Selenium/Webdriver 拒绝在 Xvfb 中启动浏览器.

Nutshell: Selenium/Webdriver refuses to start a browser inside Xvfb unless I run the script as root.

推荐答案

  • 已解决 - 编辑 * - 抱歉,我无法回答这个问题,但显然我的帐户太新,暂时无法回答.
  • 解决了!令人惊讶的是,在您提出问题后,这样的事情往往会自行解决...

    Solved! Amazing how things like this tend to solve themselves AFTER you've asked the question...

    对于那些想知道原因的人,我需要做一些事情...

    For those wanting to know why, there's a few things I needed to do...

    1) 确保有问题的用户有一个工作主目录(www-data 默认没有...它的主目录归 root 所有)

    1) Make sure the user in question has a working home directory (www-data didn't by default... its home dir was owned by root)

    2) 从命令行启动 Xvfb,然后从命令行启动 firefox(不是从脚本中) - 这将使用通常的 .dbus、.gconf 等文件夹填充用户主文件夹

    2) Start Xvfb from command line, and then start firefox from the command line (NOT from within the script) - this will populate the users home folder with the usual .dbus, .gconf etc folders

    3) 如果您收到大量延迟,然后出现加载或保存 firefox-bin 的配置信息时出错"这样的错误消息,请删除用户主目录中的 .dbus 文件夹

    3) If you get a massive delay and then an error message along the lines of "an error occurred while loading or saving configuration information for firefox-bin", delete the .dbus folder in the users home directory

    4) 再试一次 #2 - 如果您之前遇到过配置错误,现在应该没有了.

    4) Try #2 again - if you had a config error before, it should now be gone.

    5) 再次尝试运行脚本.

    5) Try running the script again.

    这对我来说很有吸引力,所以如果您在网络应用程序中运行 Xvfb 和 watir-webdriver 时遇到类似问题,请试一试.

    This worked like a charm for me, so if you're having similar issues running Xvfb and watir-webdriver from within a web app, give it a try.

    感谢所有人为网络上最好的问答网站做出的贡献......这个地方救了我的屁股比我想提到的要多.

    Thanks to all for contributing to what is hands-down the BEST Q&A site on the web... this place has saved my butt more times than I care to mention.

    注意:用户最初输入此修改为他们的问题,因为他们无法弄清楚如何将其发布为答案.后来被一些善意的人从问题中删除,但从未添加为答案.

    Note: the user originally entered this amended to their question, because they could not figure out how to post it as an answer. That was later edited out of the question by some well meaning person but never added as an answer.

    这篇关于以非 root 用户身份从 ruby​​ 在 Xvfb 中运行 Selenium::WebDriver::Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆