def test_city_diqu_day_share(self): '分享测试' poco = UnityPoco() if poco("text").get_text() == '分享再领一次': poco("btn_identify").click() poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) if poco("android.widget.LinearLayout").offspring( "com.tencent.mm:id/jx").exists(): print('分享跳转微信正常--测试通过') poco("com.tencent.mm:id/kb").click() poco("android:id/content").offspring( "com.tencent.mm:id/az_").click() poco = UnityPoco() poco("btn_identify").click() poco("img_close").click() elif poco("android:id/text1").get_text() == '登录微信': print('分享跳转微信正常--测试通过') poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) poco("com.tencent.mm:id/kb").click() poco = UnityPoco() poco("text").click() poco("img_close").click() else: print('分享跳转微信不正常--测试不通过') assert (poco("android:id/text1").get_text() == '登录微信') else: print('弹出分享失败--测试不通过') assert (poco("img_green_side"))
def test(self): DeviceNum = 'APU0215B25001477' device = Android(DeviceNum) poco = AndroidUiautomationPoco(device) poco.swipe([0.4, 0.8], [0.4, 0.5], duration=0.3) pass
def __init__(self): connect_device( "android://127.0.0.1:5037/4f74b1cc?cap_method=MINICAP_STREAM&&ori_method=MINICAPORI&&touch_method=MINITOUCH") self.poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) self.screenWidth, self.screenHeight = self.poco.get_screen_size() self.total = 0 self.loop_users()
def __init__(self): self.api = api device = connect_device("android:///") self.poco = AndroidUiautomationPoco(device, use_airtest_input=True, screenshot_each_action=False) self.timeout = 20
def __init__(self): self.package_name = 'com.tencent.weishi' self.home_activity = 'com.tencent.oscar.module.splash.SplashActivity' # 配置日志 LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" logging.basicConfig(filename='my.log', level=logging.DEBUG, format=LOG_FORMAT) # 互动红包元素【普通红包】 self.image_red_package = './pic/red.png' # 互动红包元素【答题红包】 self.image_red_package2 = './pic/red2.png' # 抢红包的切图元素【小红包】 self.catch_red_package = './pic/red_catch.jpg' # 抢红包的切图元素【中红包】 self.catch_red_package_more = './pic/red_catch_more.png' # 抢红包的切图元素【大红包】 self.catch_red_package_most = './pic/red_catch_most.png' # 获得红包的元素 self.get_red_package = './pic/part.jpg' self.wait_for_dialog_timeout = 10 # 截图临时保存路径 self.screenshot_pic_temp_path = './sc.jpg' self.poco = AndroidUiautomationPoco(screenshot_each_action=False) auto_setup(__file__)
def __init__(self): try: self.poco = AndroidUiautomationPoco(screenshot_each_action=False) self.adb = AdbUtils() auto_setup(__file__) self.connected = True except: self.connected = False
def build_poco(device): if device: poco = AndroidUiautomationPoco(device, use_airtest_input=True, screenshot_each_action=False) else: poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) return poco
def __init__(self): connect_device( "android://127.0.0.1:5037/4f74b1cc?cap_method=MINICAP_STREAM&&ori_method=MINICAPORI&&touch_method=MINITOUCH" ) self.poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) self.s_width, self.s_height = self.poco.get_screen_size() self.fans_json = "" self.validate_config()
def initDevice(self): ''' 初始化设备 :return: ''' if (ST.DEVICE is None) or (len(ST.DEVICE) == 0): #未配置设备时,使用默认设备进行连接 #先尝试连接安卓设备,如果连接失败,连接IOS try: dev = init_device(cap_method=ST.CAP_METHOD, ori_method=ST.ORI_METHOD, touch_method=ST.TOUCH_METHOD) except: dev = init_device(self.__ios) self.__airtestDevDict["___one___"] = dev self.__nameAndDevMap["___one___"] = dev.uuid devType = dev.__class__.__name__ if devType == self.__android: pocoDev = AndroidUiautomationPoco() pootDev = Poot(dev.uuid, screenshot_each_action=True) elif devType == self.__ios: pocoDev = iosPoco() pootDev = None else: raise BaseException("暂时不支持此种类型设备{%s}" % devType) self.__pocoDevList["___one___"] = pocoDev self.__pootDevList["___one___"] = pootDev self.__activeDevName = "___one___" self.__activeDev = dev self.__activePoco = pocoDev self.__activePoot = pootDev self.__activeDevType = devType else: #否则,使用配置进行连接 for devName, devUri in ST.DEVICE.items(): dev = connect_device(devUri) self.__airtestDevDict[devName] = dev self.__nameAndDevMap[devName] = dev.uuid devType = dev.__class__.__name__ if devType == self.__android: pocoDev = AndroidUiautomationPoco(dev) pootDev = Poot(dev.uuid, screenshot_each_action=True) elif devType == self.__ios: pocoDev = iosPoco() pootDev = None else: raise BaseException("暂时不支持此种类型设备{%s}" % devType) self.__activeDevName = devName self.__pocoDevList[devName] = pocoDev self.__pootDevList[devName] = pootDev self.__activeDev = dev self.__activePoco = pocoDev self.__activeDevType = devType self.__activePoot = pootDev LOGGING.info("(%s)已连接" % ",".join(self.__nameAndDevMap.values()))
def __init__(self): self.poco = AndroidUiautomationPoco(screenshot_each_action=False) auto_setup(__file__) self.location = '故宫' self.msg = "这是一条心情" # 图片数目 self.image_num = 1
def __init__(self): try: self.poco = AndroidUiautomationPoco(screenshot_each_action=False) self.adb = AdbUtils() auto_setup(__file__) self.connected = True except Exception as e: Logger.e('连接设备失败', e) self.connected = False self.prepared = False
def test_kfonline(self): '跳转到在线客服测试' poco = StdPoco() poco("Layout")[1].offspring("btn_kefu").click() from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) if poco( "com.dashengzhangyou.pykf.lailaiguangdong:id/message_fragment_container" ).offspring( "com.dashengzhangyou.pykf.lailaiguangdong:id/messageListView" ).child("android.widget.RelativeLayout")[0].offspring( "com.dashengzhangyou.pykf.lailaiguangdong:id/message_item_content" ).offspring( "com.dashengzhangyou.pykf.lailaiguangdong:id/clickable_item_text" ): self.rgkf = poco( "com.dashengzhangyou.pykf.lailaiguangdong:id/message_fragment_container" ).offspring( "com.dashengzhangyou.pykf.lailaiguangdong:id/messageListView" ).child("android.widget.RelativeLayout")[0].offspring( "com.dashengzhangyou.pykf.lailaiguangdong:id/message_item_content" ).offspring( "com.dashengzhangyou.pykf.lailaiguangdong:id/clickable_item_text" ) if self.rgkf.get_text() == '人工客服': print('客服系统跳转--测试通过') keyevent("BACK") else: print('客服系统跳转异常--测试失败') assert (self.rgkf.get_text() == '人工客服')
def vivo(): # device_1 = connect_device('android://192.168.103.156:48887/339b19f1?cap_method=javacap&touch_method=adb') # device_1 = connect_device('android:///192.168.103.156:48887?cap_method=javacap&touch_method=adb') device_1 = connect_device( 'android:///192.168.0.106:48887?cap_method=javacap&touch_method=adb') # device_1 = Android('android://192.168.103.156:48887?cap_method=javacap&touch_method=adb') poco = AndroidUiautomationPoco(device=device_1, use_airtest_input=True, screenshot_each_action=False) # poco(text="今日头条极速版").click() # poco(name="com.ss.android.article.lite:id/adg").click() # poco(name="com.ss.android.article.lite:id/qp").set_text("古剑奇谭三") for i in range(500): print(i) time.sleep(1) poco.swipe([0.5, 0.8], [0.5, 0.2])
def HandleInterfacaBox(self): ''' 处理初次进入界面可能弹出的活动弹窗 :return: ''' from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) try: tips_realname = poco(package + ":id/bt_dialog_close") # 弹框的关闭按钮 if tips_realname: tips_realname.click() except: pass sleep(2) poco = StdPoco() try: tips_change_name = poco("JJButtondialog_close_btn_n") # 弹框的关闭按钮 biaoshi = poco("SceneBaseRootView").child("JJViewGroup")[0].\ child("JJImagepage_indicator_common")[1] # 大厅下方的页标识 if tips_change_name: biaoshi.click() except: pass sleep(2)
def __init__(self): """ self.config: 获取配置文件 self.poco: 获取poco实例 """ self.config = Config().get_data print(f"device(): {device()}") # 检查adb状态 adb = ADB() device_list = adb.devices() print(f"device_list: {device_list}") device_num = len(device_list) >= 1 # print(device_list) assert_equal(device_num, True, "设备连接数至少>=1") # self.device_list = device_list # 获取poco实例 self.poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) # 获取根目录 # self.root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # if not cli_setup(): # auto_setup( # basedir=self.root_dir, # devices=self.["android_devices"], # logdir=False # ) self._setting() self.width, self.height = device().get_current_resolution() print("[BasePage] init...") self.root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) self.main_phone = self.config.get("main_phone")
def test_01_of_101(self): u'''用例test_01_of_101的操作步骤''' # 每个函数里分别实例poco,否则容易出现pocoserver无限重启的情况 poco = AndroidUiautomationPoco() print("我是TC101的test_01_of_101方法") t = 1 self.assertEquals(1, t)
def __init__(self, device_host): auto_setup(__file__) self.device_1 = connect_device( f'android:///{device_host}?cap_method=javacap&touch_method=adb') self.device_name = 'xiaoyao' self.poco = AndroidUiautomationPoco(self.device_1, screenshot_each_action=False) self.client = pymongo.MongoClient() self.dp_db = self.client['DianPing'] self.wechat_db = self.client['WeChatOfficialAccount'] self.wechat_col = self.wechat_db['wechat_search_info'] self.pandas_col = self.wechat_db['pandas_info'] self.redis_cli = redis.StrictRedis(decode_responses=True) self.biz_queue = f'{self.device_name}_wechat_biz' self.url_queue = f'{self.device_name}_article_url' self.wx_package_name = 'com.tencent.mm' self.city_en_list = [ 'guangzhou', 'dongguan', 'foshan', 'huizhou', 'zhongshan', 'zhuhai' ] self.count = 0
def real_name_authentication(self): poco = AndroidUiautomationPoco() # 在我的界面点击实名认证按钮 poco("cn.chengyu.love:id/nameLay").click() # 上传身份证正面 poco("cn.chengyu.love:id/frontCardImg").click() poco("cn.chengyu.love:id/dialog_tv_select").click() poco("cn.chengyu.love:id/check_view")[0].click() # 使用按钮 poco("cn.chengyu.love:id/button_apply").click() time.sleep(2) # 上传身份证国徽面 poco("cn.chengyu.love:id/backCardImg").click() poco("cn.chengyu.love:id/dialog_tv_select").click() poco("cn.chengyu.love:id/check_view")[1].click() # 使用按钮 poco("cn.chengyu.love:id/button_apply").click() time.sleep(2) # 上传手持身份证 poco("cn.chengyu.love:id/takeCardImg").click() poco("cn.chengyu.love:id/dialog_tv_select").click() poco("cn.chengyu.love:id/check_view")[2].click() # 使用按钮 poco("cn.chengyu.love:id/button_apply").click() time.sleep(2) poco("cn.chengyu.love:id/confirmBtn").click() time.sleep(5) value = poco("cn.chengyu.love:id/processTv1").attr("text") assert_equal(value, "预计24小时内返回结果", "实名认证填写成功") # 点击返回按钮 poco("cn.chengyu.love:id/closeBtn").click()
def first_open_yztest(self): ''' 首次启动时使用该方法,不会因为游戏不同而改变 :return: ''' clear_app("com.youzu.yztest_nosdk") home() stop_app("com.youzu.yztest_nosdk") sleep(2) start_app("com.youzu.yztest_nosdk") sleep(10) poco_android = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) self.my_andriod_poco.set_poco(poco_android) sleep(1) self.my_andriod_poco.find_poco("请输入用户名") sleep(1) os.system("adb shell input text " + self.use_name) # 没有输入框也执行的话也不影响 self.my_andriod_poco.find_poco("登录") sleep(3) # self.my_andriod_poco.find_poco("总是允许") # todo 三挡机 sleep(3) self.my_andriod_poco.find_poco("选择应用") sleep(2) self.my_andriod_poco.find_poco(self.game_name, ynlist="下翻页") sleep(2) self.my_andriod_poco.find_poco("自动截图", click_name="com.youzu.yztest_nosdk:id/auto_screen_shot", click_type="name") # 每次打开软件是默认关闭的 # os.system("start /b adb shell sh /data/local/tmp/yztest_sh.sh") 需要平台启动该服务 sleep(2)
def acquisition_conditions(self): poco = AndroidUiautomationPoco() poco(name=conditionLay).click() # 所在地 poco(name=locationLay).click() poco(name=locationChooser).swipe([-0.5, -0.5]) poco(text="确定").click() # 年龄范围 poco(name=ageRangeLay).click() poco(name=startAgeChooser).swipe([-0.5, -0.4]) poco(name=endAgeChooser).swipe([-0.5, -0.5]) poco(text="确定").click() # 身高 poco(name=heightLay).click() poco(name=startHeightChooser).swipe([-0.5, -0.4]) poco(name=endHeightChooser).swipe([-0.5, -0.5]) poco(text="确定").click() # 最低学历 poco(name=lowestEduLay).click() poco(text="确定").click() # 月收入 poco(name=incomeLay).click() poco(text="确定").click() # 点击保存 poco(text="保存").click() sleep(2)
def many_picture_zone(self): poco = AndroidUiautomationPoco() # 点击进入动态界面 poco("cn.chengyu.love:id/trendsMoreImageView").click() # 点击发布动态 poco("cn.chengyu.love:id/addTrendsLayout").click() # 选择图片 poco("cn.chengyu.love:id/tvCheck")[1].click() poco("cn.chengyu.love:id/picture_tv_ok").click() # 添加文字 poco("cn.chengyu.love:id/contentEditText").set_text("我是测试发布图片动态") # 再次添加一张图片 poco("cn.chengyu.love:id/addImageView").click() poco("cn.chengyu.love:id/tvCheck")[2].click() poco("cn.chengyu.love:id/picture_tv_ok").click() # 选择话题 poco("cn.chengyu.love:id/trendsMoreImageView").click() poco(text="#冬天的记忆").click() # 添加地点 poco("cn.chengyu.love:id/addressTextView").click() poco("cn.chengyu.love:id/titleTextView")[0].click() # 发布 poco("cn.chengyu.love:id/submitTextView").click() sleep(5) # 返回 poco("cn.chengyu.love:id/closeBtn").click() sleep(2)
def logout(self): # 调用公共方法 ba = Base() ba.login() if not cli_setup(): auto_setup(__file__, logdir='./case/logout/log') try: poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) # script content sleep(2) print("-------------登出流程开始----------------") #點擊我的 poco("android.widget.LinearLayout").offspring("android.widget.FrameLayout").child("android.view.ViewGroup").child("android.view.ViewGroup")[1].offspring("MineHome, tab, 3 of 3").offspring("android.widget.ImageView").click() #點擊設置 poco(text="設置").click() #登出 poco(text="退出登錄").click() poco(text="確定").click() print("登出成功") print("-------------登出流程结束----------------") # 退出app ba.stop_app() except Exception as e: print("-------------异常情况-------------") ba.log_error("登出流程错误: \n %s"%(e)) print(e) # 退出app ba.stop_app()
def xiaomi_usb(self): device_2 = connect_device('android:c4e6cc907d25') poco = AndroidUiautomationPoco(device=device_2, use_airtest_input=True, screenshot_each_action=False) # for i in range(self.loop_num): # print('{}_xiaomi_usb'.format(i)) # # 首页 # poco("android.widget.LinearLayout").offspring("android:id/tabs").child("android.widget.RelativeLayout")[ # 0].child("com.ss.android.article.lite:id/axy").click() # poco("android.widget.LinearLayout").offspring("android:id/tabs").child("android.widget.RelativeLayout")[ # 0].child("com.ss.android.article.lite:id/axy").click() # time.sleep(10) # poco.swipe([0.5, 0.8], [0.5, 0.2]) # time.sleep(10) # # 视频 # poco("android.widget.LinearLayout").offspring("android:id/tabs").child("android.widget.RelativeLayout")[ # 1].child("com.ss.android.article.lite:id/axy").click() # poco("android.widget.LinearLayout").offspring("android:id/tabs").child("android.widget.RelativeLayout")[ # 1].child("com.ss.android.article.lite:id/axy").click() # time.sleep(10) # poco.swipe([0.5, 0.8], [0.5, 0.2]) # time.sleep(10) # # 评论 # poco("com.ss.android.article.lite:id/ank").click() # time.sleep(20) # # 返回 # poco("com.ss.android.article.lite:id/aid").click() self.trail1(poco, 'xiaomi_usb')
def setUpClass(cls): """ 整个用例执行的前置条件 """ super(AndroidAppCase, cls).setUpClass() cls.poco = AndroidUiautomationPoco()
def oppo_usb(self): #UOI7NVMN99999999 device_2 = connect_device('android:UOI7NVMN99999999') poco = AndroidUiautomationPoco(device=device_2, use_airtest_input=True, screenshot_each_action=False) self.trail1(poco, 'oppo_usb')
def __init__(self): good_opts = self.__get_yaml('_goods.yaml') # 要爬取的商品 self.good = good_opts.get('goods').get('good1') # 筛选【想要数】多少的商品 self.num_assign = self.good.get('key_num') # 筛选数目 self.num = self.good.get('num') # 查询关键字 self.good_msg = self.good.get('key_word') # 文件路径,以时间+关键字组成 self.file_path = './%s_%s.csv' % ( self.good_msg, datetime.datetime.now().strftime("%Y_%m_%d")) # 爬取时间 self.spider_time = int(self.good.get('time')) # 爬取的数据 self.good_results = [] # 已经处理的商品 self.title_handled = [] self.poco = AndroidUiautomationPoco(screenshot_each_action=False) auto_setup(__file__)
def begin(group_name, update_frequency): global StatusRun StatusRun = 1 if not cli_setup(): auto_setup( __file__, logdir=True, devices=[ "Android://127.0.0.1:5037/127.0.0.1:7555?cap_method=JAVACAP&&ori_method=ADBORI", ]) poco = AndroidUiautomationPoco() get_into_group = 0 group = poco('com.tencent.mm:id/baj') # group hook in WeChat for each_group in group: if each_group.get_text() == group_name: each_group.click() get_into_group = 1 if not get_into_group: StatusRun = 0 while (True): time.sleep(update_frequency) if is_bao_exist(): status = catch_bao(poco('com.tencent.mm:id/auk')[-1]) if status == 0: print('Fail to get Envelop\n') else: print('\nWin: ' + str(status)) setting.addMoney(status) print('Total Win: ' + str(setting.get_setting()['money']) + '\n') poco('com.tencent.mm:id/m1').click()
def __init__(self): if G.DEVICE == None: if not cli_setup(): conf = MyData.EnvData_dir[ "device"] + "://" + MyData.EnvData_dir[ "ADBip"] + "/" + MyData.EnvData_dir["ADBdevice"] method = MyData.EnvData_dir["method"] if "127" in MyData.EnvData_dir["ADBdevice"]: method = MyData.EnvData_dir["simulator"] auto_setup(__file__, logdir=path_LOG_DIR, devices=[ conf + method, ], project_root=path_BASE_DIR) if MyData.DeviceData_dir["androidpoco"] == None: MyData.DeviceData_dir[ "androidpoco"] = AndroidUiautomationPoco() mylog.info("完成android原生元素定位方法初始化【{}】".format( MyData.DeviceData_dir["androidpoco"])) print("完成android原生元素定位方法初始化【{}】".format( MyData.DeviceData_dir["androidpoco"])) # ADBdevice = MyData.EnvData_dir["ADBdevice"] # print(MyData.mobileconf_dir["Notch_Fit"]) # if ADBdevice in MyData.mobileconf_dir["Notch_Fit"]: # print("报错把刚开始了解") # MyData.DeviceData_dir["androidpoco"].use_render_resolution(True, MyData.mobileconf_dir["Notch_Fit"][ # ADBdevice]) # mylog.info("androidpoco完成【{}】刘海屏特殊渲染处理".format(ADBdevice)) # print("androidpoco完成【{}】刘海屏特殊渲染处理".format(ADBdevice)) print("DEVIEC:", G.DEVICE)
def install_logout(self): poco = AndroidUiautomationPoco() poco(name="cn.chengyu.love:id/inviteLay").swipe([0, -0.5]) poco(name=settingLay).click() # 黑名单 poco(name=logoutBtn).click() sleep(2)
def test_add(self): auto_setup(__file__) dev = connect_device("android:///") poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) pass