2012年12月12日 星期三

Selenium-WebDriver : Windows Authentication firefox

我試了好久,很多網頁上沒有講清楚,所以我將步驟寫下:

prerequsites : 
1. firefox profile :在 開始->執行->firefox.exe -ProfileManager
2. 預設有 "default" 的profile,如果有需要,可以自行create另一個profile供selenium-webdriver使用
3. 在firefox的 工具->選項->安全->已存密碼 確認target URL的username/password已經被存入
4. 如果item 3沒有看到username/password,則手動login 進入target URL,做一次login,firefox會自動記錄username/password
5. 要注意,當某profile被firefox開起來 時,selenium-webdriver是無法開啟同一profile的,因為被lock住了。
6. 我看到有些網站說要用AutoAuth的add-on附加元件。
    新版firefox(我不確定從何版本開始,但我使用的是17.0.1)不用;
    但是3.6.17 (on Ubuntu 9.10)就需要...
7. 很多網站說要改about:config...我的感覺有點在畫老虎,畫蘭花... :D
8. 還有網站寫driver.get("http://username:password@example.com")的方式,這是for basic authentication,不是for Windows authentication

source code :
require 'rubygems' #windows平台可以不要此行
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox, :profile => "default"
#profile要指定是重點,因為沒有指定的話,selenium-webdriver是不會用任何 firefox profile的

driver.get "http://xxx/ReportServer/Pages/ReportViewer.aspx?yyy&rs:Command=Render"

沒有留言:

張貼留言