RF框架+Appium也是可以編寫app自動(dòng)化case的,用appium作為一個(gè)服務(wù),只要給RF腳本一個(gè) http://localhost:4723/wd/hub的服務(wù)地址;遠(yuǎn)程的話,把localhost 換成具體的ip或域名;
測(cè)試Android上的應(yīng)用,大概需要以下環(huán)境:
1.java jdk
2.android的sdk
3.python
4.appium
5.nodejs
6.Appium-python-Client
7.AppiumLibrary
因?yàn)槟壳皶翰蛔鯽pp的測(cè)試了,沒(méi)有具體的環(huán)境,就不給大家演示環(huán)境的搭建了,還望見(jiàn)諒,網(wǎng)上有很多相關(guān)的基礎(chǔ)環(huán)境搭建教程,大神們寫的都挺好的,大家可以去自行搜索哈。
本次主要是給大家分享的是基于RF框架下case的編寫;因?yàn)锳ndroid的模擬器非常的慢,所以下面的"啟動(dòng)配置"是以真機(jī)為基準(zhǔn)來(lái)啟動(dòng)的;
var.py 里面是變量的參數(shù),就不放出來(lái)了
腳本封裝.txt
*** Settings ***
Variables var.py
Library AppiumLibrary
*** Keywords ***
accept_alert
: FOR ${i} IN RANGE 2
\ Wait Until Page Contains Element xpath=//android.widget.Button[2] ${timeout}
\ Click Element xpath=//android.widget.Button[2]
\ log ${i}
具體的case如下:
*** Settings ***
Library AppiumLibrary
Variables var.py
Resource 腳本封裝.txt
*** Test Cases ***
啟動(dòng)配置
Comment android和APPIUM的配置信息
Open Application http://localhost:4723/wd/hub platformName=${platformName} platformVersion={platformVersion} deviceName=${deviceName} app=${app} appPackage=${appPackage}
Comment 等待啟動(dòng)頁(yè)的按鈕出現(xiàn),設(shè)置最多等待${timeout}s
Wait Until Page Contains Element xpath=//android.widget.Button ${timeout} ${timeout}s內(nèi)未定位到元素
Comment 點(diǎn)擊啟動(dòng)頁(yè)的按鈕
Click Element xpath=//android.widget.Button
登錄
Wait Until Page Contains Element xpath=//android.widget.LinearLayout[1]/android.widget.EditText ${timeout} ${timeout}s內(nèi)未定位到元素
Run Keyword And Ignore Error accept_alert
Comment 輸入用戶名
Input Text xpath=//android.widget.LinearLayout[1]/android.widget.EditText ${username}
Comment 輸入密碼
Input Password xpath=//android.widget.LinearLayout[2]/android.widget.EditText ${password}
Comment 點(diǎn)擊登錄按鈕
Click Element xpath=//android.widget.Button
抽屜頁(yè)
Comment 等待抽屜按鈕出現(xiàn),設(shè)置最多等待${timeout}s
Wait Until Page Contains Element xpath=//android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout ${timeout} ${timeout}s內(nèi)未定位到元素
Comment 點(diǎn)擊抽屜按鈕
Click Element xpath=//android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout
抽屜_應(yīng)用_報(bào)銷
Comment 定位到應(yīng)用并點(diǎn)擊
Click Element xpath=//android.widget.RelativeLayout[3]
Comment 定位到報(bào)銷并點(diǎn)擊
Sleep 2
Click Element xpath=//android.widget.ExpandableListView/android.widget.RelativeLayout[7]
Wait Until Page Contains Element xpath=//android.widget.LinearLayout[2]/android.widget.TextView[2] ${timeout} ${timeout}s內(nèi)未定位到元素
Comment 定位到新建并點(diǎn)擊
Click Element xpath=//android.widget.LinearLayout[2]/android.widget.TextView[2]
Comment 定位到項(xiàng)目并點(diǎn)擊
Click Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[1]
Comment 選擇直接報(bào)銷
Wait Until Page Contains Element xpath=//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout ${timeout} ${timeout}s內(nèi)未定位到元素
Click Element xpath=//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout
Comment 定位到開始時(shí)間并點(diǎn)擊
Click Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[2]
Comment 點(diǎn)擊確定
Click Element xpath=//android.widget.RelativeLayout/android.widget.Button[2]
Comment 定位到結(jié)束時(shí)間并點(diǎn)擊
Click Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[3]
Click Element xpath=//android.widget.RelativeLayout/android.widget.Button[2]
Comment 保存下一步
Click Element xpath=//android.widget.RelativeLayout/android.widget.Button
添加報(bào)銷明細(xì)
Wait Until Page Contains Element xpath=//android.widget.RelativeLayout[2]/android.widget.ImageView ${timeout} ${timeout}s內(nèi)未定位到元素
Comment 進(jìn)入報(bào)銷明細(xì)
Click Element xpath=//android.widget.RelativeLayout[2]/android.widget.ImageView
Wait Until Page Contains Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[1] ${timeout} ${timeout}s內(nèi)未定位到元素
Comment 定位到報(bào)銷分類并點(diǎn)擊
Click Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[1]
Comment 選擇默認(rèn)第一個(gè)報(bào)銷分類
Click Element xpath=//android.widget.RelativeLayout/android.widget.Button[2]
Comment 定位到金額并點(diǎn)擊
Click Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[2]
Wait Until Page Contains Element xpath=//android.widget.LinearLayout[2]/android.widget.Button[2] ${timeout}
Comment 點(diǎn)擊數(shù)字“8”
Click Element xpath=//android.widget.LinearLayout[2]/android.widget.Button[2]
Comment 點(diǎn)擊“+”
Click Element xpath=//android.widget.LinearLayout[3]/android.widget.ImageButton[1]
Comment 點(diǎn)擊數(shù)字“1”
Click Element xpath=//android.widget.LinearLayout[4]/android.widget.Button[1]
Comment 點(diǎn)擊數(shù)字“0”
Click Element xpath=//android.widget.LinearLayout[5]/android.widget.Button[1]
Comment 確定金額
Click Element xpath=//android.widget.LinearLayout[5]/android.widget.Button[4]
Comment 定位到'張數(shù)'并輸入內(nèi)容
Input Text xpath=//android.widget.RelativeLayout[3]/android.widget.EditText 8
Run Keyword And Ignore Error Hide Keyboard
Comment Register Keyword To Run On Failure Hide Keyboard
Comment ${msg} Run Keyword And Expect Error None Wait Until Page Contains Element xpath=//android.widget.LinearLayout/android.widget.Button[2] 2
Comment ${return} Run Keyword And Return Status Wait Until Page Contains Element xpath=//android.widget.LinearLayout/android.widget.Button[2] 2
Comment Run Keyword If ${return}==False Go Back
Comment Press Keycode 4
Comment 點(diǎn)擊上傳圖片按鈕
Click Element xpath=//android.widget.GridView/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ImageView
Comment 選擇相冊(cè)
Click Element xpath=//android.widget.LinearLayout/android.widget.TextView[3]
Comment 選擇一個(gè)圖片
Click Element xpath=//android.widget.ListView/android.widget.RelativeLayout[1]
Wait Until Page Contains Element xpath=//android.widget.LinearLayout/android.widget.Button[2] ${timeout}
Comment 點(diǎn)擊 添加完成 按鈕
Click Element xpath=//android.widget.LinearLayout/android.widget.Button[2]
Wait Until Page Contains Element xpath=//android.widget.Button ${timeout} ${timeout}s內(nèi)未定位到元素
Comment 點(diǎn)擊彈窗的確定按鈕
Click Element xpath=//android.widget.Button
Wait Until Page Contains Element xpath=//android.widget.LinearLayout[2]/android.widget.Button[2] ${timeout} ${timeout}s內(nèi)未定位到元素
Comment 點(diǎn)擊提交按鈕
Click Element xpath=//android.widget.LinearLayout[2]/android.widget.Button[2]
Wait Until Page Contains Element xpath=//android.widget.Button ${timeout} ${timeout}s內(nèi)未定位到元素
Click Element xpath=//android.widget.Button
卸載app
Remove Application ${appPackage}
kill 進(jìn)程
Comment 殺掉該app在appium服務(wù)中的進(jìn)程
Close Application