示例#1
0
    def __if_acceaaibilityid_predicate(self,
                                       locate,
                                       operate=None,
                                       text=None,
                                       el=None,
                                       index=None):
        """
        * 私有不继承
        判断 accessibilityid执行操作
        :param locate:  表达 或者定位元素
        :param operate: 执行操作 类型input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本) , slide(滑动)
        :param text: 输入文本内容
        :param el: 输入文本内容

        :return:
        """
        if operate is None:

            return self.accessibility_id(locate=locate, el=el)
        if operate in ('text', 'click', 'input', 'clear',
                       'clear_continue_input', 'slide'):
            if operate == 'text':  # 提取文本、多个时需要传递index 参数

                self.accessibility_id_text(locate=locate, el=el, index=index)

            elif operate == 'click':  # 点击操作 、多个时需要传递index 参数

                self.accessibility_id_click(locate=locate, el=el, index=index)

            elif operate == 'input':  # 输入操作 、 多个时需要传递index 参数
                if text is not None:
                    self.accessibility_id_input(locate=locate,
                                                text=text,
                                                el=el,
                                                index=index)
                logger.error('accessibility_id_input 函数必须传递 text 参数')

            elif operate == 'clear':  # 清除操作

                self.accessibility_id_clear(locate=locate, el=el, index=index)

            elif operate == 'clear_continue_input':  # 清除后在输入操作
                if text is not None:
                    self.accessibility_id_clear_continue_input(locate=locate,
                                                               text=text,
                                                               el=el,
                                                               index=index)

            elif operate == 'slide':  # 滑动操作
                if index is None:
                    index = 1
                self.scroll_page_one_time(direction=locate, swipe_times=index)

        else:
            logger.error(
                f""" accessibilityid不支持输入参数{operate}!! 目前只支持:input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)、
                slide(滑动) """)
        raise ErrorExcep(
            f""" accessibilityid不支持输入参数{operate}!! 目前只支持:input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)、
                slide(滑动) """)
示例#2
0
文件: run.py 项目: ruiyi0508/web-ui
    def receiving_argv(cls):
        """
        接收系统输入参数   1模块名称 2线程数据 3失败重跑次数 4生成结果目录名称  Python run.py all 1 1 demo
        :return:
        """
        # 1模块名称
        try:
            module_name = sys.argv[1]
            mlist = None
            if ',' in module_name:
                mlist = module_name.split(',')

            # 2线程数据
            thread_num = sys.argv[2]

            # 3失败重跑次数
            reruns = sys.argv[3]

            # 4 生成结果目录名称
            results_dir = sys.argv[4]

            if int(thread_num) <= 0 or int(thread_num) is None:
                thread_num = 1
            if int(reruns) <= 0 or int(reruns) is None:
                reruns = 1
            return results_dir, module_name, mlist, thread_num, reruns
        except Exception as e:
            logger.error(e)
            raise ErrorExcep('输入参数错误!')
示例#3
0
 def setup(self):
     try:
         webdrivers = webdriver.Remote("http://" + APIUMHOST + "/wd/hub", self.decide_appos)
         return webdrivers
     except Exception as e:
         logger.error(f'初始app失败 {e}')
         raise ErrorExcep("初始app失败!!!!")
示例#4
0
    def __if_commonly_used_predicate(self,
                                     types,
                                     locate,
                                     operate=None,
                                     text=None,
                                     el=None,
                                     index=None):
        """
        * 私有方法不继承
        判断 CommonlyUsed 执行操作
        :param locate:  表达 或者定位元素
        :param operate: 执行操作 类型input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本) ,
        :param text: 输入文本内容
        :param el: 输入文本内容
        :return:
        """
        if operate is None:
            return self.used_operate(types=types, locate=locate, el=el)

        if operate in ('text', 'click', 'input', 'clear',
                       'clear_continue_input'):
            if operate == 'text':  # 提取文本
                return self.used_text(types=types,
                                      locate=locate,
                                      el=el,
                                      index=index)

            elif operate == 'click':  # 点击操作
                self.used_click(types=types, locate=locate, el=el, index=index)

            elif operate == 'input':  # 输入操作
                if text is not None:
                    return self.used_input(types=types,
                                           locate=locate,
                                           text=text,
                                           el=el,
                                           index=index)
                logger.error(' 函数必须传递 text 参数')

            elif operate == 'clear':  # 清除操作
                return self.used_clear(types=types,
                                       locate=locate,
                                       el=el,
                                       index=index)

            elif operate == 'clear_continue_input':  # 清除后在输入操作
                if text is not None:
                    return self.used_clear_continue_input(types=types,
                                                          locate=locate,
                                                          text=text,
                                                          el=el,
                                                          index=index)
                logger.info(' 函数必须传递 text 参数')
        else:
            logger.error(f'输入的{operate}暂时不支持此操作!!!')
            logger.error("""
        目前只支持类型 : input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本) 
            """)
            raise ErrorExcep(f'输入的{operate}暂时不支持此操作!!!')
