macaca之zfb
来源:互联网 发布:fm调频发射器软件 编辑:程序博客网 时间:2024/06/05 09:58
import base64import randomimport tracebackfrom io import BytesIOimport refrom PIL import Imagefrom macaca import WebDriver, WebElementimport timefrom util.log import loggerdesired_caps = { 'platformName': 'Android', # iOS, Android. 'deviceName': '69T7N1*********', 'platformVersion': '5.1.1', 'reuse': '3', # 0: 启动并安装 app。1 (默认): 卸载并重装 app。 2: 仅重装 app。3: 在测试结束后保持 app 状态。 'package': 'com.eg.android.AlipayGphone', # zhifubao # 'activity':'com.tencent.mm.ui.LauncherUI'}phones = ['phone1', 'phone2', 'phone3']class ZhiFuBao(object): def __init__(self): self.server_url = { 'hostname': '127.0.0.1', 'port': 3456 } #输入法相应按键对应的坐标 self.keyboard = {'1': (300, 1200), '2': (550, 1200), '3': (800, 1200), '4': (300, 1350), '5': (550, 1350), '6': (800, 1350), '7': (300, 1500), '8': (550, 1500), '9': (800, 1500), '0': (550, 1700), 'enter': (1000, 1700), 'finish': (1000, 1350)} self.time_sleep = 2 self.driver = WebDriver(desired_caps, self.server_url) self.driver.init() def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): if exc_type: print(traceback.format_exc()) print('over') #头像处理,并以base64编码保存 def handle_img(self, driver=None): img = Image.open(BytesIO(base64.b64decode(driver.take_screenshot()))) img2 = img.crop((370, 275, 710, 615)) img2.save('icon.png') with open('icon.png', 'rb') as f: content = f.read() base64encode = base64.b64encode(content) return base64encode def fun(self): time.sleep(self.time_sleep) # 点击右上角符号'+' self.driver.touch('tap', {'x': 1000, 'y': 150}) time.sleep(self.time_sleep) # 点击'添加朋友' self.driver.touch('tap', {'x': 900, 'y': 400}) time.sleep(self.time_sleep) # 点击‘支付宝账户/手机号/淘宝会员名’ self.driver.touch('tap', {'x': 173, 'y': 280}) for phone in phones: time.sleep(self.time_sleep) # 输入手机号 self.driver.touch('tap', {'x': self.keyboard['enter'][0], 'y': self.keyboard['enter'][1]}) for num in phone: x, y = self.keyboard[num] self.driver.touch('tap', {'x': x, 'y': y}) time.sleep(random.random() / 10) # 输入完成,点击完成 self.driver.touch('tap', {'x': self.keyboard['finish'][0], 'y': self.keyboard['finish'][1]}) time.sleep(self.time_sleep) # 如果账户不存在 if re.search('(账户|账号)不存在', self.driver.source): print(phone, '账号不存在') # 点击确定 self.driver.touch('tap', {'x': 800, 'y': 1050}) time.sleep(self.time_sleep) # 点击右上方符号'X',清除号码 self.driver.wait_for_element('xpath', '//*[@resource-id="com.alipay.mobile.ui:id/social_btn_normal_clear"]', timeout=60).touch('tap') continue # 点击显示更多 self.driver.wait_for_element('xpath', '//*[@resource-id="com.alipay.android.phone.wallet.profileapp:id/tv_show_more"]').touch( 'tap') time.sleep(self.time_sleep) # 头像获取 icon = self.handle_img(self.driver) # 获取名字 name = self.driver.element('xpath', '//*[@resource-id="com.alipay.android.phone.wallet.profileapp:id/tv_name"]').text # 获取左侧文本 left = self.driver.elements_by_id('com.alipay.android.phone.wallet.profileapp:id/tv_left') left_text = [item.text for item in left] # 获取右侧文本 right_text = list() for item in self.driver.elements_by_id('com.alipay.android.phone.wallet.profileapp:id/tv_right'): content_desc = item.get_property('content-desc') # 是否已实名 if 'description' in content_desc: right_text.append(content_desc['description']) else: right_text.append(content_desc['text']) result = dict(zip(left_text, right_text)) result['name'] = name result['icon'] = icon print(result) # 回退 self.driver.wait_for_element('xpath', '//*[@resource-id="com.alipay.mobile.ui:id/title_bar_back_button"]', timeout=60).touch('tap') time.sleep(self.time_sleep) # 点击右上方符号'X',清除号码 self.driver.wait_for_element('xpath', '//*[@resource-id="com.alipay.mobile.ui:id/social_btn_normal_clear"]', timeout=60).touch('tap')def crawl(): with ZhiFuBao() as zfb: zfb.fun()if __name__ == '__main__': crawl()
阅读全文
0 0
- macaca之zfb
- Macaca之常见参数
- Macaca之uirecorder使用
- macaca
- macaca
- Macaca之App Inspector使用简介
- zfb笔
- Macaca之使用中存在的各种坑
- Macaca之填坑中所参考的一些文章
- Macaca之2.0版本(iOS)完全安装手册
- Macaca之测试用例(Node.JS版)
- Macaca之测试用例(Java版)
- tp3.2zfb
- zfb报错
- 安装Macaca,打不开问题
- Macaca基础原理
- Macaca Inspector启动命令
- Macaca自动化测试框架
- 模块API之symbol_put_addr
- NOJ1322求子集重量之和(Calculate the sum of a subset's weight)
- Treap 学习笔记
- 61. Rotate List
- linux进程调度方法简述
- macaca之zfb
- Java程序员不可不知的几个网站,你去过几个?
- update通用生成SQL语句方法
- 初次尝试Maven+logj2.xml 配置
- 关于浏览器的请求数据到达后台乱码问题
- 练习(6)
- Item 3:尽可能使用const【effective C++读书笔记】
- java_01.1
- ligerUI框架怎样调节文本框下拉框宽度高度等属性