robotframework-appium-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAppiumLibrary Skill for Robot Framework
适用于Robot Framework的AppiumLibrary Skill
Quick Reference
快速参考
AppiumLibrary enables mobile app testing on iOS and Android using Appium automation.
AppiumLibrary 借助Appium自动化技术,支持在iOS和Android平台上进行移动应用测试。
Installation
安装
bash
undefinedbash
undefinedInstall the library
Install the library
pip install robotframework-appiumlibrary
pip install robotframework-appiumlibrary
Install Appium server (requires Node.js)
Install Appium server (requires Node.js)
npm install -g appium
npm install -g appium
Install platform drivers
Install platform drivers
appium driver install uiautomator2 # Android
appium driver install xcuitest # iOS
undefinedappium driver install uiautomator2 # Android
appium driver install xcuitest # iOS
undefinedAppium Server
Appium 服务器
Appium server must be running before tests:
bash
appium # Start with defaults
appium server # Alternative
appium --port 4724 # Custom portDefault URL:
http://127.0.0.1:4723在运行测试前必须启动Appium服务器:
bash
appium # Start with defaults
appium server # Alternative
appium --port 4724 # Custom port默认URL:
http://127.0.0.1:4723Library Import
库导入
robotframework
*** Settings ***
Library AppiumLibraryrobotframework
*** Settings ***
Library AppiumLibraryAndroid Quick Start
Android 快速入门
Open Android App
打开Android应用
robotframework
Open Application http://127.0.0.1:4723
... platformName=Android
... platformVersion=13
... deviceName=emulator-5554
... automationName=UiAutomator2
... app=${CURDIR}/app.apkrobotframework
Open Application http://127.0.0.1:4723
... platformName=Android
... platformVersion=13
... deviceName=emulator-5554
... automationName=UiAutomator2
... app=${CURDIR}/app.apkAndroid Locators (Priority Order)
Android 定位器(优先级顺序)
robotframework
undefinedrobotframework
undefined1. accessibility_id (RECOMMENDED - stable)
1. accessibility_id (RECOMMENDED - stable)
Click Element accessibility_id=login_button
Click Element accessibility_id=login_button
2. id (resource-id)
2. id (resource-id)
Click Element id=com.example:id/login_button
Click Element id=login_button # Short form if unique
Click Element id=com.example:id/login_button
Click Element id=login_button # Short form if unique
3. xpath
3. xpath
Click Element xpath=//android.widget.Button[@text='Login']
Click Element xpath=//android.widget.Button[@text='Login']
4. android UIAutomator2 selector
4. android UIAutomator2 selector
Click Element android=new UiSelector().text("Login")
Click Element android=new UiSelector().text("Login")
5. class name
5. class name
Click Element class=android.widget.Button
undefinedClick Element class=android.widget.Button
undefinediOS Quick Start
iOS 快速入门
Open iOS App
打开iOS应用
robotframework
Open Application http://127.0.0.1:4723
... platformName=iOS
... platformVersion=17.0
... deviceName=iPhone 15
... automationName=XCUITest
... app=${CURDIR}/MyApp.app
... udid=auto # For real devicesrobotframework
Open Application http://127.0.0.1:4723
... platformName=iOS
... platformVersion=17.0
... deviceName=iPhone 15
... automationName=XCUITest
... app=${CURDIR}/MyApp.app
... udid=auto # For real devicesiOS Locators (Priority Order)
iOS 定位器(优先级顺序)
robotframework
undefinedrobotframework
undefined1. accessibility_id (RECOMMENDED - stable)
1. accessibility_id (RECOMMENDED - stable)
Click Element accessibility_id=loginButton
Click Element accessibility_id=loginButton
2. name
2. name
Click Element name=Login
Click Element name=Login
3. ios predicate string
3. ios predicate string
Click Element ios=type == 'XCUIElementTypeButton' AND name == 'Login'
Click Element ios=type == 'XCUIElementTypeButton' AND name == 'Login'
4. ios class chain (fast) - NOTE: use chain= prefix for class chains
4. ios class chain (fast) - NOTE: use chain= prefix for class chains
Click Element chain=**/XCUIElementTypeButton[]
name == 'Login'Click Element chain=**/XCUIElementTypeButton[]
name == 'Login'5. xpath
5. xpath
Click Element xpath=//XCUIElementTypeButton[@name='Login']
Click Element xpath=//XCUIElementTypeButton[@name='Login']
6. class name
6. class name
Click Element class=XCUIElementTypeButton
undefinedClick Element class=XCUIElementTypeButton
undefinedEssential Keywords
核心关键字
Element Interaction
元素交互
robotframework
Click Element locator
Click Text visible_text
Input Text locator text_to_enter
Clear Text locator
Tap locator duration=0:00:01 # Long press (replaces removed Long Press)robotframework
Click Element locator
Click Text visible_text
Input Text locator text_to_enter
Clear Text locator
Tap locator duration=0:00:01 # Long press (replaces removed Long Press)Getting Element Content
获取元素内容
robotframework
${text}= Get Text locator
${attr}= Get Element Attribute locator attribute_name
${count}= Get Matching Xpath Count //android.widget.Buttonrobotframework
${text}= Get Text locator
${attr}= Get Element Attribute locator attribute_name
${count}= Get Matching Xpath Count //android.widget.ButtonWaits
等待操作
robotframework
Wait Until Element Is Visible locator timeout=10s
Wait Until Page Contains text timeout=10s
Wait Until Page Contains Element locator timeout=10srobotframework
Wait Until Element Is Visible locator timeout=10s
Wait Until Page Contains text timeout=10s
Wait Until Page Contains Element locator timeout=10sVerification
验证操作
robotframework
Element Should Be Visible locator
Element Should Be Enabled locator
Page Should Contain Text expected_text
Page Should Contain Element locator
Element Text Should Be locator expected_textrobotframework
Element Should Be Visible locator
Element Should Be Enabled locator
Page Should Contain Text expected_text
Page Should Contain Element locator
Element Text Should Be locator expected_textScreenshots
截图
robotframework
Capture Page Screenshot filename.png
Capture Page Screenshot ${OUTPUT_DIR}/screenshots/screen.pngrobotframework
Capture Page Screenshot filename.png
Capture Page Screenshot ${OUTPUT_DIR}/screenshots/screen.pngGet Page Source (View Hierarchy)
获取页面源码(视图层级)
Useful for finding locators and debugging:
robotframework
${source}= Get Source
Log ${source}该功能有助于查找定位器和调试:
robotframework
${source}= Get Source
Log ${source}Basic Gestures
基础手势操作
robotframework
undefinedrobotframework
undefinedScroll (locator is the element to scroll to/within)
Scroll (locator is the element to scroll to/within)
Scroll Down locator
Scroll Up locator
Scroll Down locator
Scroll Up locator
Swipe (start_x, start_y, end_x, end_y, duration as timedelta)
Swipe (start_x, start_y, end_x, end_y, duration as timedelta)
Swipe start_x=500 start_y=1500 end_x=500 end_y=500 duration=0:00:01 # Swipe up
Swipe start_x=500 start_y=1500 end_x=500 end_y=500 duration=0:00:01 # Swipe up
Long press (use Tap with duration; Long Press was removed in v3.2.0)
Long press (use Tap with duration; Long Press was removed in v3.2.0)
Tap locator duration=0:00:02
Tap locator duration=0:00:02
Tap at coordinates
Tap at coordinates
Tap With Positions 500 800
undefinedTap With Positions 500 800
undefinedAndroid Scroll to Element (UIAutomator2)
Android 滚动到元素(UIAutomator2)
robotframework
undefinedrobotframework
undefinedAutomatically scrolls to find element!
Automatically scrolls to find element!
Click Element android=new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text("Settings"))
undefinedClick Element android=new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text("Settings"))
undefinedContext Switching (Hybrid Apps)
上下文切换(混合应用)
robotframework
undefinedrobotframework
undefinedCheck current context
Check current context
${context}= Get Current Context
Log Current: ${context}
${context}= Get Current Context
Log Current: ${context}
List all contexts
List all contexts
@{contexts}= Get Contexts
Log Many @{contexts}
@{contexts}= Get Contexts
Log Many @{contexts}
Switch to webview
Switch to webview
Switch To Context WEBVIEW_com.example.app
Switch To Context WEBVIEW_com.example.app
Switch back to native
Switch back to native
Switch To Context NATIVE_APP
undefinedSwitch To Context NATIVE_APP
undefinedMobile Browser Testing
移动浏览器测试
Android Chrome
Android Chrome
robotframework
Open Application http://127.0.0.1:4723
... platformName=Android
... deviceName=emulator-5554
... automationName=UiAutomator2
... browserName=Chrome
Go To Url https://example.com
Input Text id=username admin
Click Element css=button[type='submit']robotframework
Open Application http://127.0.0.1:4723
... platformName=Android
... deviceName=emulator-5554
... automationName=UiAutomator2
... browserName=Chrome
Go To Url https://example.com
Input Text id=username admin
Click Element css=button[type='submit']iOS Safari
iOS Safari
robotframework
Open Application http://127.0.0.1:4723
... platformName=iOS
... deviceName=iPhone 15
... automationName=XCUITest
... browserName=Safari
Go To Url https://example.comrobotframework
Open Application http://127.0.0.1:4723
... platformName=iOS
... deviceName=iPhone 15
... automationName=XCUITest
... browserName=Safari
Go To Url https://example.comSession Management
会话管理
robotframework
undefinedrobotframework
undefinedClose app and end session
Close app and end session
Close Application
Close Application
Background/foreground
Background/foreground
Background Application 5 # Background for 5 seconds
Background Application 5 # Background for 5 seconds
NOTE: Quit Application was removed in v3.0.0 - use Close Application instead
NOTE: Quit Application was removed in v3.0.0 - use Close Application instead
NOTE: Reset Application was removed in v3.2.0 - use Close Application + Open Application instead
NOTE: Reset Application was removed in v3.2.0 - use Close Application + Open Application instead
undefinedundefinedW3C Capabilities Format (Appium 2.x)
W3C 能力配置格式(Appium 2.x)
Appium 2.x uses W3C capabilities with the vendor prefix for non-standard capabilities:
appium:robotframework
Open Application http://127.0.0.1:4723
... platformName=Android
... appium:automationName=UiAutomator2
... appium:app=/path/to/app.apk
... appium:deviceName=emulator-5554
... appium:autoGrantPermissions=trueOnly is standard W3C. All other Appium-specific capabilities need the prefix.
AppiumLibrary will typically add the prefix automatically, but explicitly using it is recommended for clarity.
platformNameappium:Appium 2.x 使用带厂商前缀的W3C能力配置来标识非标准能力:
appium:robotframework
Open Application http://127.0.0.1:4723
... platformName=Android
... appium:automationName=UiAutomator2
... appium:app=/path/to/app.apk
... appium:deviceName=emulator-5554
... appium:autoGrantPermissions=true只有是标准W3C能力。所有其他Appium专属能力都需要添加前缀。
AppiumLibrary通常会自动添加该前缀,但为了清晰起见,建议显式使用。
platformNameappium:Cloud Testing (BrowserStack / Sauce Labs)
云测试(BrowserStack / Sauce Labs)
BrowserStack
BrowserStack
robotframework
Open Application http://hub-cloud.browserstack.com/wd/hub
... platformName=Android
... appium:deviceName=Google Pixel 7
... appium:platformVersion=13.0
... appium:app=bs://your_app_hash
... bstack:options={"userName": "${BS_USERNAME}", "accessKey": "${BS_ACCESS_KEY}"}robotframework
Open Application http://hub-cloud.browserstack.com/wd/hub
... platformName=Android
... appium:deviceName=Google Pixel 7
... appium:platformVersion=13.0
... appium:app=bs://your_app_hash
... bstack:options={"userName": "${BS_USERNAME}", "accessKey": "${BS_ACCESS_KEY}"}Sauce Labs
Sauce Labs
robotframework
Open Application https://ondemand.us-west-1.saucelabs.com:443/wd/hub
... platformName=iOS
... appium:deviceName=iPhone 14
... appium:platformVersion=16
... appium:app=storage:filename=MyApp.ipa
... sauce:options={"username": "${SAUCE_USERNAME}", "accessKey": "${SAUCE_ACCESS_KEY}"}robotframework
Open Application https://ondemand.us-west-1.saucelabs.com:443/wd/hub
... platformName=iOS
... appium:deviceName=iPhone 14
... appium:platformVersion=16
... appium:app=storage:filename=MyApp.ipa
... sauce:options={"username": "${SAUCE_USERNAME}", "accessKey": "${SAUCE_ACCESS_KEY}"}Removed Keywords and Alternatives
已移除的关键字及替代方案
Several keywords were removed in AppiumLibrary v3.x:
| Removed Keyword | Version Removed | Alternative |
|---|---|---|
| v3.2.0 | |
| v3.0.0 | |
| v3.2.0 | Use W3C Actions via Execute Script |
| v3.0.0 | Use W3C Actions via Execute Script |
| v3.2.0 | |
| v3.0.0 | |
| v3.0.0 | |
| N/A | |
AppiumLibrary v3.x版本中移除了多个关键字:
| 已移除关键字 | 移除版本 | 替代方案 |
|---|---|---|
| v3.2.0 | |
| v3.0.0 | |
| v3.2.0 | 通过Execute Script使用W3C Actions |
| v3.0.0 | 通过Execute Script使用W3C Actions |
| v3.2.0 | 先执行 |
| v3.0.0 | |
| v3.0.0 | |
| N/A | |
W3C Actions for Zoom/Pinch
用于缩放/捏合的W3C Actions
Zoom and Pinch gestures require W3C Actions in AppiumLibrary v3.x. These can be performed
using multi-touch sequences via the Appium driver directly if needed:
robotframework
undefined在AppiumLibrary v3.x中,缩放和捏合手势需要使用W3C Actions。如果需要,可通过Appium驱动直接执行多点触控序列:
robotframework
undefinedExample: Use Execute Script to perform pinch/zoom via driver
Example: Use Execute Script to perform pinch/zoom via driver
Execute Script mobile: pinchOpen {"elementId": "${element_id}", "percent": 0.75}
undefinedExecute Script mobile: pinchOpen {"elementId": "${element_id}", "percent": 0.75}
undefinedWhen to Load Additional References
何时加载更多参考文档
Reference files for deeper guidance (planned):
<!-- Note: Reference files listed below are planned for future addition -->
| Need | Reference File |
|---|---|
| Android locator strategies | |
| iOS locator strategies | |
| Device capabilities setup | |
| Gestures and scrolling | |
| iOS-specific features | |
| Android-specific features | |
| Complete keyword list | |
| Common issues and solutions | |
以下是用于深入指导的参考文件(规划中):
<!-- Note: Reference files listed below are planned for future addition -->
| 需求 | 参考文件 |
|---|---|
| Android定位器策略 | |
| iOS定位器策略 | |
| 设备能力配置 | |
| 手势与滚动操作 | |
| iOS专属功能 | |
| Android专属功能 | |
| 完整关键字列表 | |
| 常见问题与解决方案 | |