Xvfb和Chromedriver有什么区别以及何时使用它们
问题描述:
我打算设置硒来测试我的Web应用程序.
Hi I am planning to setup selenium to test my web application.
我已经阅读了chromedriver和Xvfb均可用于运行测试. 我还读到Xvfb可以配置为使用chromdriver.
I have read that both chromedriver and Xvfb can be used to run the tests. I have also read that Xvfb can be configured to use chromdriver.
这让我感到困惑. chromedriver和Xvfb在运行硒测试中起什么作用.
So that got me confused. What role does chromedriver and Xvfb in runnning the selenium tests.
谢谢
答
- chromedriver-在 chrome 浏览器(带有GUI)上运行测试.
- Xvfb-以 headless 模式运行测试.可以是包括chrome在内的任何浏览器(浏览器GUI不会显示,因此您可以将机器用于其他操作).
- chromedriver - to run tests on chrome browser (with GUI).
- Xvfb - to run tests in headless mode. can be any browser including chrome (Browser GUI won't be displayed, so you can use the machine for some other operations).
代码段(python):
Chrome驱动程序(在此处下载):
Chrome Driver (download here):
browser = webdriver.Chrome() // to launch tests in Chrome browser.
Xvfb-使用pyvirtualdisplay(Xvfb的python包装器):
Xvfb - using pyvirtualdisplay (python wrapper for Xvfb) :
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
# now Chrome will run in a virtual display.
# you will not see the browser.
browser = webdriver.Chrome()
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()
参考文献: