您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Watir
Watir WedDriver支持的瀏覽器操作
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/1/14 13:44:29 ] 推薦標(biāo)簽:Watir WedDriver

Watir Webdriver的工作方式是:

Watir 腳本 -> Browser Driver -> Browser ->Screen (or headless)

目前支持的Browser Driver 有IEDriver, ChromeDriver, FFDriver,SafariDriver, HeadlessDriver

我們來(lái)看一下對(duì)各個(gè)browser的支持:

Chrome

標(biāo)準(zhǔn)創(chuàng)建
browser = Watir::Browser.new :chrome

帶profile的創(chuàng)建,下例為設(shè)置不彈出download窗口,并設(shè)置下載默認(rèn)路徑

profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = "/path/to/dir"

browser = Watir::Browser.new :chrome, :profile => profile

帶switch的創(chuàng)建,下例為忽略證書錯(cuò)誤,關(guān)閉popup窗口彈出,禁止自動(dòng)翻譯
browser = Watir::Browser.new :chrome, :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate]

設(shè)置代理
browser = Watir::Browser.new :chrome, :switches => %w[--proxy-server=myproxy.com:8080]

Firefox

標(biāo)準(zhǔn)創(chuàng)建
browser = Watir::Browser.new :firefox

使用默認(rèn)的profile
browser = Watir::Browser.new :firefox, :profile => 'default'

設(shè)置所需的profile
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = "/tmp/webdriver-downloads"
profile['browser.download.folderList'] = 2
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"
 
browser = Watir::Browser.new :firefox, :profile => profile

禁止native event,該方法主要是window使用默認(rèn)的一個(gè)較低level的交互方法來(lái)與webdrive進(jìn)行交互,有時(shí)候會(huì)引起莫名的錯(cuò)誤,可以禁止:
profile = Selenium::WebDriver::Firefox::Profile.new
profile.native_events = false
browser = Watir::Browser.new :firefox, :profile => profile

設(shè)置代理服務(wù)
profile = Selenium::WebDriver::Firefox::Profile.new
profile.proxy = Selenium::WebDriver::Proxy.new :http => 'myproxy.com:8080:, :ssl => 'myproxy.com:8080'

browser = Watir::Browser.new :firefox, :profile => profile

設(shè)置使用addon,例如:firebug
profile = Selenium::WebDriver::Firefox::Profile.new
profile.add_extension "../path/to/firebug.xpi"

browser = Watir::Browser.new :firefox, :profile => profile

IE

標(biāo)準(zhǔn)創(chuàng)建
browser = Watir::Browser.new :firefox

IE使用默認(rèn)配置,也是說(shuō),你必須手工配置IE來(lái)滿足你的需要。

Safari

標(biāo)準(zhǔn)創(chuàng)建
browser = Watir::Browser.new :safari

safari現(xiàn)在支持還不夠完善,有待進(jìn)一步更新。

Headless

Headless不是瀏覽器,他是ruby對(duì)Xvfb的封裝,從而使得能headless的linux上運(yùn)行一個(gè)圖形界面程序。

Xvfb or X virtual framebuffer 是一種將所有的圖形化操作在內(nèi)存中隱式運(yùn)行,而不是在屏幕上顯式運(yùn)行的一種服務(wù)器。

舉個(gè)簡(jiǎn)單的例子
require 'watir-webdriver'
require 'headless'

headless = Headless.new
headless.start

browser = Watir::Browser.start 'www.google.com'
puts b.title
b.close

headless.destroy

通過(guò)先生成headless,我們能在非圖形界面的操作系統(tǒng)上,運(yùn)行一個(gè)圖形界面的程序。

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd