robotframework-appiumlibrary 循环连接断开wifi

*** 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值