霍格沃兹测试学院 2018年08月11日 Appium

思寒_seveniruby · August 11, 2018 · Last by jiarui replied at August 17, 2018 · 1769 hits

打开uiautomatorviewer: uiautomatorviewer
uiautomator api: https://developer.android.com/reference/android/support/test/uiautomator/UiScrollable
app:https://m.hujiang.com/ar_ANDROID_69/?source=PC
chromedriver下载路径: https://chromedriver.storage.googleapis.com/index.html
chrome remote debug: https://www.girish.in/how-remote-debugging-works-in-chrome/

chrome版本对应:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md

adb forward tcp:4000 localabstract:webview_devtools_remote_23323
def test_scrollable(self):
# 测试如何使用uiautomator查询列表中的元素
self.driver.find_element_by_accessibility_id('Graphics').click()
ua_scroll = 'new UiScrollable(new UiSelector().className("android.widget.ListView")).scrollIntoView(new UiSelector().text("UnicodeChart"))'
self.driver.find_element_by_android_uiautomator(ua_scroll).click()
sleep(5)

微信小程序
获取小程序进程

adb shell dumpsys activity top | grep ACTIVITY
adb shell ps {端口号}
com.tencent.mm:appbrand0
'appPackage': 'com.tencent.mm'
'
appActivity': 'com.tencent.mm.ui.LauncherUI'

作业1:
一个appium自动化过程中,ADB做了哪些事情,并且把相关的命令截取出来;

作业2:
利用uiscrollable编写一个脚本,并实现一个自定义手势;

作业3:
基于沪江学习编写webview自动化脚本;

附加作业:
利用python实现一个Appiumserver的启动和关闭;

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 4 条回复 时间 点赞
阿廉 上海测试开发全天班 (一期) 汇总贴 中提及了此贴 12 Aug 15:09

