Example #1
0
def _locating_element(
    element,
    waittime,
    action='',
):
    el_location = None
    try:
        el, value = e.get(element)
    except:
        logger.exception(
            'Locating the element:%s is Failure, no element in define' %
            element)
        raise Exception(
            'Locating the element:%s is Failure, no element in define' %
            element)

    wait = WebDriverWait(g.driver, waittime)

    if el['by'].lower() in ('title', 'url', 'current_url'):
        return None
    elif action == 'CLICK':
        el_location = wait.until(
            EC.element_to_be_clickable((getattr(By, el['by'].upper()), value)))
    else:
        logger.debug('locating the element %s' % value)
        el_location = wait.until(
            EC.presence_of_element_located((getattr(By,
                                                    el['by'].upper()), value)))

    return el_location
Example #2
0
    def run(self, sheet_name):
        # 1.从 Excel 获取测试用例集
        try:
            data = self.testcase_workbook.read(sheet_name)
            testsuite = testsuite_format(data)
            # logger.info('Testsuite imported from Excel:\n' +
            #             json.dumps(testsuite, ensure_ascii=False, indent=4))
            logger.info('From Excel import testsuite success')
        except:
            logger.exception('*** From Excel import testsuite fail ***')
            self.code = -1
            sys.exit(self.code)

        # 2.初始化全局对象
        try:
            g.init(self.desired_caps, self.server_url)
            g.set_driver()
            # 如果测试数据文件存在,则从该文件里读取一行数据,赋值到全局变量列表里
            data_file = path.join('data',
                                  g.project_name + '-' + sheet_name + '.csv')
            if path.exists(data_file):
                g.var = get_record(data_file)
            data_file = path.join(
                'data', g.project_name + '-' + sheet_name + '-globle.txt')
            if path.exists(data_file):
                g.var.update(get_all_record(data_file))
            w.init()
        except:
            logger.exception('*** Init global object fail ***')
            self.code = -1
            sys.exit(self.code)

        # 3.解析测试用例集
        try:
            parse(testsuite)
            logger.debug('testsuite has been parsed:\n' + str(testsuite))
        except:
            logger.exception('*** Parse testsuite fail ***')
            self.code = -1
            sys.exit(self.code)

        # 4.执行测试套件
        ts = TestSuite(testsuite, self.report_ts[sheet_name], self.conditions)
        ts.run()

        # 5.判断测试结果
        if self.report_ts[sheet_name].high_errors + self.report_ts[sheet_name].medium_errors + \
                self.report_ts[sheet_name].high_failures + self.report_ts[sheet_name].medium_failures:
            self.code = -1

        # 6.保存测试结果
        try:
            self.report_data[sheet_name] = testsuite2report(testsuite)
            data = testsuite2data(testsuite)
            self.report_workbook.write(data, sheet_name)
        except:
            logger.exception('*** Save the report is fail ***')
Example #3
0
 def switch_context(self, context):
     if context.strip() == '':
         context = 'NATIVE_APP'
     logger.debug('--- ALL   Contexts:%s' % g.driver.contexts)
     logger.debug('--- Input  Context:%s' % repr(context))
     if context != self.current_context:
         if context == '':
             context = None
         logger.info('--- Switch Context:%s' % repr(context))
         g.driver.switch_to.context(context)
         self.current_context = context
Example #4
0
    def run(self, sheet_name):
        # 1.从 Excel 获取测试用例集
        try:
            data = self.testcase_workbook.read(sheet_name)
            testsuite = testsuite_format(data)
            # logger.info('Testsuite imported from Excel:\n' +
            #             json.dumps(testsuite, ensure_ascii=False, indent=4))
            logger.info('From Excel import testsuite success')
        except:
            logger.exception('*** From Excel import testsuite failure ***')
            self.code = -1
            sys.exit(self.code)

        # 2.初始化全局对象
        try:
            g.set_driver()
            # 如果测试数据文件存在,则从该文件里读取数据,赋值到全局变量列表里
            data_file = Path('data') / (g.plan_name + '-' + sheet_name +
                                        '.csv')
            if data_file.is_file():
                g.test_data = get_record(str(data_file))
            w.init()
        except:
            logger.exception('*** Init global object failure ***')
            self.code = -1
            sys.exit(self.code)

        # 3.解析测试用例集
        try:
            parse(testsuite)
            logger.debug('testsuite has been parsed:\n' + str(testsuite))
        except:
            logger.exception('*** Parse testsuite failure ***')
            self.code = -1
            sys.exit(self.code)

        # 4.执行测试套件
        g.ts = TestSuite(testsuite, sheet_name, self.junit_suite[sheet_name],
                         self.conditions)
        g.ts.run()

        # 5.判断测试结果
        if self.junit_suite[sheet_name].high_errors + self.junit_suite[sheet_name].medium_errors + \
                self.junit_suite[sheet_name].high_failures + self.junit_suite[sheet_name].medium_failures:
            self.code = -1

        # 6.保存测试结果
        try:
            data = testsuite2data(testsuite)
            self.report_workbook.write(data, sheet_name)
            self.report_data[sheet_name] = testsuite2report(testsuite)
        except:
            logger.exception('*** Save the report is failure ***')