4:Keywords參考庫
RobotFramework有很多可以參考的庫,但是我只是用到了BuiltIn和Selenium2Library,里面提供了寫腳本的一些關鍵字,但是Wait Until Element Is Visible這個關鍵字用不了,原因我也不知道為什么。
5:RobotFramework 關鍵字(因時間有限,我會一點一點的累加的,另外我是用Xpath寫的腳本)
open browser| url, browser=firefox,alias=None,remote_url=False,desired_capabilities=None, ff_profile_dir=None
打開瀏覽器 | url表示你需要打開的網頁地址 | browser表示你用什么瀏覽器打開這個網頁 | 后面的內容可以為空,所以忽略。
Set Browser Implicit Wait| seconds
設置瀏覽器等待時間(單位為秒)| seconds 表示瀏覽器等待的時間
input text| locator, text
向文本框輸入值 | locator 表示定位器 | text 表示您要輸入的文本內容
Click Button| locator
單擊按鈕時間| locator表示定位器
Click Link| locator
單擊A標簽| locator表示定位器
Click Element| locator
單擊某個標簽| locator表示定位器
Element should contain|expected, message=
驗證元素被定位器包含文本預期 | expected 表示期望值的locator | Message 表示你想要的消息
這個例子是說明了用戶名和密碼為空的情況下是否有提示‘用戶不存在’
Close All Browsers
關閉所有瀏覽器
unselect frame
集前幀與當前幀(回到頂部的frame,避免frame找不到元素,所以從最頂部的grame開始定位,特別是大模塊之間的定位)
Select frame|locator
設置feame被定位為當前你要定位的frame | locator表示定位器(關鍵屬性為幀id和名稱)
Select From List By Value|locator, *values
從列表中選擇值 | locator表示定位器 | *values表示您要定位的值
Select From List By label| locator, *lable
從列表中選擇你要的定位的標簽 | locator表示定位器 | *lable表示您要定位的標簽
(lable可以是多個值)
Wait Until Keyword Succeeds| timeout, retry_interval, name, *args
等到指定的關鍵字成功或給定的超時過期。| timeout 表示超時 | retry_interval 表示重新操作的間隔時間 | name表示要等待的關鍵字名稱 | *args 表示所需等待加載的locator
Element Should Be Visible| locatormessage=
驗證元素是被定位器可見的 | locator表示定位器 | message可忽略
注:繼上一步"快速添加"后等待10sec(秒) 間隔時間為0sec,然后驗證元素是否被定位器可見,這樣就能解決瀏覽器快速切換模塊導致頁面加載找不到當前元素的情況了。
Drag And Drop By Offset| source, xoffset, yoffset
用于拖拽的按鈕 | source 表示我的元素 | xoffset表示橫向偏移量 |yoffset 表示縱向偏移量
Set Selenium Speed|seconds
設置操作腳本等待時間|seconds 等待時間值,單位秒
注:這個Keyword一旦操作,后面的每個腳本執行的步驟都會等待0.3秒。
choose file| locator , filepath
查看文件 | 定位器 | 路徑
例:Choose File |logo_1 |${logoFilePath}
Run Keyword And Return Status| name | *args
運行關鍵字,并返回一個狀態(true、false) | *args自定義變量
Table Column Should Contain|table_locator, col, expected, loglevel=INFO
列表應該包含,通常用來查找某個字符 |table_locator列表定位器 |col表示列|expected預期值|loglevel表示日志,級別
Element Should Be Visible |locator, message=
表示元素應該可見,用來定位元素的,和click有本質的區別,首先是要可見的,返回true和false,如果為false的話就說明是不可用的element,而click element是一個點擊的動作 | locator表示定位器 | message表示返回的一個消息,這個消息可以用來覆蓋一個默認的錯誤消息,也可為空。
should be true|condition, msg=None
表示返回一個狀態 true和false |condition表示一個條件,狀態, | 消息,用來覆蓋默認的消息
更多參考:http://robotframework.googlecode.com/hg/doc/libraries/BuiltIn.html#Should Be True
未完待續... ...