Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Open Source > Mobile Dev > Android Component/ Project &&
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
utils.py 6.24 KB
Copy Edit Raw Blame History
gb112211 authored 2019年05月29日 17:14 +08:00 . 设备列表显示设备名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2015年1月23日
@author: xuxu
'''
import os
import platform
import re
import subprocess
import time
import Tkinter as tk
import ttk
import exception
serialno_num = ""
# 判断系统类型,windows使用findstr,linux使用grep
system = platform.system()
if system is "Windows":
find_util = "findstr"
else:
find_util = "grep"
# 判断是否设置环境变量ANDROID_HOME
if "ANDROID_HOME" in os.environ:
if system == "Windows":
command = os.path.join(os.environ["ANDROID_HOME"], "platform-tools", "adb.exe")
else:
command = os.path.join(os.environ["ANDROID_HOME"], "platform-tools", "adb")
else:
raise EnvironmentError(
"Adb not found in $ANDROID_HOME path: %s." %os.environ["ANDROID_HOME"])
def get_screen_size(window):
return window.winfo_screenwidth(),window.winfo_screenheight()
def get_window_size(window):
return window.winfo_reqwidth(),window.winfo_reqheight()
def center_window(root, width, height):
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
root.geometry(size)
class Window(object):
device_id = ""
device_id_list = []
device_name_list = []
device_name_dict = {}
root = None
box = None
def __init__(self, device_id_list, root):
self.device_id_list = device_id_list
self.device_name_dict = get_device_name_dict(self.device_id_list)
self.get_device_name_list()
self.device_id = device_id_list[0]
self.root = root
self.box = None
def show_window(self):
self.root.title(u'Serialno Number')
center_window(self.root, 300, 240)
self.root.maxsize(600, 400)
self.root.minsize(300, 240)
# options = self.device_id_list
options = self.device_name_list
self.box = ttk.Combobox(values=options)
self.box.current(0)
self.box.pack(expand = tk.YES)
self.box.bind("<<ComboboxSelected>>", self.select)
ttk.Button(text=u"确定", command=self.ok).pack(expand = tk.YES)
self.root.mainloop()
def select(self, event=None):
for key, value in self.device_name_dict.iteritems():
if value == self.box.selection_get():
self.device_id = key
# self.device_id = self.box.selection_get()
def ok(self):
global serialno_num
serialno_num = self.device_id
self.root.destroy()
def get_device_name_list(self):
for id in self.device_id_list:
self.device_name_list.append(self.device_name_dict.get(id))
# adb命令
def adb(args):
global serialno_num
if serialno_num == "":
devices = get_device_list()
if len(devices) == 1:
# global serialno_num
serialno_num = devices[0]
else:
root = tk.Tk()
window = Window(devices, root)
window.show_window()
cmd = "%s -s %s %s" %(command, serialno_num, str(args))
return subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#adb shell命令
def shell(args):
global serialno_num
if serialno_num == "":
devices = get_device_list()
if len(devices) == 1:
serialno_num = devices[0]
else:
root = tk.Tk()
window = Window(devices, root)
window.show_window()
cmd = "%s -s %s shell %s" %(command, serialno_num, str(args))
return subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#获取设备状态
def get_state():
return os.popen("adb -s %s get-state" %serialno_num).read().strip()
# 获取对应包名的pid
def get_app_pid(pkg_name):
if system is "Windows":
string = shell("ps | findstr %s$" %pkg_name).stdout.read()
string = shell("ps | grep -w %s" %pkg_name).stdout.read()
if string == '':
return "the process doesn't exist."
pattern = re.compile(r"\d+")
result = string.split(" ")
result.remove(result[0])
return pattern.findall(" ".join(result))[0]
# 杀掉对应包名的进程
def kill_process(pkg_name):
pid = get_app_pid(pkg_name)
result = shell("kill %s" %str(pid)).stdout.read().split(": ")[-1]
if result != "":
raise exception.SriptException("Operation not permitted or No such process")
# 获取设备上当前应用的包名与activity
def get_focused_package_and_activity():
pattern = re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+")
tmp = shell("dumpsys activity | %s mFocusedActivity" %find_util).stdout.read()
name = ""
try:
name = pattern.findall(tmp)[0]
except:
tmp = shell("dumpsys window w | %s \/ | %s name=" %(find_util, find_util)).stdout.read()
name = pattern.findall(tmp)[0]
return name
# 获取当前应用的包名
def get_current_package_name():
return get_focused_package_and_activity().split("/")[0]
# 获取当前设备的activity
def get_current_activity():
return get_focused_package_and_activity().split("/")[-1]
# 时间戳
def timestamp():
return time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time()))
def get_device_list():
devices = []
result = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines()
result.reverse()
for line in result[1:]:
if "attached" not in line.strip():
devices.append(line.split()[0])
else:
break
return devices
def get_device_name_dict(devices):
device_dict = {}
if not devices:
return
for device in devices:
cmd = "adb -s %s shell getprop ro.product.model" %device
device_name = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readline().strip()
device_dict[device] = device_name
return device_dict
# 连接设备
# adb("kill-server").wait()
# adb("start-server").wait()
adb("wait-for-device").wait()
if get_state() != "device":
adb("kill-server").wait()
adb("start-server").wait()
if get_state() != "device":
raise exception.SriptException("Device not run")
if __name__ == "__main__":
print get_focused_package_and_activity()
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Android测试中常用到的脚本
Cancel

Releases

No release

The Open Source Evaluation Index is derived from the OSS Compass evaluation system, which evaluates projects around the following three dimensions

1. Open source ecosystem

  • Productivity: To evaluate the ability of open-source projects to output software artifacts and open-source value.
  • Innovation: Used to evaluate the degree of diversity of open source software and its ecosystem.
  • Robustness: Used to evaluate the ability of open-source projects to resist internal and external interference and self recover in the face of changing development environments.

2. Collaboration, People, Software

  • Collaboration: represents the degree and depth of collaboration in open source development behavior.
  • Observe the influence of core personnel in open source projects, and examine the evaluations of users and developers on open source projects from a third-party perspective.
  • Software: Evaluate the value of products exported from open-source projects and their ultimate destination. It is also a concrete manifestation of "open source software", one of the oldest mainstream directions in open source evaluation.

3. Evaluation model

    Based on the dimensions of "open source ecosystem" and "collaboration, people, and software", identify quantifiable indicators directly or indirectly related to this goal, quantitatively evaluate the health and ecology of open source projects, and ultimately form an open source evaluation index.

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Android
1
https://gitee.com/xuxu1988/AndroidTestScripts.git
git@gitee.com:xuxu1988/AndroidTestScripts.git
xuxu1988
AndroidTestScripts
AndroidTestScripts
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /