协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
appium【开发与工程】Appium is an open-source framework that automates native, hybrid and mobile-web apps on iOS and Android through the WebDriver protocol. Use when the user wants to set up Appium 3, write mobile UI tests in JavaScript (WebdriverIO) or Python, pick capabilities, run gestures, or fix "appium", "XCUITest", "UiAutomator2", "mobile automation" problems. For…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Appium is a server that exposes the W3C WebDriver protocol for mobile apps. Test scripts (WebdriverIO, Python, Java, Ruby, .NET) send commands to the server, and a platform driver carries them out: UiAutomator2 for Android and XCUITest for iOS (iOS needs macOS and Xcode). Appium 3 is the current major version (3.8 at the time of writing); it needs Node.js 20.19+ or 22.12+ and npm 10+, speaks only W3C commands, and ships no drivers, so you install them separately.
npm install -g appium # the only supported install route
appium driver install uiautomator2 # Android
appium driver install xcuitest # iOS (macOS only)
appium driver list --installed
# Environment checks. The standalone appium-doctor package is deprecated;
# use the doctor built into each driver:
appium driver doctor uiautomator2
appium driver doctor xcuitest
appium # listens on http://127.0.0.1:4723
Android needs ANDROID_HOME pointing at the SDK and adb on the PATH. Appium 3 requires driver-scoped insecure features, e.g. appium --allow-insecure=uiautomator2:adb_shell (*:adb_shell applies to all drivers).
Every non-standard key carries the appium: prefix. deviceName does not pick a device on Android: select one with appium:udid (real device), appium:avd (emulator to boot) or appium:platformVersion (auto-detect).
// capabilities.js
export const androidCaps = {
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:avd': 'Pixel_7_API_34',
'appium:app': '/Users/dana/projects/shop-app/app/build/outputs/apk/debug/app-debug.apk',
'appium:autoGrantPermissions': true,
'appium:newCommandTimeout': 240,
};
export const iosCaps = {
platformName: 'iOS',
'appium:automationName': 'XCUITest',
'appium:deviceName': 'iPhone 15',
'appium:platformVersion': '17.5',
'appium:app': '/Users/dana/projects/shop-app/build/ShopApp.app',
'appium:autoAcceptAlerts': true,
};
npm install --save-dev webdriverio @wdio/cli @wdio/appium-service @wdio/mocha-framework
// wdio.conf.js
export const config = {
runner: 'local',
specs: ['./tests/**/*.spec.js'],
capabilities: [{
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:avd': 'Pixel_7_API_34',
'appium:app': './app/build/outputs/apk/debug/app-debug.apk',
}],
framework: 'mocha',
mochaOpts: { timeout: 60000 },
services: ['appium'], // starts the globally installed Appium server on port 4723
};
Run with npx wdio run wdio.conf.js. In WebdriverIO, $('~login-button') finds by accessibility id (content-desc on Android, accessibility identifier on iOS).
Prefer the driver's mobile: commands over legacy TouchAction. The UiAutomator2 set includes clickGesture, longClickGesture, doubleClickGesture, dragGesture, flingGesture, swipeGesture, scrollGesture, pinchOpenGesture, pinchCloseGesture. XCUITest has mobile: swipe, mobile: scroll, mobile: touchAndHold, mobile: pinch and others (see the driver docs).
Request: "Write an Appium test that logs into my Android shopping app and checks the welcome text."
// tests/login.spec.js
describe('Login screen', () => {
it('logs in with valid credentials', async () => {
await $('~email-input').setValue('dana.ortiz@shopmail.dev');
await $('~password-input').setValue(process.env.SHOP_TEST_PASSWORD);
await $('~login-button').click();
const welcome = await $('~welcome-message');
await welcome.waitForDisplayed({ timeout: 10000 });
await expect(welcome).toHaveText('Welcome back, Dana');
});
});
Run appium in one terminal (or rely on the appium service) and npx wdio run wdio.conf.js. The emulator boots, the APK installs, and Mocha reports 1 passing.
Request: "Python version: add an item, scroll the list, and assert it is listed."
# tests/test_items.py
import pytest
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
@pytest.fixture
def driver():
options = UiAutomator2Options()
options.platform_name = "Android"
options.avd = "Pixel_7_API_34"
options.app = "./app-debug.apk"
d = webdriver.Remote("http://127.0.0.1:4723", options=options)
yield d
d.quit()
def test_add_item(driver):
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, "add-item"))).click()
driver.find_element(AppiumBy.ACCESSIBILITY_ID, "item-name").send_keys("Oat milk 1L")
driver.find_element(AppiumBy.ACCESSIBILITY_ID, "save-button").click()
driver.execute_script("mobile: scrollGesture", {
"left": 100, "top": 500, "width": 200, "height": 600,
"direction": "down", "percent": 1.0,
})
assert wait.until(
EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, "item-Oat milk 1L"))
).is_displayed()
Install with pip install Appium-Python-Client pytest (client 6.x, Python 3.10+). UiAutomator2Options replaced the removed desired_capabilities argument.
appium driver update uiautomator2, not by reinstalling Appium.appium: prefix on a custom capability is the most common "invalid capabilities" error.-android uiautomator locators are on Google's deprecation path.waitForDisplayed, WebDriverWait) instead of sleeps.mobile: execute commands.