Robot Framework Appium案例
程序员文章站
2024-03-22 16:05:40
...
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 失败,改为按键输入
上一篇: 前端自动化测试实践02—jest基本语法
下一篇: 快速学习-Kylin Cube构建优化
推荐阅读
-
Robot Framework Appium案例
-
Robot Framework 常见问题处理方式
-
Python3 + Robot Framework的安装与实例演示
-
Robot Framework + Selenium library + IEDriver环境搭建
-
Robot Framework测试环境搭建(python3.7.2,pip在线安装)
-
[Android自动化测试(四)] robot framework+appium元素定位
-
Python3.7+Robot Framework+RIDE1.7.4.1安装使用教程
-
Byteart Retail V2 - 基于Entity Framework Code First的领域驱动设计实践案例
-
学习 Robot Framework IDE 的一些感受
-
使用Robot Framework Support插件在pycharm中运行robotframework用例