RF-APP自动化测试-「Android」

RF-APP自动化测试-「Android」_第1张图片

 

RF框架+Appium也是可以编写app自动化case的,用appium作为一个服务,只要给RF脚本一个 http://localhost:4723/wd/hub的服务地址;远程的话,把localhost 换成具体的ip或域名;

RF-APP自动化测试-「Android」_第2张图片

 

测试Android上的应用,大概需要以下环境:

1.java jdk

2.android的sdk

3.python

4.appium

5.nodejs

6.Appium-python-Client

7.AppiumLibrary

因为目前暂不做app的测试了,没有具体的环境,就不给大家演示环境的搭建了,还望见谅,网上有很多相关的基础环境搭建教程,大神们写的都挺好的,大家可以去自行搜索哈。

本次主要是给大家分享的是基于RF框架下case的编写;因为Android的模拟器非常的慢,所以下面的"启动配置"是以真机为基准来启动的;

var.py 里面是变量的参数,就不放出来了


脚本封装.txt


RF-APP自动化测试-「Android」_第3张图片

 

*** 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 ***
启动配置
 Comment android和APPIUM的配置信息
 Open Application http://localhost:4723/wd/hub platformName=${platformName} platformVersion={platformVersion} deviceName=${deviceName} app=${app} appPackage=${appPackage}
 Comment 等待启动页的按钮出现,设置最多等待${timeout}s
 Wait Until Page Contains Element xpath=//android.widget.Button ${timeout} ${timeout}s内未定位到元素
 Comment 点击启动页的按钮
 Click Element xpath=//android.widget.Button
 
登录
 Wait Until Page Contains Element xpath=//android.widget.LinearLayout[1]/android.widget.EditText ${timeout} ${timeout}s内未定位到元素
 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 点击登录按钮
 Click Element xpath=//android.widget.Button
 
抽屉页
 Comment 等待抽屉按钮出现,设置最多等待${timeout}s
 Wait Until Page Contains Element xpath=//android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout ${timeout} ${timeout}s内未定位到元素
 Comment 点击抽屉按钮
 Click Element xpath=//android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout
 
抽屉_应用_报销
 Comment 定位到应用并点击
 Click Element xpath=//android.widget.RelativeLayout[3]
 Comment 定位到报销并点击
 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内未定位到元素
 Comment 定位到新建并点击
 Click Element xpath=//android.widget.LinearLayout[2]/android.widget.TextView[2]
 Comment 定位到项目并点击
 Click Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[1]
 Comment 选择直接报销
 Wait Until Page Contains Element xpath=//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout ${timeout} ${timeout}s内未定位到元素
 Click Element xpath=//android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout
 Comment 定位到开始时间并点击
 Click Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[2]
 Comment 点击确定
 Click Element xpath=//android.widget.RelativeLayout/android.widget.Button[2]
 Comment 定位到结束时间并点击
 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
 
添加报销明细
 Wait Until Page Contains Element xpath=//android.widget.RelativeLayout[2]/android.widget.ImageView ${timeout} ${timeout}s内未定位到元素
 Comment 进入报销明细
 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内未定位到元素
 Comment 定位到报销分类并点击
 Click Element xpath=//android.widget.ScrollView/android.widget.LinearLayout/android.widget.RelativeLayout[1]
 Comment 选择默认第一个报销分类
 Click Element xpath=//android.widget.RelativeLayout/android.widget.Button[2]
 Comment 定位到金额并点击
 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 点击数字“8”
 Click Element xpath=//android.widget.LinearLayout[2]/android.widget.Button[2]
 Comment 点击“+”
 Click Element xpath=//android.widget.LinearLayout[3]/android.widget.ImageButton[1]
 Comment 点击数字“1”
 Click Element xpath=//android.widget.LinearLayout[4]/android.widget.Button[1]
 Comment 点击数字“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 定位到'张数'并输入内容
 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 点击上传图片按钮
 Click Element xpath=//android.widget.GridView/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ImageView
 Comment 选择相册
 Click Element xpath=//android.widget.LinearLayout/android.widget.TextView[3]
 Comment 选择一个图片
 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 点击 添加完成 按钮
 Click Element xpath=//android.widget.LinearLayout/android.widget.Button[2]
 Wait Until Page Contains Element xpath=//android.widget.Button ${timeout} ${timeout}s内未定位到元素
 Comment 点击弹窗的确定按钮
 Click Element xpath=//android.widget.Button
 Wait Until Page Contains Element xpath=//android.widget.LinearLayout[2]/android.widget.Button[2] ${timeout} ${timeout}s内未定位到元素
 Comment 点击提交按钮
 Click Element xpath=//android.widget.LinearLayout[2]/android.widget.Button[2]
 Wait Until Page Contains Element xpath=//android.widget.Button ${timeout} ${timeout}s内未定位到元素
 Click Element xpath=//android.widget.Button
 
卸载app
 Remove Application ${appPackage}
 
kill 进程
 Comment 杀掉该app在appium服务中的进程
 Close Application
 

【如果认可,还望转发;您的支持,是我继续的动力!】

【如有建议,还望赐教;您的鞭策,是我努力的方向!】

你可能感兴趣的:(Robotframework)