developer tip

Selenium RC에서 브라우저를 숨길 수 있습니까?

optionbox 2020. 9. 5. 09:44
반응형

Selenium RC에서 브라우저를 숨길 수 있습니까?


일부 브라우저 작업을 자동화하기 위해 Selenium RC를 사용하고 있지만 브라우저가 보이지 않게하고 싶습니다. 이게 가능해? 어떻게? 셀레늄 그리드는 어떻습니까? Selenium RC 창도 숨길 수 있습니까?


몇 가지 옵션이 있습니다.

  • 브라우저를 보려면 VNC 또는 원격 데스크톱 연결을 통해 연결할 수있는 완전히 다른 컴퓨터 (또는 가상 컴퓨터)에서 브라우저가 열리도록 Selenium Grid를 사용할 수 있습니다. 또한 다른 옵션 : 해당 원격 서버에서 Jenkins 포 그라운드 프로세스를 실행하면 데스크톱에서 테스트 프로젝트를 실행할 수 있습니다.

  • XVFB의 Linux에서 Selenium 'headless'를 실행할 수 있습니다. 나는 이것을 시도한 적이 없으며 노력할만한 가치가 있는지 의심합니다. http://www.alittlemadness.com/2008/03/05/running-selenium-headless/

  • Windows 서비스에서 Selenium RC를 래핑 할 수 있습니다. http://support.microsoft.com/kb/137890 . 이후 버전의 Windows에 대한 권한 제약으로 인해 Selenium이 Windows 2000과 같은 데스크톱에 액세스하지 못하도록 할 수 있다는 점을 제외하고는 가능합니다.

  • 또 다른 옵션은 '실제'브라우저를 실행하지 않는 WebDriver HTMLUnitDriver와 같은 것을 사용하는 것입니다. http://code.google.com/p/webdriver/ . 또한 PhantomJS 옵션과 사용할 수있는 'headless Chrome'이 있습니다.

  • 물론 클라우드에서 테스트를 실행할 수있는 SauceLabs와 같은 서비스를 사용하는 옵션도 있습니다. 테스트가 완료되면 실행중인 비디오를 볼 수 있습니다.


Linux에서는 헤드리스 (가상) 디스플레이에서 WebDriver를 실행하여 브라우저를 숨길 수 있습니다. 이것은 Xvfb (X 가상 프레임 버퍼)로 수행 할 수 있습니다.

https://github.com/cgoldberg/xvfbwrapper를 사용하여 Python 코드에서 직접 Xvfb를 제어 할 수 있습니다 xvfbwrapper.

헤드리스 실행을위한 Python 코드는 다음과 같습니다.

from selenium import webdriver
from xvfbwrapper import Xvfb

display = Xvfb()
display.start()

# now Firefox will run in a virtual display. 
# you will not see the browser.
driver = webdriver.Firefox()
driver.get('http://www.google.com')

print(driver.title)
driver.quit()

display.stop()

Debian / Ubuntu에 종속 항목을 설치합니다.

$ sudo apt-get install xvfb
$ pip install xvfbwrapper

브라우저 창을 쉽게 숨길 수있었습니다.

그냥 PhantomJS를 설치합니다 . 그런 다음 다음 줄을 변경하십시오.

driver = webdriver.Firefox()

에:

driver = webdriver.PhantomJS()

나머지 코드는 변경할 필요가 없으며 브라우저가 열리지 않습니다. 디버깅 목적으로 driver.save_screenshot('screen.png')코드의 다른 단계에서 사용 하십시오.


Windows 서비스로 Selenium RC의 경우 +1.

테스트를 완전히 숨겨서 실행하려면 Windows에있는 경우 솔루션이 많지 않다고 생각합니다.

LAN에있는 컴퓨터를 항상 온라인 상태로 유지하고 셀레늄 RC 서버를 실행하기 위해 내가하고자하는 일입니다. 따라서 테스트를 실행하기 위해 localhost 대신 해당 컴퓨터의 IP를 사용합니다. 예를 들면 :

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

(서버를 실행하는 컴퓨터의 IP라고 생각하면).

설정을 마치면 컴퓨터에서 테스트를 실행하고 브라우저와 RC 서버 창은 다른 컴퓨터에 있으며 완료되면 다시 자신의 컴퓨터로 돌아갑니다.


Linux에서는 가상 디스플레이에서 테스트 브라우저를 실행할 수 있습니다. xvfb가상 X 서버를 만들기위한 패키지 가 필요 합니다. Debian 기반 배포판에서는 다음을 실행하십시오.

sudo apt-get install xvfb

ephemeral-x.sh가상 디스플레이에서 실행할 명령을 편리하게 설정 하는 멋진 도구 가 있습니다. 다운로드하여 실행 가능하게 만드십시오.

wget https://raw.github.com/jordansissel/xdotool/master/t/ephemeral-x.sh
chmod +x ephemeral-x.sh

그런 다음이를 사용하여 Selenium 서버를 시작할 수 있습니다.

./ephemeral-x.sh java -jar selenium-standalone.jar

All browser windows created by Selenium will now use the virtual display and will be invisible to you.


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.


This is how I run my tests with maven on a linux desktop (Ubuntu). I got fed up not being able to work with the firefox webdriver always taking focus.

I installed xvfb

xvfb-run -a mvn clean install

Thats it


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


There is a PhantomJS related project called GhostDriver , that is meant to run PhantomJS instances in a Selenium Grid using webdriver wire JSON protocol. That is probably what you are looking for, although this question is 4 years old now.


On MacOSX, I haven't been able to hide the browser window, but at least I figured out how to move it to a different display so it doesn't disrupt my workflow so much. While Firefox is running tests, just control-click its icon in the dock, select Options, and Assign to Display 2.


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.


Using headless Chrome would be your best bet, or you could post directly to the site to interact with it, which would save a lot of compute power for other things/processes. I use this when testing out web automation bots that search for shoes on multiple sites using cpu heavy elements, the more power you save, and the simpler your program is, the easier it is to run multiple processes at a time with muhc greater speed and reliability.

참고URL : https://stackoverflow.com/questions/1418082/is-it-possible-to-hide-the-browser-in-selenium-rc

반응형