示例#5
0
    def setup():
        try:
            caps = CAPA
            webdrivers = webdriver.Remote("http://" + APIUMHOST + ":" + APIUMPORT + "/wd/hub", caps)

            return webdrivers
        except Exception as e:
            logger.error(f'初始app失败 {e}')
            raise ErrorExcep("初始app失败!!!!")
示例#6
0
 def get_case(self, yaml_names=None, case_names=None):
     """
     获取用例数据
     :param yaml_names: ymal 路径
     :param case_names:  用例名称
     :return:
     """
     if yaml_names is not None:
         d = GetCaseYmal(yaml_name=yaml_names, case_name=case_names)
         return d
     else:
         raise ErrorExcep('yaml路径不能为空!')
示例#7
0
    def waitForElement(self, types, locate):
        """
        等待元素被加载  配合 isElementExist 函数检查元素是否存在
        :param types: 定位类型  used_operate 函数传递过来
        :param locate:  定位器
        :return:
        """
        timeout = IMPLICITLY_WAIT_TIME
        poll = POLL_FREQUENCY
        try:
            wait = WebDriverWait(self.driver, timeout, poll_frequency=poll)

            element = wait.until(
                EC.presence_of_element_located((types, locate)))
            logger.info(f'等待页面元素 {locate} {types}  存在')
            return element
        except Exception:
            logger.error('等待元素错误,元素在等待时间内未出现!')
            raise ErrorExcep('等待元素错误,元素在等待时间内未出现!')
示例#8
0
    def web_expression(self,
                       types,
                       locate,
                       operate=None,
                       text=None,
                       el=None,
                       index=None,
                       notes=None):
        """
        web 执行操作判断
        :param types: 定位类型
        :param locate: 表达 或者定位元素
        :param operate: 执行操作  input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)  * 只支持 5种
        :param text : 输入文本内容
        :param el: 单个/多个  默认 el=None 单个  / 如果 el = 's' 代表多个
        :param index:

        :param notes: 帮助说明 /说明此步骤
        :return:
        """

        if types in ('id', 'name', 'xpath', 'css', 'class', 'link', 'partlink',
                     'tag'):
            logger.info(notes)
            return self.__if_commonly_used_predicate(
                types=types,
                locate=locate,
                operate=operate,
                text=text,
                el=el,
                index=index,
            )

        else:
            logger.error(f'输入的{types}操作类型,暂时不支持!!')
            logger.error(
                """只支持 id,name,xpath,css,class,link,partlink,tag 定位方式""")
            raise ErrorExcep(f'输入的{types}操作类型,暂时不支持!!')
示例#9
0
    def get_by_type(self, types):
        """
        获取定位类型  目前 app 只提供了 ,
        *安卓 (id(resource-id), class(ClassName) , xpath,)
        *iso (xpath, class(type) ,cont_name(name) , )
        :param types:  str
        :return:  False
        """
        types = types.lower()
        if types == "id":
            if PLATFORMNAME.lower() == 'android':
                logger.warning('此方法只支持android系统,ios不支持建议更换定位方式!!')
                return By.ID
            else:
                logger.error(f'{PLATFORMNAME} 不支持id定位')
        elif types == "xpath":
            return By.XPATH
        elif types == "class":
            return By.CLASS_NAME
        else:
            logger.info(f"Locator type {types} not correct/supported")

        raise ErrorExcep(f'不支持输入类型参数{types}!!!')
