1.数据线连接电脑和手机;
2.用adb获取手机的UUID:cmd-> adb devices
前面的就是你手机的UUID
3.打开appium,选择手机的安卓版本(关于手机中查看),填写手机的UUID,如下图
4.点击右上角的三角,运行显示下图,即为成功
5.运行Python脚本 cmd ->python app.py,如下
#! /usr/bin/env python # coding=utf-8 import os import time import unittest from selenium import webdriver from lib2to3.pgen2.driver import Driver from lib2to3.tests.support import driver PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p)) desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '5.1.1' desired_caps['deviceName'] = '760BBKR228X2' desired_caps['app'] = PATH('D:\\zsfile\\xyk.apk') # 如果设置的是app在电脑上的路径,则不需要配appPackage和appActivity,同理反之 # 启动app driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) driver.quit()
6.运行成功。
遇到的问题,及解决方法:
1.报错:selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Original error: Screen did not unlock);
解决方法:先停止appium,设置-勾选“override existing session”,点击启动服务,问题解决;
2.错误:error: cannot connect to daemon: cannot connect to 127.0.0.1:5037: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 (10060)
解决方法:cmd->adb kill-server cmd->adb start-server
C:\Users\Administrator>adb kill-server C:\Users\Administrator>adb start-server adb server version (31) doesn't match this client (36); killing... * daemon started successfully * C:\Users\Administrator>
在启动服务,解决;