*** Settings ***
Library AppiumLibrary
*** Variables ***
*** Test Cases ***
连接wifi #testcase名称
[Setup]
:FOR ${i} in range 10 #循环次数为10次
\ 打开设置
\ sleep 1 #每个操作后建议设置等待时间,避免代码执行时找不到界面元素
\ 进入wifi搜索界面
\ sleep 1
\ 连接wifi-johnny50
\ sleep 3
\ 断开wifi-johnny50
\ sleep 2
\ 关闭应用
[Teardown]
*** Keywords ***
打开设置 #定义关键字‘打开设置’
Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1 deviceName=1560ab67 appPackage=com.android.settings appActivity=MainSettings
进入wifi搜索界面 #定义关键字‘进入wifi搜索界面’
Click Element xpath=//*[contains(@text,'WLAN')]
连接wifi-johnny50 #定义关键字‘连接wifi-johnny50’
: FOR ${i} IN RANGE 20
\ swipe 849 934 70 482 1000 #注意滑动时x,y坐标是先结束坐标,后开始坐标
\ sleep 3
\ ${num} Get Matching Xpath Count xpath=//*[contains(@text,'johnny50')] #计算text为johnny50的控件个数,这里用到关键字get matching xpath count
\ Exit For Loop If ${num}>0 #当控件个数大于0时停止滑动
Click Element xpath=//*[contains(@text,'johnny50')]
sleep 1
input text xpath=//*[contains(@resource-id,'com.android.settings:id/password')] chenlong0709
sleep 3
Click Element xpath=//*[contains(@text,'连接')]
断开wifi-johnny50
${num} Get Matching Xpath Count xpath=//*[contains(@text,'点击分享密码')] #使用关键字get matching xpath count来判断wifi是否已连上
Run Keyword If ${num}>0 log wifi had connected
Run Keyword If ${num}>0 click element xpath=//android.widget.TextView[@text='点击分享密码']/../following-sibling::android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView
sleep 1
:FOR ${i} in range 20
\ swipe 0 666 0 352
\ sleep 1
\ ${num1} Get Matching Xpath Count xpath=//*[contains(@text,'删除网络')]
\ Exit For Loop If ${num1}>0
sleep 1
Click Element xpath=//*[contains(@text,'删除网络')]
Click Element xpath=//*[contains(@text,'确定')]
关闭应用
Close Application
robotframework-appiumlibrary 循环连接断开wifi
最新推荐文章于 2024-07-06 19:46:32 发布