Robot Framework Appium案例

1、验证Android的版本信息

示例代码

*** Settings ***
Suite Setup       Open Settings App
Library           AppiumLibrary



*** Variables ***
${EXPECTED_ANDROID_VERSION}    8.1.0
${EXPECTED_MODEL_NUMBER}    Nexus 6P

*** Test Cases ***
Test Case 1: Model Number Test
    [Tags]    System Information
    Verify Model Number    ${EXPECTED_MODEL_NUMBER}

Test Case 2: Android Version Test
    [Tags]    System Information
    Verify Android Version    ${EXPECTED_ANDROID_VERSION}


   

*** Keywords ***
Open Settings App
    Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=8.1.0    deviceName=dev_name    appPackage=com.android.settings    appActivity=.Settings
    Sleep    2s
    Open About phone page

Open About phone page

    Log    Step 1: Scroll down until find "System"
    : FOR    ${i}    IN RANGE    20
    \    Swipe    400    1000    400    500    200
    \    ${count}    Get Matching Xpath Count    xpath=//*[contains(@text, 'System')]
    \    Exit For Loop If    ${count}>0
	
    Log    Step 2: Click the "System" Label
    Click Element    xpath=//*[contains(@text, 'System')]

    Log    Step 3: Scroll down until find "About phone"
    : FOR    ${i}    IN RANGE    20
    \    Swipe    400    1000    400    500    200
    \    ${count}    Get Matching Xpath Count    xpath=//*[contains(@text, 'About phone')]
    \    Exit For Loop If    ${count}>0
	
    Log    Step 4: Click the "About Phone" Label
    Click Element    xpath=//*[contains(@text, 'About phone')]
	
    Log    Step 3: Scroll down until find "Build number"
    : FOR    ${i}    IN RANGE    20
    \    Swipe    400    1000    400    500    200
    \    ${count}    Get Matching Xpath Count    xpath=//*[contains(@text, 'Build number')]
    \    Exit For Loop If    ${count}>0


Verify Android Version
    [Arguments]    ${expected_android_version}
    Log    Verify the Page if contains the right Android Version
    Page Should Contain Text    ${expected_android_version}    INFO
	Press Keycode    4    None
 

Verify Model Number
    [Arguments]    ${expected_Model_Number}
    Log    Verify the Page if contains the right model number
    Page Should Contain Text    ${expected_Model_Number}    INFO

示例效果

在这里插入图片描述

2、Camera测试

示例代码

*** Settings ***
Library           AppiumLibrary

*** Test Cases ***
open camera
    Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=8.1.0    deviceName=dev_name    appPackage=com.google.android.GoogleCamera    appActivity=com.android.camera.CameraActivity
    Sleep    2s
    Click Element    xpath=//*[contains(@text, 'ALLOW')]
    Sleep    2s

take phone
    Click Element    xpath=//*[contains(@resource-id, 'id/shutter_button')]

示例效果
在这里插入图片描述

3、WiFi测试

示例代码

*** Settings ***
Suite Setup       Open Settings App
Library           AppiumLibrary

*** Variables ***
${SSID_NAME}      vivo
${PASSWORD}       88888888

*** Test Cases ***
Test Case 1: Turn On WiFi
    [Tags]    WiFi Test
    Turn On WiFi

Test Case 2: Connect WiFi
    [Tags]    WiFi Test
    Connect WiFi    ${SSID_NAME}    ${PASSWORD}

*** Keywords ***
Open Settings App
    Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=8.1.0    deviceName=dev_name    appPackage=com.android.settings    appActivity=.Settings
    Sleep    2s
    Open WiFi Setting Page

Open WiFi Setting Page
    Log    Click the "Wi-Fi" Label
    Wait Until Page Contains Element    xpath=//*[contains(@text, 'Network')]    10    Can NOT find "Network" label
    Click Element    xpath=//*[contains(@text, 'Network')]

Turn On WiFi
    Wait Until Page Contains Element    xpath=//*[contains(@resource-id, 'id/switch_widget')]
    ${wifi_status} =    Get Element Attribute    xpath=//*[contains(@resource-id, 'id/switch_widget')]    text
    Run Keyword If    '${wifi_status}' != 'ON'    Click Element    xpath=//*[contains(@resource-id, 'id/switch_widget')]
	Sleep    2s
	Click Element    xpath=//*[contains(@text, 'Wi')]

Connect WiFi
    [Arguments]    ${ssid_name}    ${password}
    Log    Step 1: Click the SSID-Name ${ssid_name}
    Wait Until Page Contains Element    xpath=//*[contains(@text, '${ssid_name}')]    10    Can NOT find ${ssid_name}
    Click Element    xpath=//*[contains(@text, '${ssid_name}')]
    Sleep    2s
    Log    Step 2: Check if the AP ${ssid_name} already connected, if connected then disconnect
    ${count}    Get Matching Xpath Count    xpath=//*[contains(@text, 'Forget')]
    Run Keyword If    ${count} > 0    Log    WiFi already connected, forget it then re-connect
    Run Keyword If    ${count} > 0    Click Element    xpath=//*[contains(@text, 'Forget')]
    Run Keyword If    ${count} > 0    Sleep    2s
    Run Keyword If    ${count} > 0    Click Element    xpath=//*[contains(@text, '${ssid_name}')]
    Run Keyword If    ${count} > 0    Sleep    2s
    Log    Step 3: Input the password then connect.
    Wait Until Page Contains Element    xpath=//*[contains(@resource-id, 'id/password')]    10    Can NOT find "password" text
	Press Keycode    15    None
	Press Keycode    15    None
	Press Keycode    15    None
	Press Keycode    15    None
	Press Keycode    15    None
	Press Keycode    15    None
	Press Keycode    15    None
	Press Keycode    15    None
    Sleep    1s
    Click Element    xpath=//*[contains(@text, 'CONNECT')]
    Log    Step 4: Check if the WiFi connected sucesfully or not.
    Wait Until Page Contains    Connected    10    The device does NOT connect to the Access Point ${ssid_name} yet

示例效果

在这里插入图片描述

4、遇到问题

问题1. Press Keycode 15 None
No keyword with name ‘Press Keycode 15’ found. Did you mean:
AppiumLibrary.Press Keycode

Press Keycode 15 None
直接改代码时,关键词空格格式不对

问题2.
Input Value xpath=//[contains(@resource-id, ‘id/password’)] ${password}
Input Text xpath=//
[contains(@resource-id, ‘id/password’)] ${password}
Cannot set the element to ‘88888888’. Did you interact with the correct element?

input 失败,改为按键输入

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值