Is it possible to hide the browser in Selenium RC?

2019-01-02 22:23发布

I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?

11条回答
聊天终结者
2楼-- · 2019-01-02 22:36

There are a few options:

  • You could use Selenium Grid so that the browser is opened on a completely different machine (or virtual machine) that you can then connect to via VNC or Remote Desktop Connection if you wanted to see the browser. Also, another option: if you run a Jenkins foreground process on that remote server, it can execute your test project on the desktop.

  • You can run Selenium 'headless' on Linux in XVFB. I've never tried doing this and doubt it's really worth the effort. http://www.alittlemadness.com/2008/03/05/running-selenium-headless/

  • You can wrap Selenium RC in a Windows service. http://support.microsoft.com/kb/137890 . Except that permissions constraints on later versions of windows will probably prevent Selenium from accessing the desktop like Windows 2000 used to allow us to do.

  • Another option would be to use something like WebDriver HTMLUnitDriver, which doesn't launch a 'real' browser. http://code.google.com/p/webdriver/ . Also there is a PhantomJS option as well as a 'headless Chrome' that you could use.

  • Of course there's also the option of using a service like SauceLabs, where you can get your tests to be run in the cloud. After your tests have completed you can watch a video of them running.

查看更多
劫难
3楼-- · 2019-01-02 22:36

In many cases PhantomJS will not completely suit your needs, I would like to elaborate on the headless chrome option mentioned in Dave Hunt's answer.

chrome 57 has just launched this feature. You can use it by passing the --headless flag via ChromeDriver, for more info see the discussion in this question

查看更多
做自己的国王
4楼-- · 2019-01-02 22:36
curl -k https://gist.githubusercontent.com/terrancesnyder/995250/raw/cdd1f52353bb614a5a016c2e8e77a2afb718f3c3/ephemeral-x.sh -o ~/ephemeral-x.sh
chmod +x ~/ephemeral-x.sh
~/ephemeral-x.sh TestsStarterCommand

By the way this is a feature needed by any developer running e2e that logically will spawn browsers. In a development environment it is annoying to deal with the window that keeps popping up and which which you can accidentally interact making the test fail.

查看更多
太酷不给撩
5楼-- · 2019-01-02 22:38

I easily managed to hide the browser window.

Just install PhantomJS. Then, change this line:

driver = webdriver.Firefox()

to:

driver = webdriver.PhantomJS()

The rest of your code won't need to be changed and no browser will open. For debugging purposes, use driver.save_screenshot('screen.png') at different steps of your code.

查看更多
小情绪 Triste *
6楼-- · 2019-01-02 22:41

+1 for Selenium RC as a windows service.

For having the tests run completely hidden, I think you don't have much solutions if you're on windows.

What I'd do it to dedicate a computer in your LAN to be online all the time and have a selenium RC server running. So you use that computer's IP instead of localhost to run your tests. For example:

browser = selenium("10.15.12.34",4444,"*firefox","http://saucelabs.com")

(considering that that's the ip of the computer running the server).

Having that setup, you run your tests in you computer, the browsers and the RC server window are in another computer and the go back to yours once done.

查看更多
SAY GOODBYE
7楼-- · 2019-01-02 22:45

If you're on Windows, one option is to run the tests under a different user account. This means the browser and java server will not be visible to your own account.

查看更多
登录 后发表回答