序
本文主要讨论Selenium不同webdriver的构造
Selenium 2.0
Selenium 2,又名 WebDriver,它的主要新功能是集成了 Selenium 1.0 以及 WebDriver(WebDriver 曾经是 Selenium 的竞争对手)。也就是说 Selenium 2 是 Selenium 和 WebDriver 两个项目的合并,即 Selenium 2 兼容 Selenium,它既支持 Selenium API 也支持 WebDriver API。
支持的web driver
- ChromeDriver
- EventFiringWebDriver
- FirefoxDriver
- HtmlUnitDriver
- InternetExplorerDriver
- PhantomJSDriver
- RemoteWebDriver
- SafariDriver
PhantomJS与Ghost Driver
phantomis就是一个基于webkit的无界面浏览器,而ghost driver是phantomis的WebDriver Wire Protocol的js实现。 后来ghost driver跟phantomjs合并在一起,内嵌在phantomis中,相当于现在的phantomis = ghost driver + phantomis浏览器
driver特性
chromedriver
chrome driver的好处是支持mobile emulation
MapmobileEmulation = new HashMap<>(); mobileEmulation.put("deviceName", "iphone 5"); Map chromeOptions = new HashMap<>(); chromeOptions.put("mobileEmulation", mobileEmulation); dcaps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
firefoxdriver(geckodriver
)
FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(true); profile.setAcceptUntrustedCertificates(true); profile.setAssumeUntrustedCertificateIssuer(false); dcaps.setCapability(FirefoxDriver.PROFILE, profile);
firefox的功能看起来相对鸡肋一些
通用设置
LoggingPreferences logging = new LoggingPreferences(); logging.enable(LogType.PERFORMANCE, Level.ALL); logging.enable(LogType.BROWSER, Level.ALL); dcaps.setCapability(CapabilityType.LOGGING_PREFS, logging); dcaps.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);