简体   繁体   English

如何在后台运行selenium webdriver?

[英]How to run selenium webdriver in the background?

I've been using Selenium for 2 weeks. 我一直在使用Selenium 2周。

It's been really useful so far. 到目前为止它确实很有用。

When developing, I like having the browsers pop up so I can see what's going on, but in production, I don't want the server to keep opening and closing Firefox windows. 在开发时,我喜欢弹出浏览器,这样我就可以看到发生了什么,但在生产中,我不希望服务器继续打开和关闭Firefox窗口。 I've looked through this forum, done Google searches, etc., but can't find a way to run the browsers in the background. 我查看了这个论坛,完成了谷歌搜索等,但找不到在后台运行浏览器的方法。

Anybody have a tip on how to do this? 有人提示如何做到这一点?

Try PhantomJS which is a headless browser webkit. 试试PhantomJS这是一个无头浏览器webkit。 HTMLUnit is also similar to PhantomJs; HTMLUnit也类似于PhantomJs; however, usage of PhamtomJs is highly recommended. 但是,强烈建议使用PhamtomJs。

PhantomJs uses Google chrome's JavaScript Engine but without a GUI. PhantomJs使用Google chrome's JavaScript Engine但没有GUI。

Refer : http://phantomjs.org/ 参考: http//phantomjs.org/

Found simple solutin for JAVA Seleniun Google Chrome 找到JAVA Seleniun谷歌Chrome的简单解决方案

    System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("headless");
    return new ChromeDriver(options);

if the server is on linux, you can allocate a display just to run selenium using Xvfb to create a virtual display 如果服务器在linux上,你可以使用Xvfb分配显示器来运行selenium来创建虚拟显示器

if the server is on windows you can register the daemon to run as another user than the user logged in, giving the service a desktop. 如果服务器在Windows上,您可以将守护程序注册为以用户登录的另一个用户身份运行,从而为该服务提供桌面服务。 this only work for the local system admin account or by registry tweaking as detailed here note that you will have to set up internet explorer properties for the user the service is running as 这仅适用于本地系统管理员帐户或通过注册表调整,如此处详细说明您必须为运行该服务的用户设置Internet Explorer属性

Give it a try : https://github.com/detro/ghostdriver . 试一试: https//github.com/detro/ghostdriver

It uses Headless approach to automate websites. 它使用Headless方法自动化网站。

Phantom is good headless option, but sssuming you want to stick with same tools you are using ... (the following assumes Linux as platform) Phantom是一个很好的无头选择,但是你想要坚持使用你正在使用的相同工具......(以下假设Linux作为平台)

  1. install xvfb (apt-get install xvfb) 安装xvfb(apt-get install xvfb)
  2. You can then run selenium/firefox "headless" (assuming Linux) with the following command:- 然后,您可以使用以下命令运行selenium / firefox“headless”(假设Linux): -

DISPLAY=:1 xvfb-run java -jar [selenium JAR filename] DISPLAY =:1 xvfb-run java -jar [selenium JAR filename]

Now, when your test suite kicks off selenium, it will run using Firefox without browser windows popping up. 现在,当您的测试套件启动selenium时,它将使用Firefox运行而不会弹出浏览器窗口。

Have you thought about running against a Selenium Grid instead? 您是否考虑过反对Selenium Grid? See https://code.google.com/p/selenium/wiki/Grid2 请参阅https://code.google.com/p/selenium/wiki/Grid2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM