Exemplo n.º 1
0
 def except_error(self, msg, is_applet=True):
     if is_applet:
         AppletUtil.switch_operate(self.driver,  switch_to_app=True)
     self._fail(self.test.failureException(
         '{0}\n{1}  line:{2}'.format(msg, str(sys._getframe().f_back.f_code.co_filename),
                                     str(sys._getframe().f_back.f_lineno))))
     if is_applet:
         AppletUtil.switch_operate(self.driver)
 def app_page_login_account(self, phone, clear_length=0):
     """登陆账号"""
     AppletUtil.switch_operate(self.driver, switch_to_app=True)
     if clear_length:
         for x in range(clear_length):
             self.keyboard_num('d').click()
     for x in (list(str(phone))):
         self.keyboard_num(x).click()
         time.sleep(0.5)
     AppletUtil.switch_operate(self.driver)
 def handle_alert_tip(self, allow=True):
     """微信弹框页面处理"""
     AppletUtil.switch_operate(self.driver, switch_to_app=True)
     alert_tip = self.wait_check_access_alert_tip_page() or self.wait_check_bind_phone_tip_page()
     if not alert_tip:
         print('未发现弹框提示')
     else:
         print(alert_tip.text)
         self.alert_confirm_btn().click() if allow else self.alert_cancel_btn().click()
         time.sleep(3)
         AppletUtil.switch_operate(self.driver)
 def handle_request_access(self, allow=True):
     """权限申请页面处理过程"""
     AppletUtil.switch_operate(self.driver, switch_to_app=True)
     alert_tip = self.wait_check_request_access_tip_page()
     if not alert_tip:
         print('未发现申请权限提示')
     else:
         print(alert_tip.text)
         self.allow_request_btn().click if allow else self.cancel_request_btn().click()
         time.sleep(3)
     AppletUtil.switch_operate(self.driver)
 def enter_into_applet_operate(self):
     """进入小程序主要步骤"""
     if self.wait_check_wechat_home_page():
         print('微信主页面')
         self.screen_swipe_down(0.5, 0.2, 0.9, 1000)
         if self.wait_check_applets_list_page():
             ele = self.applet_icon()
             if ele:
                 ele[0].click()
                 time.sleep(5)
                 AppletUtil.switch_operate(self.driver)
             else:
                 raise Exception('未发现小程序图标')
 def app_page_login_password(self, password, assert_text=None, is_check=False, clear_length=0):
     """登陆密码"""
     AppletUtil.switch_operate(self.driver, switch_to_app=True)
     # password_ele = self.password_input_empty_ele() or self.password_input_no_empty_ele()
     if clear_length:
         for x in range(clear_length):
             os.system("adb shell input keyevent 67")
     os.system("adb shell input text {}".format(password))
     if is_check:
         self.login_btn().click()
         if not Toast().find_toast(assert_text):
             self.base_assert.except_error("账号格式错误, 未发现提示 %s" % assert_text)
         else:
             print(assert_text, '\n')
     else:
         self.login_btn().click()
     AppletUtil.switch_operate(self.driver)
 def share_image_operate(self):
     share_btn = self.share_friend_btn() or self.share_btn()
     share_btn.click()
     time.sleep(2)
     AppletUtil.switch_operate(self.driver, switch_to_app=True)
     if not self.wechat.wait_check_select_friend_page():
         self.base_assert.except_error('点击分享给好友按钮, 未进入微信选择好友页面')
     self.wechat.wechat_back_up_btn().click()
     AppletUtil.switch_operate(self.driver)
     # 生成报告按钮检验
     generate_report_btn = self.generate_report_btn(
     ) or self.share_and_generate_report_btn()
     generate_report_btn.click()
     if not self.wait_check_report_page():
         self.base_assert.except_error('点击生成海报按钮, 未出现海报页面')
     else:
         self.save_img_btn().click()
         self.wechat.handle_request_access()
         if not self.wait_check_save_success_page():
             self.base_assert.except_error('点击保存并分享按钮, 未弹出保存成功信息')
         else:
             print(self.success_info().text)
             self.success_ok_btn().click()
 def get_wait_check_page_ele(self,
                             locator,
                             single=True,
                             applets=True,
                             timeout=10):
     """
         页面检查点判断方法
         :param locator 定位方法
         :param single  是否是list
         :param applets 是否是小程序页面
         :param timeout 超时时间
         :return 返回元素或者 False
     """
     try:
         if single:
             ele = WebDriverWait(
                 self.driver, timeout,
                 0.5).until(lambda x: x.find_element(*locator))
         else:
             ele = WebDriverWait(
                 self.driver, timeout,
                 0.5).until(lambda x: x.find_elements(*locator))
         return ele
     except Exception as e:
         if applets:
             try:
                 current_title = self.driver.title
                 if ':INVISIBLE' in current_title:
                     AppletUtil.switch_to_active_applet_window(self.driver)
                     return self.get_wait_check_page_ele(locator,
                                                         single=single)
                 return False
             except Exception as e:
                 AppletUtil.switch_to_active_applet_window(self.driver)
                 return self.get_wait_check_page_ele(locator, single=single)
         else:
             return False
def switch_app_catch_pic():
    driver = BasePage().get_driver()
    if IS_APPLET:
        AppletUtil.switch_operate(driver, switch_to_app=True)