uiautomator +python 安卓UI自动化尝试
使用方法基本说明:https://www.cnblogs.com/mliangchen/p/5114149.html,https://blog.csdn.net/Eugene_3972/article/details/76629066
环境准备:https://www.cnblogs.com/keeptheminutes/p/7083816.html
简单实例
1.自动化安装与卸载 :https://my.oschina.net/yangyanxing/blog/498403
2.自动化登录测试 :http://www.cnblogs.com/leiziv
注:安卓6.0以上的手机不会自动安装app-uiautomator.apk和app-uiautomator-test.apk,需要手动安装,否则报错ioerror RPC server not started
uiautomator +python+HTMLTestRunner 安卓UI自动化实现
#coding:utf-8
from uiautomator import Device
import os
import unittest
from HTMLTestRunner import HTMLTestRunner
import time d=Device('127.0.0.1:62001')
print d.info class TestEle(unittest.TestCase):
def setUp(self):
cmd = 'adb shell am start me.ele/me.ele.application.ui.home.HomeActivity'
os.system(cmd)
cmd = 'adb shell am start me.ele/me.ele.shopping.ui.search.SearchActivity'
os.system(cmd) def tearDown(self):
cmd='adb shell am force-stop me.ele'
os.system(cmd) def testSearch(self):
d(resourceId='me.ele:id/editor').set_text('coco')
d(resourceId='me.ele:id/search').click()
d.screenshot(r"E:\code\auto\ele_search.png")
self.assertTrue(d(text="coco").exists) if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestEle))
now = time.strftime('%Y-%m-%d', time.localtime(time.time()))
test_dir = r'E:\code\auto'
filename = test_dir + '/' + now + 'test_result.html'
fp = file(filename,'wb')
runner = HTMLTestRunner(stream=fp, title='ele demo by uiautomator', description= u'测试结果')
runner.run(suite)
注:
1.通过adb devices获取设备名,127.0.0.1:62001是夜神模拟器的设备名
2.通过adb shell dumpsys window | findstr mCurrentFocus命令获取apk应用名和.MainActivity,如me.ele/me.ele.application.ui.home.HomeActivity
3.通过'adb shell am start me.ele/me.ele.application.ui.home.HomeActivity' 启动模拟器上app的activity,使用真机无法启动,可能是app应用不允许外部访问
C:\Users\admin>adb shell am start me.ele/me.ele.application.ui.home.HomeActivity
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=me.ele/.application.ui.home.HomeActivity }
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
flg=0x10000000 cmp=me.ele/.application.ui.home.HomeActivity } from null (pid=21101, uid=2000) not exported from uid 10046
at android.os.Parcel.readException(Parcel.java:1468)
at android.os.Parcel.readException(Parcel.java:1422)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2150)
at com.android.commands.am.Am.runStart(Am.java:694)
at com.android.commands.am.Am.onRun(Am.java:272)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:78)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
at dalvik.system.NativeStart.main(Native Method)
4.通过uiautomatorviewer获取resourceId
运行结果:d(text="coco").exists包含了搜索栏的'coco',故而断言成功


uiautomator +python 安卓UI自动化尝试的更多相关文章
- 使用appium+python做UI自动化的demo
使用appium+python做UI自动化的demo 案例使用的知乎app,下载最新的知乎apk,存在了电脑上,只需要配置本机上app目录,不需要再配置appPackage和appActivity # ...
- 谷歌安卓UI自动化测试策略
中文翻译版: 为了使大家确信"应做单元测试,就一定能做单元测试",谷歌测试工程师Mona El Mahdy专门写了一篇博客,提出了几种执行安卓应用用户界面单元测试的方法.Mahdy ...
- 【Python】UI自动化-1
一.安装selenium和环境配置 1 pip install selenium 2 三个驱动文件放到d:盘根目录 3 安装火狐版本33 4 安装插件:selenium ide\firebug\fir ...
- Python实现UI自动化
1. Selenium2 + WebDriver API 2. unittest单元测试框架 3. HTMLTestRunner.html测试报告 4. 自动化测试模型介绍 5. ...
- python WEB UI自动化在日期框中动态输入当前日期
要在日期框中输入当前日期,如下图 代码为 本想用最简单的方法,直接用sendkeys发送当前日期,如下: current_time=time.strftime('%Y-%m-%d',time.loca ...
- Android_UiAutomator(安卓UI自动化)环境搭建
一.配置JDK环境变量 1.新建系统变量JAVA_HOME,然后输入引号内的内容(JDK安装目录) "C:\Program Files\Java\jdk1.8.0_51" ...
- python+selenium UI自动化不同浏览器之间的切换
class register(): ROBOT_LIBRARY_SCOPE = 'GLOBAL' def __init__(self): pass # m默认打开chrome def open_bro ...
- Python Selenium 搭建Web UI自动化
Python搭建UI自动化环境 下载Python3 Python官网 PyCharm 环境配置 安装Python 勾选Add Python to PATH,一直下一步. 验证:CMD输入Python ...
- 测试自动化:java+selenium3 UI自动化(1) - 环境搭建
1.前言 我大概是在2012年第一次正式接触到自动化测试,那个时候跟随我的团队一起,就当时项目的UI自动化尝试做出了探索. 在我离开那家公司的时候,我们的自动化测试体系仍然难言完美,但是也已经达到了非 ...
随机推荐
- linux命令(001) -- chkconfig
一.准备知识 在说明chkconfig命令的用途之前,有必要先了解一下Linux系统中/etc/rc[0-6].d目录的用途. 众所周知,在Linux系统定义了7种不同的启动级别,这7种启动级别的含义 ...
- 涨知识-VI 基于TCP/UDP的应用层协议
基于TCP/UDP的应用层协议: 基于TCP: Telnet(Teletype over the Network, 网络电传),通过一个终端(terminal)登陆到网络 FTP(File Trans ...
- 批量建文件夹【win7企业版】
在记事本中notepad.exe按如下格式编辑好 md + 空格 + 文件夹名字(多个之间用空格隔开) 保存为.bat格式,运行即可批量创建文件夹.
- 鼠标单击到 img行的时候图片隐藏方案
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- pd_ds 之 hash
http://attack.cf/?post=23 打个广告....
- win32之bitmap篇
先讲一下LoadBitmap的用法,代码如下: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); HDC hMemDC = CreateCompa ...
- Memcached 在Linux上的安装
1.安装libevent wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libeve ...
- EF-Linq
一丶基本语法(from a in Table where a.id="001" select a).Tolist(); 隐式内连接from a in table1 join b i ...
- Python学习笔记——Matplot库
https://www.cnblogs.com/laoniubile/p/5893286.html 一.基本指令 import matplotlib.pyplot as plt plt.figure ...
- cf 337 div2 c
C. Harmony Analysis time limit per test 3 seconds memory limit per test 256 megabytes input standard ...