appium解锁android真机系统的屏幕

在使用appium进行app自动化操作的过程中,经常遇到的第一个难题就是如何解锁系统屏幕,也就是亮屏解锁。

实际上解决办法如下:在desired_capabilities中增加两个参数unlockType和unlockKey,类似的示例代码如下:

desired_caps={}

desired_caps['platformName']='Android'

desired_caps['platformVersion']='8.0.0'

desired_caps['deviceName']='WG5T16A18019'

desired_caps['appPackage']='com.xxxx'

desired_caps['appActivity']='com.xxxx.ui.SplashActivity'

desired_caps['autoGrantPermissions']=True
desired_caps['unlockType']="password"
desired_caps['unlockKey']="111111"

其中的unlockType可以设置为:pin,password,pattern,fingerprint当中的一个,顾名思义,分别对应pin,密码,手势解锁以及指纹解锁四种方式。

而unlockKey则为具体值,例如password即为实际的解锁口令,而pattern模式下则为手势解锁的滑动过程,如下图所示,则应设置为5416或者是6145(取决于滑动顺序)

复制代码
__author__ = 'Jeff.xie'
from appium import webdriver
# coding:utf-8
from time import sleep

from appium.webdriver.common.multi_action import MultiAction
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from appium.webdriver.common.appiumby import AppiumBy
desired_caps = {}

desired_caps['platformName'] = 'Android'
# desired_caps['platformVersion'] = '11'
# desired_caps['deviceName'] = 'RFCNA0DREDX'
desired_caps['platformVersion'] = '11'
desired_caps['deviceName'] = '9b2157cfaedb'
desired_caps['appPackage'] = 'xxxxxxxxx'
desired_caps['appActivity'] = 'xxxxxxxxx'
desired_caps\['unlockType'\] = 'password'
desired_caps\['unlockKey'\] = '1234'
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)
# driver.set_location(12, 123, 10)  #设置经度,纬度,海拔
print(driver.location)

# Java
# driver.setLocation(new Location(49, 123, 10)); // Must be a driver that implements LocationContext
# 参考文档
# https://appium.readthedocs.io/en/stable/en/commands/session/geolocation/set-geolocation/#example-usage

sleep(10)

# driver.find_element(By.XPATH,"//android.widget.TextView[@text='登入']").click()
# driver.find_element_by_android_uiautomator('new UiSelector().text("登入")').click() # 不可用
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("登入")').click()  # 可用
sleep(1)
# driver.find_element(By.XPATH,"//android.widget.TextView[@text='用戶名稱']").click()
sleep(1)
driver.find_element(By.XPATH,'//android.widget.EditText[@content-desc="username-input"]').send_keys('contester0042')
sleep(1)
driver.find_element(By.XPATH,"//android.widget.TextView[@text='密碼']").click()
sleep(1)
driver.find_element(By.XPATH,'//android.widget.EditText[@content-desc="password-input"]').send_keys('Aa123321')
# driver.find_element(By.XPATH,'//android.widget.EditText[@content-desc="password-input"]').send_keys(Keys.ENTER)
driver.hide_keyboard()
sleep(1)
driver.find_element(By.XPATH,"//android.widget.TextView[@text='登入']").click()
sleep(10)
相关推荐
MJH82711 天前
JMeter全流程性能测试实战!
自动化测试·功能测试·jmeter·单元测试·appium·性能测试·测试工程师
Lossya12 天前
【自动化测试】Appium Server如何安装和Appium Server安装困难的原因和解决方法以及常见的一些安装失败的错误和解决方法
自动化测试·测试工具·npm·node.js·appium·自动化
Lossya12 天前
【自动化测试】Appium 生态工具以及Appium Desktop如何安装和使用
自动化测试·测试工具·ui·appium·自动化
一禅(OneZen)12 天前
【L1.第六章】Appium 如何定位与页面等待实战
python·selenium·uni-app·appium·自动化·web
小码哥说测试13 天前
Postman如何测试WebSocket接口!
自动化测试·软件测试·websocket·selenium·测试工具·appium·postman
kingapex115 天前
Appium高级话题:混合应用与原生应用测试策略
自动化测试·appium
Lossya16 天前
【自动化测试】UI自动化的分类、如何选择合适的自动化测试工具以及其中appium的设计理念、引擎和引擎如何工作
自动化测试·测试工具·ui·appium·自动化
嗯诺17 天前
黑马头条APP手工测试项目
appium
测试界吖吖18 天前
软件测试 | APP测试 —— Appium 的环境搭建及工具安装教程
自动化测试·软件测试·功能测试·程序人生·职场和发展·appium
Coco(学习)1 个月前
Wimdows使用Appium IOS自动化
运维·appium·自动化