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 timed=Device('127.0.0.1:62001')
print d.infoclass 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',故而斷言成功

?

轉載于:https://www.cnblogs.com/Ryana/p/9045214.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389624.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389624.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389624.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

5922. 統計出現過一次的公共字符串

5922. 統計出現過一次的公共字符串 給你兩個字符串數組 words1 和 words2 ,請你返回在兩個字符串數組中 都恰好出現一次 的字符串的數目。 示例 1:輸入:words1 ["leetcode","is","amazing","as",&…

Python+Appium尋找藍牙/wifi匹配

前言: 此篇是介紹怎么去尋找藍牙,進行匹配。主要2個問題點: 1.在不同環境下,搜索到的藍牙數量有變 2.在不同環境下,搜索到的藍牙排序會變 簡單思路: 將搜索出來的藍牙名字添加到一個list去,然后…

power bi中的切片器_在Power Bi中顯示選定的切片器

power bi中的切片器Just recently, while presenting my session: “Magnificent 7 — Simple tricks to boost your Power BI Development” at the New Stars of Data conference, one of the questions I’ve received was:就在最近,在“新數據之星”會議上介紹我…

字符串匹配 sunday算法

#include"iostream" #include"string.h" using namespace std;//BF算法 int strfind(char *s1,char *s2,int pos){int len1 strlen(s1);int len2 strlen(s2);int i pos - 1,j 0;while(j < len2){if(s1[i j] s2[j]){j;}else{i;j 0;}}if(j len2){…

5939. 半徑為 k 的子數組平均值

5939. 半徑為 k 的子數組平均值 給你一個下標從 0 開始的數組 nums &#xff0c;數組中有 n 個整數&#xff0c;另給你一個整數 k 。 半徑為 k 的子數組平均值 是指&#xff1a;nums 中一個以下標 i 為 中心 且 半徑 為 k 的子數組中所有元素的平均值&#xff0c;即下標在 i …

Adobe After Effects CS6 操作記錄

安裝 After Effects CS6 在Mac OS 10.12.5 上無法直接安裝, 需要瀏覽到安裝的執行文件后才能進行 https://helpx.adobe.com/creative-cloud/kb/install-creative-suite-mac-os-sierra.html , 但是即使安裝成功, 也不能正常啟動, 會報"You can’t use this version of the …

數據庫邏輯刪除的sql語句_通過數據庫的眼睛查詢sql的邏輯流程

數據庫邏輯刪除的sql語句Structured Query Language (SQL) is famously known as the romance language of data. Even thinking of extracting the single correct answer from terabytes of relational data seems a little overwhelming. So understanding the logical flow…

好用的模塊

import requests# 1、發get請求urlhttp://api.xxx.xx/api/user/sxx_infodata{stu_name:xxx}reqrequests.get(url,paramsdata) #發get請求print(req.json()) #字典print(req.text) #string,json串# 返回的都是什么# 返回的類型是什么# 中文的好使嗎# 2、發請求posturlhttp://api…

5940. 從數組中移除最大值和最小值

5940. 從數組中移除最大值和最小值 給你一個下標從 0 開始的數組 nums &#xff0c;數組由若干 互不相同 的整數組成。 nums 中有一個值最小的元素和一個值最大的元素。分別稱為 最小值 和 最大值 。你的目標是從數組中移除這兩個元素。 一次 刪除 操作定義為從數組的 前面 …

BZOJ4127Abs——樹鏈剖分+線段樹

題目描述 給定一棵樹,設計數據結構支持以下操作 1 u v d  表示將路徑 (u,v) 加d 2 u v 表示詢問路徑 (u,v) 上點權絕對值的和 輸入 第一行兩個整數n和m&#xff0c;表示結點個數和操作數接下來一行n個整數a_i,表示點i的權值接下來n-1行,每行兩個整數u,v表示存在一條(u,v)的…

數據挖掘流程_數據流挖掘

數據挖掘流程1-簡介 (1- Introduction) The fact that the pace of technological change is at its peak, Silicon Valley is also introducing new challenges that need to be tackled via new and efficient ways. Continuous research is being carried out to improve th…

北門外的小吃街才是我的大學食堂

學校北門外的那些小吃攤&#xff0c;陪我度過了漫長的大學四年。 細數下來&#xff0c;我最懷念的是…… &#xff08;1&#xff09;烤雞翅 吸引指數&#xff1a;★★★★★ 必殺技&#xff1a;酥流油 烤雞翅有蜂蜜味、香辣味、孜然味……最愛店家獨創的秘制雞翅。雞翅的外皮被…

786. 第 K 個最小的素數分數

786. 第 K 個最小的素數分數 給你一個按遞增順序排序的數組 arr 和一個整數 k 。數組 arr 由 1 和若干 素數 組成&#xff0c;且其中所有整數互不相同。 對于每對滿足 0 < i < j < arr.length 的 i 和 j &#xff0c;可以得到分數 arr[i] / arr[j] 。 那么第 k 個…

[LeetCode]最長公共前綴(Longest Common Prefix)

題目描述 編寫一個函數來查找字符串數組中的最長公共前綴。如果不存在公共前綴&#xff0c;返回空字符串 ""。 示例 1:輸入: ["flower","flow","flight"]輸出: "fl"示例 2:輸入: ["dog","racecar",&quo…

域嵌套太深_pyspark如何修改嵌套結構域

域嵌套太深In our adventures trying to build a data lake, we are using dynamically generated spark cluster to ingest some data from MongoDB, our production database, to BigQuery. In order to do that, we use PySpark data frames and since mongo doesn’t have …

redis小結

Redis 切換到redis的目錄 啟動&#xff1a;./redis-server 關閉&#xff1a;killall redis-server Redis的數據類型&#xff1a; String字符 list鏈表 set集合&#xff08;無序&#xff09; Sort Set排序&#xff08;有序&#xff09; hash數據類型 string類型的數據操作 re…

WIN10下ADB工具包安裝的教程和總結 --201809

ADB&#xff08;Android Debug Bridge&#xff09;是Android SDK中的一個工具, 使用ADB可以直接操作管理Android模擬器或者真實的Andriod設備。 ADB主要功能有: 在Android設備上運行Shell(命令行)管理模擬器或設備的端口映射在計算機和設備之間上傳/下載文件將電腦上的本地APK軟…

1816. 截斷句子

1816. 截斷句子 句子 是一個單詞列表&#xff0c;列表中的單詞之間用單個空格隔開&#xff0c;且不存在前導或尾隨空格。每個單詞僅由大小寫英文字母組成&#xff08;不含標點符號&#xff09;。 例如&#xff0c;“Hello World”、“HELLO” 和 “hello world hello world”…

spark的流失計算模型_使用spark對sparkify的流失預測

spark的流失計算模型Churn prediction, namely predicting clients who might want to turn down the service, is one of the most common business applications of machine learning. It is especially important for those companies providing streaming services. In thi…

峰識別 峰面積計算 peak detection peak area 源代碼 下載

原文:峰識別 峰面積計算 peak detection peak area 源代碼 下載Comparative analysis of peak-detection techniques for comprehensive two-dimensional chromatography http://www.docin.com/p-172045359.html http://terpconnect.umd.edu/~toh/spectrum/ipeak.html R…