示例#10
0
    def if_operate_ios_predicate(self,
                                 locate,
                                 operate=None,
                                 text=None,
                                 el=None,
                                 index=None,
                                 wait=0.5):
        """
        判断 ios_predicate操作执行
         :param expression:  表达 或者定位元素
        :param operate: 执行操作、 类型input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本) , slide(滑动)
        :param text: 输入文本内容
        :param el:  单个/多个  默认 el=None 单个  / 如果 el = 's' 代表多个
        :param index:
         android_uiautomator_click 、android_uiautomator_text、android_uiautomator_input、android_uiautomator_clear、
         列表索引位置  find_element传递时 此值必填
         scroll_page_one_time index 传递滑动次数
        :param wait: 默认 等待0.5 秒
        :return:
        """
        if operate is None:
            time.sleep(wait)
            return self.ios_predicate(locate=locate, el=el)

        elif operate == 'text':  # 提取文本
            time.sleep(wait)
            return self.ios_predicate_text(locate=locate, el=el, index=index)

        elif operate == 'click':  # 点击操作
            time.sleep(wait)
            return self.ios_predicate_click(locate=locate, el=el, index=index)

        elif operate == 'input':  # 输入操作
            if text is not None:
                time.sleep(wait)
                self.ios_predicate_input(locate=locate,
                                         text=text,
                                         el=el,
                                         index=index)
            logger.error('ios_predicate_input 函数必须传递 text 参数')

        elif operate == 'clear':  # 清除操作
            time.sleep(wait)
            self.ios_predicate_clear(locate=locate, el=el, index=index)

        elif operate == 'clear_continue_input':  # 清除后在输入操作
            time.sleep(wait)
            self.ios_predicate_clear_continue_input(locate=locate,
                                                    text=text,
                                                    el=el,
                                                    index=index)

        elif operate == 'slide':  # 滑动操作
            if index is None:
                index = 1
            self.scroll_page_one_time(direction=locate, swipe_times=index)
        else:
            logger.error(
                f""" 不支持输入参数{operate}!! 目前只支持:input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)、
                slide(滑动) """)
            raise ErrorExcep(
                f""" 不支持输入参数{operate}!! 目前只支持:input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)、
                    slide(滑动) """)
示例#11
0
    def if_commonly_used_predicate(self,
                                   types,
                                   locate,
                                   operate=None,
                                   text=None,
                                   el=None,
                                   index=None,
                                   wait=0.5):
        """
        判断 CommonlyUsed 执行操作
        :param locate:  表达 或者定位元素
        :param operate: 执行操作 类型input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本) , slide(滑动)
        :param text: 输入文本内容
        :param el: 输入文本内容
        :param wait: 默认 等待0.5 秒
        :return:
        """
        if operate is None:
            time.sleep(wait)
            return self.used_operate(types=types, locate=locate, el=el)

        elif operate == 'text':  # 提取文本
            time.sleep(wait)
            return self.used_text(types=types,
                                  locate=locate,
                                  el=el,
                                  index=index)

        elif operate == 'click':  # 点击操作
            time.sleep(wait)
            self.used_click(types=types, locate=locate, el=el, index=index)

        elif operate == 'input':  # 输入操作
            if text is not None:
                time.sleep(wait)
                return self.used_input(types=types,
                                       locate=locate,
                                       text=text,
                                       el=el,
                                       index=index)
            logger.error('android_uiautomator_input 函数必须传递 text 参数')

        elif operate == 'clear':  # 清除操作
            time.sleep(wait)
            return self.used_clear(types=types,
                                   locate=locate,
                                   el=el,
                                   index=index)

        elif operate == 'clear_continue_input':  # 清除后在输入操作
            if text is not None:
                time.sleep(wait)
                return self.used_clear_continue_input(types=types,
                                                      locate=locate,
                                                      text=text,
                                                      el=el,
                                                      index=index)
            logger.info(
                'android_uiautomator_clear_continue_input 函数必须传递 text 参数')

        elif operate == 'slide':  # 滑动操作
            if index is None:
                index = 1
            self.scroll_page_one_time(direction=locate, swipe_times=index)
        else:
            logger.error(
                f""" 不支持输入参数{operate}!! 目前只支持:input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)、
               """)
            raise ErrorExcep(
                f""" 不支持输入参数{operate}!! 目前只支持:input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)、
               """)
