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