def __init__(self, driver): self.driver = driver # 获取基础操作 self.operation = Operation(driver) self.preprocessing = Preprocessing(driver) relation_operate = RelationOperate(driver) self.elements = relation_operate.get_element()
def __init__(self, driver): self.driver = driver # 获取基础操作 self.operation = Operation(driver) self.preprocessing = Preprocessing(driver) sift_operate = SiftOperation(driver) self.elements = sift_operate.get_element()
def __init__(self, driver, log=None): if log is None: self.log = Logger("预处理步骤").getlog() else: self.log = log self.driver = driver self.excel = ReadExcel().read_excel("common") self.operation = Operation(driver, self.log) self.by = MobileBy()
class RelationOperate: elements = None def __init__(self, driver): self.driver = driver # 获取基础操作 self.operation = Operation(driver) def get_element(self): """获取「查关系」元素""" with open(element, 'r', encoding='UTF-8') as f: elements = json.load(f) self.elements = elements return elements def hot_relation(self): """进入样例关系""" # 点击首页-查关系tab self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'homeSearch relation n'").click() # 点击输入框 self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.elements["search_box"]).click() # 点击马云-赵薇,热门关系 self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.elements["hot_relation"]).click() relation_point = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == '王忠军'") return relation_point
def setUpClass(cls): cls.start_time = datetime.datetime.now() cls.driver, cls.udid, cls.log = driver_setup() cls.preprocessing = Preprocessing(cls.driver, log=cls.log) # 跳过首页引导 cls.preprocessing.skip_guide() # 点击同意用户协议 cls.preprocessing.agree_license() # 跳过升级弹窗 cls.preprocessing.cancel_update() # 跳过监控日报 cls.preprocessing.skip_monitor() # 获取基础操作 cls.operation = Operation(cls.driver, log=cls.log) # 获取账号操作 cls.account = Account(log=cls.log)
class SiftProcess: def __init__(self, driver): self.driver = driver # 获取基础操作 self.operation = Operation(driver) self.preprocessing = Preprocessing(driver) sift_operate = SiftOperation(driver) self.elements = sift_operate.get_element() def random_key(self, key, option): """ 更多筛选,选中筛选项 :param key: 搜索词 :param option: 筛选项 :return: """ # 点击首页-查关系tab self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'homeSearch relation n'").click() # 点击输入框 self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.elements["search_box"]).click() # 点击查关系-开始节点输入框 self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '添加第一个公司或老板'").click() # 搜索中间页,输入开始节点 # todo 搜索词做成随机的 self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '输入公司名称、老板姓名、品牌名称等'").send_keys( str(key)) # 点击更多筛选 self.operation.new_element(MobileBy.IOS_PREDICATE, "value = '更多筛选'").click() # 点击-商标 # todo 筛选项做成随机的 self.preprocessing.random_options(find_type=MobileBy.IOS_PREDICATE, find_element="value = '商标'") self.operation.new_element(MobileBy.IOS_PREDICATE, "value = '{}'".format(option)).click() # 点击-确认 self.operation.new_element(MobileBy.IOS_PREDICATE, "value = '确认'").click()
class Preprocessing(): def __init__(self, driver, log=None): if log is None: self.log = Logger("预处理步骤").getlog() else: self.log = log self.driver = driver self.excel = ReadExcel().read_excel("common") self.operation = Operation(driver, self.log) self.by = MobileBy() def skip_guide(self, number=4): """ 跳过引导页 @param number: @return: """ try: for i in range(number): self.operation.mobile_swipe('left') self.log.info("跳过首页引导") except Exception as e: self.log.error(error_format(e)) raise e def agree_license(self): """ 点击用户协议 @return: """ try: element = self.operation.is_element(self.by.IOS_PREDICATE, self.excel['agree_license']) if element: self.operation.new_element( self.by.IOS_PREDICATE, self.excel['agree_license']).click() self.log.info("点击同意用户协议") except Exception as e: self.log.error('点击同意用户协议失败!!!') self.log.error(error_format(e)) raise e def cancel_update(self): """ 跳过 升级弹窗 @return: """ try: element = self.operation.is_element(self.by.IOS_PREDICATE, self.excel['update_title'], outtime=10) if element: self.operation.new_element(self.by.IOS_PREDICATE, self.excel['close_update']).click() self.log.info("跳过升级弹窗") except Exception as e: self.log.error(error_format(e)) raise e def skip_monitor(self): """ 跳过监控日报 @return: """ try: element = self.operation.is_element(self.by.IOS_PREDICATE, self.excel['monitor_title']) if element: self.operation.new_element( self.by.IOS_PREDICATE, self.excel['close_monitor']).click() self.log.info("跳过监控日报") except Exception as e: self.log.error(error_format(e)) raise e def skip_monitor_daily_email(self, select=False, email=None): """ 监控日报相关操作 @param select: @param email: @return: """ if self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, "XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[1]/XCUIElementTypeStaticText[1]" ): if select: if email: self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, "XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1]" ).click() self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, "XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1]" ).send_keys(email) self.operation.new_element(MobileBy.ACCESSIBILITY_ID, "保存").click() else: self.operation.new_element(MobileBy.ACCESSIBILITY_ID, "跳过").click() def back_index(self): """ 回到首页 @return: """ back_count = 0 while back_count < 10: back_count += 1 flag = self.operation.is_element(MobileBy.IOS_CLASS_CHAIN, self.excel['index'].format(1), outtime=1) if flag: self.log.info("已返回到首页") break else: self.log.info("未返回到首页,点击「返回」按钮") self.backtrack() def backtrack(self): """ 返回 @return: """ elements = self.operation.new_elements(MobileBy.IOS_CLASS_CHAIN, self.excel['button']) for element in elements: if element.get_attribute( "visible") == "true" and element.get_attribute('name') in [ 'nav back new', 'App Back' ]: element.click() break def hide_keyboard(self): """ 隐藏键盘 + 搜索 按钮功能 @return: """ self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.excel['search_bar']).send_keys("\n") def clear_text(self): """ 一键清除 按钮 @return: """ self.operation.new_element(MobileBy.ACCESSIBILITY_ID, "清除文本").click() def clear_history(self, select=True): """ 历史 「清空」按钮 @return: """ self.operation.new_element(MobileBy.ACCESSIBILITY_ID, "清空").click() if select: self.operation.new_element(MobileBy.ACCESSIBILITY_ID, "确定").click() else: self.operation.new_element(MobileBy.ACCESSIBILITY_ID, "取消").click() def get_permission(self): """ 获取 所有权限 @return: """ permission = self.operation.new_element(MobileBy.IOS_PREDICATE, self.excel['permission'], outtime=2) if permission is not None: permission.click() self.log.info("获取权限") def is_login(self): """ 判断 登陆状态 @return: """ # 回到首页 self.back_index() # 进入 我的 self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.excel['index'].format(5)).click() # 是否有 登陆 按钮 login_status = self.operation.is_element(MobileBy.ACCESSIBILITY_ID, "立即登录", outtime=3) if login_status: self.log.info("未登录账号") result = not login_status else: self.log.info("已登录账号") result = not login_status return result def login(self, phone_num, password): """" 登录公用方法 @return: """ try: flag = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == '密码登录'") if flag: self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '密码登录'").click() phone = self.operation.is_element(MobileBy.IOS_PREDICATE, "value == '输入手机号'") if phone: self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '输入手机号'").click() else: self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, self.excel['login_phone']).click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '清除文本'").click() self.operation.new_element( MobileBy.IOS_PREDICATE, "value == '输入手机号'").send_keys(phone_num) self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '输入密码'").click() self.operation.new_element( MobileBy.IOS_PREDICATE, "value == '输入密码'").send_keys(password) self.hide_keyboard() self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, self.excel['agreement_button']).click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '登录'").click() element = self.operation.is_element( self.by.IOS_PREDICATE, self.excel['monitor_title']) if element: self.operation.new_element( self.by.IOS_PREDICATE, self.excel['close_monitor']).click() self.log.info("跳过监控日报") else: self.back_index() self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.excel['mytab_button']).click() self.operation.mobile_swipe('down') self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '立即登录'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '密码登录'").click() phone = self.operation.is_element(MobileBy.IOS_PREDICATE, "value == '输入手机号'") if phone: self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '输入手机号'").click() else: self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, self.excel['login_phone']).click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '清除文本'").click() self.operation.new_element( MobileBy.IOS_PREDICATE, "value == '输入手机号'").send_keys(phone_num) self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '输入密码'").click() self.operation.new_element( MobileBy.IOS_PREDICATE, "value == '输入密码'").send_keys(password) self.hide_keyboard() self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, self.excel['agreement_button']).click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '登录'").click() element = self.operation.is_element( self.by.IOS_PREDICATE, self.excel['monitor_title']) if element: self.operation.new_element( self.by.IOS_PREDICATE, self.excel['close_monitor']).click() self.log.info("跳过监控日报") login_status = self.operation.is_element( MobileBy.IOS_PREDICATE, "name == '立即登录'") if login_status is not True: self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, self.excel['index'].format(1)).click() self.log.info("登录成功,并回到首页") except Exception as e: self.log.error(error_format(e)) raise e def logout(self): """ 退出登录 @return: """ flag = self.operation.is_element(MobileBy.IOS_CLASS_CHAIN, self.excel['index'].format(1)) if flag is not True: self.back_index() self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.excel['index'].format(5)).click() login_status = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == '立即登录'") if login_status: self.log.info("已经是未登录状态") else: swip_up_count = 0 while swip_up_count < 4: swip_up_count += 1 elment = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == '设置'") if elment: self.log.info("找到设置按钮") self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.excel['set_icon']).click() break else: self.log.info("未找到设置按钮,继续向上滑") self.operation.mobile_swipe('up') self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '退出'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '确定'").click() swip_down_count = 0 while swip_down_count < 4: swip_down_count += 1 log_stu = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == '立即登录'") if log_stu: self.operation.new_element( MobileBy.IOS_CLASS_CHAIN, self.excel['index'].format(1)).click() self.log.info("已退出登录并回到首页") break else: self.log.info("未找到立即登录按钮,继续向上滑") self.operation.mobile_swipe('down') def enter_monitor_list(self): """ 进入到 我的->监控列表 @return: """ # 返回到「首页」 try: self.back_index() # 点击「我的」 self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.excel['index'].format(5)).click() # 点击「我的监控」 self.operation.new_element(MobileBy.ACCESSIBILITY_ID, '我的监控').click() # 点击「监控列表」 self.operation.new_element(MobileBy.ACCESSIBILITY_ID, '监控列表').click() except Exception as e: self.log.error(error_format(e)) def random_options(self, find_type, find_element, num=None, x=0.03, fromy=0.6, toy=0.5): """ 随机查找一个选项 @param find_type: 查找方法 @param find_element: 查找元素 @param num: 指定第几个筛选项,默认为None,随机选择 @param x: 滑动 x 起始/结束坐标 @param fromy: 滑动 y 起始坐标 @param toy: 滑动 y 结束坐标 @return: 会返回选择项的文本名字 """ groups = self.operation.new_elements(find_type=find_type, find_element=find_element) groups_len = len(groups) if not num is None: random_num = num - 1 else: random_num = random.randint(0, groups_len - 1) self.log.info("随机项下标:{}".format(random_num)) random_name = groups[random_num].text self.log.info("共有 {} 选项,选择第 {} 个:{}".format(groups_len, random_num + 1, random_name)) loop_num = 5 while loop_num > 0: if loop_num == 5: find_groups = groups else: find_groups = self.operation.new_elements( find_type=find_type, find_element=find_element) self.log.info("选项是否可见:{}".format( find_groups[random_num].get_attribute("visible"))) if find_groups[random_num].get_attribute("visible") == "true": if find_groups[random_num].text == random_name: find_groups[random_num].click() return random_name else: raise NoSuchElementException("随机的选项:{},实际要点击的选项:{}".format( random_name, find_groups[random_num].text)) self.operation.mobile_drag_to_duration(fromX=x, fromY=fromy, toX=x, toY=toy) loop_num -= 1 else: raise NoSuchElementException("随机项:{} 未找到".format(random_name))
def __init__(self, driver): self.driver = driver # 获取基础操作 self.operation = Operation(driver)
class RelationProcess: def __init__(self, driver): self.driver = driver # 获取基础操作 self.operation = Operation(driver) self.preprocessing = Preprocessing(driver) relation_operate = RelationOperate(driver) self.elements = relation_operate.get_element() def relation_share(self): """更多操作-分享""" self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relation plus'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relationShip share'").click() share_tag = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == '微信'") self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '取消'").click() return share_tag def relation_save(self): """更多操作-保存""" self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relation plus'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relationShip save'").click() self.preprocessing.get_permission() save_tag = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == '已保存相册'") return save_tag def relation_scan(self): """更多操作-扫一扫""" self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relation plus'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relationShip scan'").click() scan_tag = self.operation.is_element(MobileBy.IOS_CLASS_CHAIN, self.elements["scan"]) self.preprocessing.backtrack() return scan_tag def relation_edit(self): """更多操作-删减""" self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relation plus'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relationShip edit'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '赵薇'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relationShip sure n'").click() edit_tag = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == '赵薇'") return edit_tag def relation_demo(self): """查关系样例,相关操作""" self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'fullScreen n'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'outFullScreen n'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relation clear n'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == '清除所有信息'").click() self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'company logo'").click() home_page_tag = self.operation.is_element(MobileBy.IOS_PREDICATE, "name == 'homeSearch relation n'") return home_page_tag def relation_search(self): """输入查关系节点,相关操作""" # 点击首页-查关系tab self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'homeSearch relation n'").click() # 点击输入框 self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.elements["search_box"]).click() # 点击查关系-开始节点输入框 self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '添加第一个公司或老板'").click() # 搜索中间页,输入开始节点 self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '输入公司名称、老板姓名、品牌名称等'").send_keys("北京金堤科技有限公司") # 选中节点1 self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.elements["first_port"]).click() # 点击查关系-结束节点输入框 self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '添加第二个公司或老板'").click() # 搜索中间页,输入结束节点 self.operation.new_element(MobileBy.IOS_PREDICATE, "value == '输入公司名称、老板姓名、品牌名称等'").send_keys("盐城金堤科技有限公司") # 选中节点2 self.operation.new_element(MobileBy.IOS_CLASS_CHAIN, self.elements["first_port"]).click() # 节点输入完毕,点击查关系按钮 self.operation.new_element(MobileBy.IOS_PREDICATE, "name == 'relation discover n'").click()