示例#12
0
    def app_expression(self,
                       types,
                       locate,
                       operate=None,
                       text=None,
                       el=None,
                       index=None,
                       wait=0.5):
        """
        app  执行操作判断
        安卓 ios 表达式定位方法  (uiautomator(安卓) / ios_predicate(ios)  accessibilityid(安卓/ios))
        :param types: 定位类型
        :param locate: 表达 或者定位元素
        安卓  'new UiSelector().text("显示")'
        iOS  "type == 'XCUIElementTypeButton' AND value == 'ClearEmail'"
        :param operate: 执行操作  input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本) , slide(滑动)   * 只支持 6种
        :param text : 输入文本内容
        :param el: 单个/多个  默认 el=None 单个  / 如果 el = 's' 代表多个
        :param index:
        :param wait: 默认 等待0.5 秒
        :return:
        """
        # 只支持安卓
        if PLATFORMNAME.lower() == 'android' and types == 'uiautomator':
            logger.warning('此方法只支持android系统!!')
            return self.if_android_operate_uiautomator(locate=locate,
                                                       operate=operate,
                                                       text=text,
                                                       el=el,
                                                       index=index,
                                                       wait=wait)

        # 只支持 iso
        elif PLATFORMNAME.lower() == 'ios' and types == 'ios_predicate':
            logger.warning('此方法只支持ios系统!!')
            return self.if_operate_ios_predicate(locate=locate,
                                                 operate=operate,
                                                 text=text,
                                                 el=el,
                                                 index=index,
                                                 wait=wait)

        elif types == 'accessibilityid':
            return self.if_acceaaibilityid_predicate(locate=locate,
                                                     operate=operate,
                                                     text=text,
                                                     el=el,
                                                     index=index,
                                                     wait=wait)

        elif types in ('xpath', 'class', 'id'):
            return self.if_commonly_used_predicate(types=types,
                                                   locate=locate,
                                                   operate=operate,
                                                   text=text,
                                                   el=el,
                                                   index=index,
                                                   wait=wait)
        else:

            logger.error(f"""输入的{operate}操作类型,暂时不支持!!
            uiautomator 、ios_predicate 、accessibilityid、xpath、class、id 定位类型
            """)
            raise ErrorExcep(f"""输入的{operate}操作类型,暂时不支持!!
            uiautomator 、ios_predicate 、accessibilityid、xpath、class、id 定位类型
            """)
示例#13
0
    def __if_operate_ios_predicate(self,
                                   locate,
                                   operate=None,
                                   text=None,
                                   el=None,
                                   index=None):
        """
        * 私有不继承
        判断 ios_predicate操作执行
        :param locate:  expression 表达式 如 :ios_predicate  name=="个人统计"
        :param operate: 执行操作、 类型input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本) , slide(滑动)
        :param text: 输入文本内容
        :param el:  单个/多个  默认 el=None 单个  / 如果 el = 's' 代表多个
        :param index:
         android_uiautomator_click 、android_uiautomator_text、android_uiautomator_input、android_uiautomator_clear、
         列表索引位置  find_element传递时 此值必填
         scroll_page_one_time index 传递滑动次数
        :return:
        """
        if operate is None:

            return self.ios_predicate(locate=locate, el=el)
        if operate in ('text', 'click', 'input', 'clear',
                       'clear_continue_input', 'slide'):
            if operate == 'text':  # 提取文本

                return self.ios_predicate_text(locate=locate,
                                               el=el,
                                               index=index)

            elif operate == 'click':  # 点击操作

                return self.ios_predicate_click(locate=locate,
                                                el=el,
                                                index=index)

            elif operate == 'input':  # 输入操作
                if text is not None:
                    self.ios_predicate_input(locate=locate,
                                             text=text,
                                             el=el,
                                             index=index)
                logger.error('ios_predicate_input 函数必须传递 text 参数')

            elif operate == 'clear':  # 清除操作

                self.ios_predicate_clear(locate=locate, el=el, index=index)

            elif operate == 'clear_continue_input':  # 清除后在输入操作

                self.ios_predicate_clear_continue_input(locate=locate,
                                                        text=text,
                                                        el=el,
                                                        index=index)

            elif operate == 'slide':  # 滑动操作
                if index is None:
                    index = 1
                self.scroll_page_one_time(direction=locate, swipe_times=index)
        else:
            logger.error(
                f""" ios_predicate不支持输入参数{operate}!! 目前只支持:input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)、
                slide(滑动) """)
            raise ErrorExcep(
                f""" ios_predicate不支持输入参数{operate}!! 目前只支持:input(输入) , clear(清除) , clear_continue_input(清除在输入) 、click(点击) ,text(提取文本)、
                    slide(滑动) """)