近接手數(shù)據(jù)資源平臺產(chǎn)品的自動化建設(shè),該項目依賴smartgwt框架,項目初期嘗試使用watir、webdriver來進行自動化腳本開發(fā),后都因不能準確定位元素而失敗告終,經(jīng)過多次google和討論,后利用selenium ide工具進行錄制,終于有所成效。(雖然回放偶爾會提示找不到元素)。
好,入正題,利用selenium ide錄制基于smartgwt框架的項目
第一步:搭建selenium ide環(huán)境。
下載selenium ide插件,安裝firefox(注意:selenium ide插件的版本需要與firefox版本兼容,我這里下載的是:selenium-ide-1.10.0.xpi、Firefox_Setup_15.0.1.exe)
第二步:讓selenium ide支持用戶自定義定位器。
由于smartgwt框架采用事件代理,動態(tài)加載頁面元素,因此傳統(tǒng)的通過ID或者簡單的attribute來定位元素行不通,這里我們利用smartgwt提供的自定義定位器來進行(即2個js腳本:user-extensions.js、user-extensions-ide.js 可以從smartgwt官網(wǎng)下載)。
打開selenium ide,在菜單欄選擇【Options】->options選項,加載自定義定位器,如下圖:
打開options界面:
http://img.blog.csdn.net/20130517181204458
加載自定義定位器:
第三步:重啟selenium ide,接下來可以像錄制普通產(chǎn)品一樣進行錄制了。
在錄制過程中可能會遇到的問題:
1、腳本錄制好之后回放,報錯:
[error] Timed out after 30000ms
[error]Element scLocator=//ToolStripButton[ID="isc_ToolStripPermissionButton_19"]/icon not found
該問題可能是速度控制條播放速度過快導(dǎo)致,調(diào)整播放速度至slow