Xvfb和Chromedriver有什么区别以及何时使用它们 [英] What is difference between Xvfb and Chromedriver and when to use them

查看:493
本文介绍了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.

谢谢

推荐答案

  1. chromedriver-在 chrome 浏览器(带有GUI)上运行测试.
  2. Xvfb-以 headless 模式运行测试.可以是包括chrome在内的任何浏览器(浏览器GUI不会显示,因此您可以将机器用于其他操作).
  1. chromedriver - to run tests on chrome browser (with GUI).
  2. 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()

参考文献:

  1. 如何在Xvfb中运行Selenium?

这篇关于Xvfb和Chromedriver有什么区别以及何时使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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