一、环境准备
1.jdk1.8 2.python:3.7.8 3.Appium Inspector 4.Appium Service 桌面版 5.Node.js 6.android-sdk 7. Appium-Python-Client 安装 Appium-Python-Client:pip install Appium-Python-Client
下载链接:https://pan.baidu.com/s/1n4XOdfGrUckBOIJY3EZ9Ew 提取码:k6o5
二、配置环境变量
配置java python node 安卓sdk的环境变量 安卓sdk配置platform-tools下的环境变量
三、实战演示
1.启动Appium Service 2.使用数据线连接手机(手机开启调试模式) 3.若没有配置环境变量JAVA_HOME和ANDROID_HOME,可编辑配置,如下图所示 使用Appium-Python-Client 去连接Appium server
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
desired_caps = {
'platformName': 'Android',
'platformVersion': '12',
'deviceName': 'cangfengtest',
'appPackage': 'com.tencent.mm',
'appActivity': 'ui.LauncherUI',
'unicodeKeyboard': True,
'resetKeyboard': True,
'noReset': True,
'newCommandTimeout': 6000,
'automationName': 'UiAutomator2'
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(3)
element=driver.find_element(By.ID,"com.tencent.mm:id/hga")
print(element)
element.click()
辅助定位元素工具:Appium Inspector
1.连接参数配置 远程主机:127.0.0.1 远程端口: 4723 远程路径:/wd/hub JSON Representation:
{
"platformName": "Android",
"deviceName": "cangfengtest",
"appPackage": "com.tencent.wework",
"appActivity": "launch.LaunchSplashActivity",
"unicodeKeyboard": true,
"resetKeyboard": true,
"noReset": true,
"newCommandTimeout": 6000,
"automationName": "UiAutomator2"
}
|