作业1:

  • 打印出指定设备中的应用包【adb shell pm list packages 】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell pm list packages io.appium.android.apis'
  • 等待指定设备连接电脑【adb wait-for-device】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 wait-for-device'
  • 进入指定设备并打印ping [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell echo ping'
  • 获取指定设备中已安装的指定应用包的信息【adb shell dumpsys package】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell dumpsys package io.appium.settings'
  • 获取指定设备中的进程【adb shell ps】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell ps'
  • 获取指定设备的系统属性--系统sdk版本【adb shell getprop 】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell getprop ro.build.version.sdk'
  • 在指定设备上给予io.appium.settings模拟位置信息的权限 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell appops set io.appium.settings android\:mock_location allow'
  • 在指定设备上安装apk文件【adb install】 [debug][ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 install 'C:\\ProgramFiles(x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-android-ime\\bin\\UnicodeIME-debug.apk''
  • 获取指定设备上的默认输入法【adb shell settings get secure default_inpput_method】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell settings get secure default_input_method'
  • 在指定设备上确定对应输入法可用【adb shell ime enable】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell ime enable io.appium.android.ime/.UnicodeIME'
  • 在指定设备上更改默认输入法【adb shell ime set】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell ime set io.appium.android.ime/.UnicodeIME'
  • 获取指定设备的屏幕分辨率【adb shell wm size】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell wm size'
  • PC端所有4724端口的数据将被重定向到手机端4724端口server上【adb forward xx xx】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 forward tcp\:4724 tcp\:4724'
  • 将PC端的数据传输到手机指定目录【adb push】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 push 'C:\\ProgramFiles(x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-android-bootstrap\\bootstrap\\bin\\AppiumBootstrap.jar' /data/local/tmp/'
  • 在指定设备启动某个APP【adb shell am start】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell am start -W -n io.appium.android.apis/io.appium.android.apis.ApiDemos -S'
  • 在指定设备关闭指定包名的应用程序【adb shell am force-stop】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell am force-stop io.appium.android.apis'
  • 模拟点击设备的Home键【adb shell input keyevent code】 [debug] [ADB] Running 'D:\Android\sdk\platform-tools\adb.exe -P 5037 -s 30607a42 shell input keyevent 3'

作业2

def test_touch(self):
# 画一个“2
self.driver.find_element_by_accessibility_id("Graphics").click()
ui_scrollable = 'new UiScrollable(new UiSelector().className("android.widget.ListView")).' \
'scrollIntoView(new UiSelector().text("Touch Paint"))'
self.driver.find_element_by_android_uiautomator(ui_scrollable).click()
sleep(2)
action = TouchAction(self.driver)
height = self.driver.get_window_size()['height']
width = self.driver.get_window_size()['width']
action.press(x=0.3*width, y=0.1*height).wait(1000).move_to(x=0.7*width, y=0.1*height).\
wait(1000).move_to(x=0.7*width, y=0.5*height).wait(1000).move_to(x=0.3*width, y=0.5*height).\
wait(1000).move_to(x=0.3*width, y=0.9*height).wait(1000).move_to(x=0.7*width, y=0.9*height).release()
action.perform()
sleep(2)

作业3

def test_hj(self):
self.driver.find_element_by_xpath(u'//*[@text="登录"]').click()
edit_text_list = self.driver.find_elements_by_class_name('android.widget.EditText')
# 由于沪江APP,在输错多次后,会出现验证码按钮,所以先判断对应输入框的个数
if len(edit_text_list) > 2:
edit_text_list[0].send_keys('username')
edit_text_list[1].send_keys('password')
edit_text_list[2].send_keys('123123')
self.driver.find_element_by_xpath(u'//*[@text="登录"]').click()
try:
view = self.driver.find_elements_by_xpath(u'//*[@text="图片验证码输入错误"]')
print(view[0].text)
self.assertEqual(view[0].text, "图片验证码输入错误", "验证码输入错误,提示正确")
except Exception as error:
print("未找到对应提示")
raise error
else:
edit_text_list[0].send_keys('username')
edit_text_list[1].send_keys('password')
self.driver.find_element_by_xpath(u'//*[@text="登录"]').click()
toast = self.driver.find_element_by_xpath('//android.widget.Toast') # 通过uiautomator2进行获取toast提示
self.assertEqual(toast.text, '用户名或密码错误,您可使用手机快速登录', "用户名以及密码输错,提示正确")

作业1
1、连接设备

adb devices
#查询设备,生成已连接的模拟器/设备的列表

adb -P 5037 -s e3bdd2dc wait-for-device
#等待设备处于在线状态,即直至此实例状态为 device

adb -P 5037 -s e3bdd2dc shell echo ping
#测试网络

2、安装io.appium.settings

adb -P 5037 -s e3bdd2dc shell pm list packages io.appium.settings
#调用软件包管理器 (pm),获取包名称包含io.appium.settings的软件包,以检查io.appium.settings是否安装

adb -P 5037 -s e3bdd2dc shell dumpsys package io.appium.settings
#获取io.appium.settings的包信息

adb -P 5037 -s e3bdd2dc shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000
#启动io.appium.settings,调用 Activity Manager (am)启动Settings -W:等待启动完成,-n component:指定带有软件包名称前缀的组件名称以创建显式 intent-a action:指定 intent 操作,-c category:指定 intent 类别,-f flags:将标志添加到 setFlags() 支持的 intent

adb -P 5037 -s e3bdd2dc shell appops set io.appium.settings android\:mock_location allow
#允许mock_location?没明白

adb -P 5037 -s e3bdd2dc shell ps
#打印进程状态

3、获取设备信息

adb -P 5037 -s e3bdd2dc shell getprop ro.build.version.sdk
#获取Android SDK版本号

adb -P 5037 -s e3bdd2dc shell getprop ro.build.version.release
#获取Android 系统版本号

adb -P 5037 -s e3bdd2dc shell wm size
#获取屏幕分辨率

adb -P 5037 -s e3bdd2dc shell getprop ro.product.model
#获取设备/模拟器的机型

adb -P 5037 -s e3bdd2dc shell getprop ro.product.manufacturer
#获取设备/模拟器的厂商

4、检查aapt是否安装

aapt
#检查aapt是否安装,aapt用于编译打包资源

5、安装io.appium.unlock

adb -P 5037 -s e3bdd2dc shell pm list packages io.appium.unlock
#检查io.appium.unlock是否安装

adb -P 5037 -s e3bdd2dc shell dumpsys package io.appium.unlock
#获取io.appium.unlock的包信息

6、安装应用apk

Starting '/Users/zqq/Library/Android/sdk/tools/bin/apkanalyzer' with args ["-h","manifest","print","/Users/zqq/Downloads/normandy_hjpc.apk"]
#调用apk分析工具(apkanalyzer),打印apkmainfest信息

adb -P 5037 -s e3bdd2dc shell pm list packages com.hujiang.normandy
#检查沪江app是否安装

adb -P 5037 -s e3bdd2dc shell dumpsys package com.hujiang.normandy
#获取com.hujiang.normandy的包信息

adb -P 5037 -s e3bdd2dc shell rm -rf /data/local/tmp/strings.json
#删除模拟器/设备中的/data/local/tmp/strings.json

adb -P 5037 -s e3bdd2dc push /var/folders/wc/htlq9bx94f9_2y984580nw8c0000gn/T/com.hujiang.normandy/strings.json /data/local/tmp
#将strings.json文件复制到模拟器/设备

adb -P 5037 -s e3bdd2dc shell am start -W -n com.hujiang.normandy/com.hujiang.normandy.SplashActivity -S
#启动沪江app,调用 Activity Manager (am)启动SplashActivity-W:等待启动完成,-S:启动 Activity 前强行停止目标应用

7、设置端口转发

adb -P 5037 -s e3bdd2dc forward tcp\:4724 tcp\:4724
#设置端口转发,将对特定主机端口的请求转发到模拟器/设备实例上的其他端口

8、启动Bootstrap.jar

adb -P 5037 -s e3bdd2dc push /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp
#将AppiumBootstrap.jar文件复制到模拟器/设备

Creating ADB subprocess with args: ["-P",5037,"-s","e3bdd2dc","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.hujiang.normandy","-e","disableAndroidWatchers",false,"-e","acceptSsl"]
#启动Bootstrap

9、其他

adb -P 5037 -s e3bdd2dc shell dumpsys window
#获取window信息?没明白

adb -P 5037 -s e3bdd2dc shell dumpsys window windows
#获取windowwindows的信息?没明白

作业2

# 手势操作
def test_touch_action(self):
self.driver.find_element_by_accessibility_id("Graphics").click()
au_code = 'new UiScrollable(new UiSelector().className("android.widget.ListView"))' \
'.scrollIntoView(new UiSelector().text("Touch Paint"))'
self.driver.find_element_by_android_uiautomator(au_code).click()
sleep(3)
action = TouchAction(self.driver)
action.press(x=0.3, y=0.3).wait(ms=2000)\
.move_to(x=0.8, y=0.3).wait(ms=2000)\
.move_to(x=0.8, y=0.8).wait(ms=2000)\
.move_to(x=0.3, y=0.8)\
.release().perform()
sleep(5)

作业3

def my_swith_to(self, context_type):
for context in self.driver.contexts:
if context_type in context.lower():
self.driver.switch_to.context(context)
break

# 测试沪江登录
def test_hj(self):
self.driver.find_element_by_xpath(u'//*[@text="登录"]').click()

self.my_swith_to('webview')
self.driver.find_element_by_xpath('//*[@id="hp-login-normal"]/div[1]/input').clear().send_keys('ujydim')
self.driver.find_element_by_xpath('//*[@id="hp-login-normal"]/div[3]/input').clear().send_keys('Aa123456')

self.my_swith_to('native')
self.driver.find_element_by_xpath(u'//*[@text="登录"]').click()

try:
self.driver.find_element_by_xpath(u'//*[@text="ujydim"]')
print("登录成功")
except Exception as ec:
print("登录失败")
print(format(ec))

作业1

#等待设备onlineadb wai-for-device,-P:post,-s:serialno
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 wait-for-device'
#打印ping状态
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell echo ping'
#检查是否安装appium setting 应用(adb shell pm list packages)
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell pm list packages io.appium.settings'
#获取出appium setting应用信息(adb shell dumsys package
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell dumpsys package io.appium.settings'
#查看设备进程(adb shell ps
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell ps'
#查看sdk版本号(adb shell getprop获取配置属性)
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell getprop ro.build.version.sdk'
#启动appium settingadb shell am start
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'
#赋予io.appium.settings位置权限(adb shell appops
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell appops set io.appium.settings android\:mock_location allow'
#安装unicodeIME(adb install)
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 install 'C:\\Program Files (x86)\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-android-ime\\bin\\UnicodeIME-debug.apk''
#设置默认输入法为unicodeIME(adb shell setting更改系统设置)
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell settings get secure default_input_method'
#使unicodeIME可用(adb shell ime
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell ime enable io.appium.android.ime/.UnicodeIME'
#设置输入法为unicodeIMEadb shell ime
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell ime set io.appium.android.ime/.UnicodeIME'
#获取屏幕分辨率(adb vm size)
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell wm size'
删除-rf /data/local/tmp/strings.jsonadb shell rm)什么文件?
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell rm -rf /data/local/tmp/strings.json'
#本机文件复制到设备(adb push
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 push C\:\\Users\\71578\\AppData\\Local\\Temp\\com.hujiang.normandy\\strings.json /data/local/tmp'
#本机4724端口映射到设备4724adb forward
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 forward tcp\:4724 tcp\:4724'
#结束io.appium.unlock应用(adb shell am force-stop)
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell am force-stop io.appium.unlock'
#打开文件(adb shell cat)
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell cat /proc/net/unix'

#列出所有设备到本机的端口连接(adb forward --list
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 forward --list'
#移除设备12935端口到本机的连接(adb forward --remove
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 forward --remove tcp\:12935'
"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.17134\"}}}"
#按下Home
[ADB] Running 'D:\Android\Sdk\platform-tools\adb.exe -P 5037 -s VBJDU18425015298 shell input keyevent 3'

作业2
手机无密码状态下,设置为Z图案密码。

# -*- coding:utf-8 -*-

from appium import webdriver
import unittest
from appium.webdriver.common.touch_action import TouchAction
from time import sleep

class PattenTest(unittest.TestCase):
def setUp(self):
caps = {}
caps['platformName'] = 'Android'
caps['deviceName'] = 'huawei'
caps['noReset'] = True
caps['fullReset'] = False
caps['unicodeKeyboard'] = True
caps['resetKeyboard'] = True
caps['appPackage'] = 'com.android.settings' #启动手机设置菜单
caps['appActivity'] = '.HWSettings'

self.driver = webdriver.Remote('http://localhost:4723/wd/hub',caps)
self.driver.implicitly_wait(10)

def tearDown(self):
self.driver.quit()

def test_pattern(self):
“设置锁屏密码为图案Z
auto_scroll = u'new UiScrollable(new UiSelector().className("android.support.v7.widget.RecyclerView"))
.scrollIntoView(new UiSelector().text("安全和隐私"))'#滑动到安全和隐私
self.driver.find_element_by_android_uiautomator(auto_scroll).click()
self.driver.find_element_by_xpath(u'//android.widget.TextView[contains(@text,"锁屏和密码")]').click()
self.driver.find_element_by_xpath(u'//android.widget.TextView[@text="锁屏密码"]').click()
self.driver.find_element_by_android_uiautomator(u'new UiSelector().text("图案密码")').click()

#定义锁屏图案为Z,有时候画第一次会不成功,绘制多了一次,最后点击完成。
# uiautomatorviewer无法获取该页面元素,使用坐标
action = TouchAction(self.driver)
action.press(x=276,y=800).wait(ms=1000).move_to(x=545,y=800).wait(ms=1000).move_to(x=825,y=800)\
.wait(ms=1000).move_to(x=545,y=1077).wait(ms=1000)\
.move_to(x=276,y=1350).wait(ms=1000).move_to(x=545,y=1350).wait(ms=1000).move_to(x=825,y=1350).release().perform()

#再次输入图案Z
action.press(x=276, y=800).wait(ms=1000).move_to(x=545, y=800).wait(ms=1000).move_to(x=825, y=800) \
.wait(ms=1000).move_to(x=545, y=1077).wait(ms=1000) \
.move_to(x=276, y=1350).wait(ms=1000).move_to(x=545, y=1350).wait(ms=1000).move_to(x=825, y=1350).release().perform()

# 再次输入图案Z
action.press(x=276, y=800).wait(ms=1000).move_to(x=545, y=800).wait(ms=1000).move_to(x=825, y=800) \
.wait(ms=1000).move_to(x=545, y=1077).wait(ms=1000) \
.move_to(x=276, y=1350).wait(ms=1000).move_to(x=545, y=1350).wait(ms=1000).move_to(x=825, y=1350).release().perform()

#点击完成
action.tap(x=797,y=2183).perform()

#按back,消除录入指纹弹开
self.driver.press_keycode(4)
sleep(1)

#设置完成后显示图案密码,通过定位判断是否设置成功
try:
self.driver.find_element_by_android_uiautomator(u'new UiSelector().text("图案密码")')
print(u"图案密码设置完成")
except:
print(u"设置图案密码失败")

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(PattenTest)
unittest.TextTestRunner(verbosity=2).run(suite)

作业3

#--*-- conding:utf-8 -*--
from appium import webdriver
from time import sleep
import unittest


class WebviewTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
caps = {}
caps['platformName'] = 'Android'
caps['deviceName'] = 'Hornor 10'
caps['noReset'] = True
caps['fullRest']= False
caps['unicodeKeyboard'] = True
caps['resetKeyboard'] = True
caps['automationName'] = 'uiautomator2' #出现overide
caps['noSign'] = True
caps['app'] = 'D:\\training\\normandy_hjpc.apk'
caps['chromedriverExecutable'] = 'D:\\training\\chromedriver\\chromedriver2.37.exe'
#caps['chromedriverExecutableDir'] = 'D:/training/chromedriver'

cls.driver = webdriver.Remote('http://localhost:4723/wd/hub',caps)
cls.driver.implicitly_wait(10)

@classmethod
def tearDownClass(cls):
cls.driver.quit()

def test_login_inputNull(self):
"测试用户名和密码为空,登录是否有提示"
self.driver.find_element_by_id('com.hujiang.normandy:id/login').click()
self.driver.switch_to.context(self.driver.contexts[1])
self.driver.find_element_by_xpath('//*[@id="hp-login-normal"]/div[1]/input').clear() #用户名为空
self.driver.find_element_by_xpath('//*[@id="hp-login-normal"]/div[3]/input ').clear() #密码为空
self.driver.find_element_by_xpath('//*[@id="hp-login-normal"]/button').click()
try:
self.assertIn(u'不能为空',self.driver.page_source,u'没有提示用户名和密码为空')
except AssertionError as er:
print(format(er))
except Exception as er:
print(format(er))


def test_login_inputError(self):
“测试密码错误时,toast提示是否正确”
self.driver.find_element_by_xpath('//*[@id="hp-login-normal"]/div[1]/input').clear().send_keys('kewei2017') # 用户名
self.driver.find_element_by_xpath('//*[@id="hp-login-normal"]/div[3]/input ').send_keys('12345')
self.driver.find_element_by_xpath('//*[@id="hp-login-normal"]/button').click()
toast = self.driver.find_element_by_xpath('//android.widget.toast')

try:
self.assertEqual(u'用户名和密码错误,您可使用手机快速登录',toast,'没有提示用户名和密码错误')
except AssertionError as er:
print(format(er))
except Exception as er:
print(format(er))


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(WebviewTest)
unittest.TextTestRunner(verbosity=2).run(suite)

作业一

# 尝试获取Android手机连接
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
# 与一个Android设备建立连接,设备IDLGH990d383a057
[debug] [ADB] 1 device(s) connected
[info] [AndroidDriver] Using device: LGH990d383a057
[debug] [ADB] Setting device id to LGH990d383a057
# 获取本地app的地址,并检查app安装包是否存在
[info] [BaseDriver] Using local app '/Users/jiarui/Downloads/ApiDemos-debug.apk'
[debug] [AndroidDriver] Checking whether app is actually present
[info] [AndroidDriver] Starting Android session
# 执行ADB命令:adb -P 5037 -s LGH990d383a057
# 等待deviceidLGH990d383a057的设备联机
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 wait-for-device'
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell echo ping
# ping deviceid为等待deviceidLGH990d383a057的设备
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell echo ping'
# apk的设置信息push到设备
[debug] [AndroidDriver] Pushing settings apk to device...
# 获取安装apk的配置信息
[debug] [ADB] Getting install status for io.appium.settings
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell pm list packages io.appium.settings
# 列出所有io.appium.settings安装包
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell pm list packages io.appium.settings'
# io.appium.settings已经被安装
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.settings'
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell dumpsys package io.appium.settings'
# 获取io.appium.settings的系统信息
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell dumpsys package io.appium.settings'
# 当前安装的io.appium.settings不需要升级
[debug] [ADB] The installed 'io.appium.settings' package does not require upgrade ('2.3.0' >= '2.3.0')
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell ps
# 查看设备的所有进程
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell ps'
# io.appium.settings已经运行起来了,并且不需要重置permission
[debug] [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell getprop ro.build.version.sdk
# 获取设备的属性值ro.build.version.sdk
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell getprop ro.build.version.sdk'
# 当前ro.build.version.sdk的值为24level24
[debug] [ADB] Current device property 'ro.build.version.sdk': 24
[debug] [ADB] Device API level: 24
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell appops set io.appium.settings android\:mock_location allow
# 设置io.appium.settings中的mock_locationallow
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell appops set io.appium.settings android\:mock_location allow'
[warn] [AndroidDriver] setDeviceLanguageCountry requires language or country.
[warn] [AndroidDriver] Got language: 'undefined' and country: 'undefined'
[debug] [Logcat] Starting logcat capture
# 开启unicode键盘
[debug] [AndroidDriver] Enabling Unicode keyboard support
[debug] [AndroidDriver] Pushing unicode ime to device...
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 install /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk
# 在设备上安装UnicodeIME-debug.apk
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 install /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk'
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 install /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk'
# UnicodeIME-debug.apk已经安装了
[debug] [ADB] Application '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk' already installed. Continuing.
# 执行ADB命令:adb -P 5037 -s LGH990d383a057
# 设置使用默认的输入法
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell settings get secure default_input_method'
# 取消之前的键盘设置,将键盘设置为unicodeIME
[debug] [AndroidDriver] Unsetting previous IME com.android.adbkeyboard/.AdbIME
[debug] [AndroidDriver] Setting IME to 'io.appium.android.ime/.UnicodeIME'
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell ime enable io.appium.android.ime/.UnicodeIME
# 启用UnicodeIME
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell ime enable io.appium.android.ime/.UnicodeIME'
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell ime set io.appium.android.ime/.UnicodeIME
# 设置io.appium.android.ime/.UnicodeIME
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell ime set io.appium.android.ime/.UnicodeIME'
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Getting install status for io.appium.unlock
# 执行ADB命令:adb -P 5037 -s LGH990d383a057 shell pm list packages io.appium.unlock
# 查看设备上安装的io.appium.unlock
[debug] [ADB] Running '/Users/jiarui/Library/Android/sdk/platform-tools/adb -P 5037 -s LGH990d383a057 shell pm list packages io.appium.unlock'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.unlock'

作业二

画五角星

def test_touch_action(self):
self.driver.find_element_by_accessibility_id('Graphics').click()
ua_scroll = 'new UiScrollable(new UiSelector().' \
'className("android.widget.ListView")).scrollIntoView(new UiSelector().text("FingerPaint"))'
self.driver.find_element_by_android_uiautomator(ua_scroll).click()
action = TouchAction(self.driver)
action.long_press(x=0.3, y=0.4).move_to(x=0.8, y=0.4).release().perform()
action.long_press(x=0.8, y=0.4).move_to(x=0.3, y=0.6).release().perform()
action.long_press(x=0.3, y=0.6).move_to(x=0.55, y=0.25).release().perform()
action.long_press(x=0.55, y=0.25).move_to(x=0.8, y=0.6).release().perform()
action.long_press(x=0.8, y=0.6).move_to(x=0.3, y=0.4).release().perform()

作业三

def test_hj(self):
self.driver.find_element_by_xpath(u'//*[@text="登录"]').click()
print(self.driver.contexts)
self.driver.switch_to.context(self.driver.contexts[1])
for context in self.driver.contexts:
if 'webview' in context.lower():
self.driver.switch_to.context(context)
break

un = WebDriverWait(self.driver, 5000).until(lambda driver: driver.find_element_by_name("username"), '找不到用户名输入框')
un.clear().send_keys('uuuuuuu')
self.driver.find_element_by_name('password').clear().send_keys('123456')
self.driver.find_element_by_class_name('hp-btn').click()


需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up