Beispiel #1
0
 def main(self):
     """
     生成测试报告主函数
     根据status yaml的文件来生成测试报告
     :return:
     """
     import GetHtml
     self.__analyze_log()
     result = self.__yaml_file(self.all_result_path, '.yaml')
     lst = []
     for case_name, confirm_status in result.items():
         case_name = str(case_name).split('.')[0]
         case_result = self.__open_yaml(confirm_status)
         case_img = self.__confirm_file(
             str(confirm_status).replace('status',
                                         'img').replace('yaml', 'png'))
         case_per = self.__confirm_file(
             str(confirm_status).replace('status',
                                         'per').replace('yaml', 'png'))
         case_log = self.__confirm_file(
             str(confirm_status).replace('status',
                                         'log').replace('yaml', 'log'))
         case_filter = self.__confirm_file(
             str(confirm_status).replace('status', 'log').replace(
                 'yaml', 'log').replace(case_name, case_name + 'filter'))
         if case_per is None:
             # 获取error图片
             ini = U.ConfigIni()
             case_per = ini.get_ini('test_case', 'error_img')
         lst.append(
             GetHtml.get_html_tr(case_name, case_result, case_img, case_per,
                                 case_log, case_filter))
     GetHtml.get_html(''.join(lst), self.__app_info(), self.__device_info(),
                      self.__test_case_execution_status(),
                      self.all_result_path)
Beispiel #2
0
    def main(self):
        """
        开启多线程:
                线程1:安装应用
                线程2:获取当前页面是否有可点击的按钮
        :return:
        """
        ini = U.ConfigIni()
        install_file = ini.get_ini('test_install_path', 'path')
        package_name = ini.get_ini('test_package_name', 'package_name')

        threads = []

        click_button = threading.Thread(target=self.tap_all, args=())
        threads.append(click_button)
        install_app = threading.Thread(
            target=self.__install_app, args=(
                package_name, install_file))
        threads.append(install_app)
        process_list = range(len(threads))

        for i in process_list:
            threads[i].start()
        for i in process_list:
            threads[i].join()

        self.adb.shell('"rm -r /data/local/tmp/*.xml"')
Beispiel #3
0
def case_yaml_file():
    """

    :return: 返回当前设备下的yaml test case列表
    """
    ini = U.ConfigIni()
    yaml_path = ini.get_ini('test_case', 'case')
    return GetFilePath.all_file_path(yaml_path, '.yaml')
Beispiel #4
0
def config_initialize():
    ini = U.ConfigIni()
    ini.set_ini('test_device', 'device',
                project_path + '/data/device_info.yaml')
    ini.set_ini('test_info', 'info',
                project_path + '/data/appium_parameter.yaml')
    ini.set_ini('test_case', 'case_xlsx', project_path + '/data/keyword.xlsx')
    ini.set_ini('test_case', 'report_file', project_path + '/report')
Beispiel #5
0
    def get_apk_name(self):
        dir = os.path.split(__file__)[0].replace('Public', 'Data')

        ini = U.ConfigIni()

        with open(dir + ini.get_ini('apk_info', 'apk_info_path'), 'r') as f:
            apk_name = yaml.load(f)
            f.close()
        return apk_name
Beispiel #6
0
def set_device_yaml():
    device_lst = get_device_detail()
    for device in device_lst:
        L.Logging.success('get device:{},Android Version:{}'.format(
            device['deviceName'], device['platformVersion']))
    ini = U.ConfigIni()
    with open(ini.get_ini('test_device', 'device'), 'w') as f:
        yaml.dump(device_lst, f)
        f.close()
Beispiel #7
0
def clean_device_yaml():
    ini = U.ConfigIni()
    device_yaml = ini.get_ini('test_device','device')
    if os.path.getsize(device_yaml):
        with open(device_yaml,'w') as f:
            f.truncate()
            f.close()
        return
    return
Beispiel #8
0
 def __app_info(self):
     """
     获取应用包名和版本号
     :return:
     """
     ini = U.ConfigIni()
     package_name = ini.get_ini('test_package_name', 'package_name')
     package_name_version = self.adb.specifies_app_version_name(
         package_name)
     return package_name, package_name_version
Beispiel #9
0
def get_device_info():
    device_list = []
    ini = U.ConfigIni()
    test_info = ini.get_ini('test_info', 'info')
    test_device = ini.get_ini('test_device', 'device')
    with open(test_info) as f:
        test_dict = yaml.load(f)
    with open(test_device) as f:
        for device in yaml.load(f):
            device_list.append(dict(test_dict.items() + device.items()))
    return device_list
Beispiel #10
0
def download():
    dir = os.path.split(__file__)[0].replace('Public', 'Data')

    ini = U.ConfigIni()
    apk_path = dir + ini.get_ini('apk_location', 'apk_path')
    print apk_path

    apk_url = ini.get_ini('apk_url', 'apk_jenkins_url')
    apk_name = apk_url.split("/")[-1]
    with open(dir + ini.get_ini('apk_info', 'apk_info_path'), 'w') as f:
        yaml.dump(apk_name, f)
        f.close()
    get_url(apk_url, apk_path)
Beispiel #11
0
 def mkdir_file(self):
     ini = U.ConfigIni()
     result_path = ini.get_ini('test_case', 'log_file')
     result_path_file = result_path + '\\' + self.time
     file_list = [
         result_path, result_path_file, result_path_file + '\log',
         result_path_file + '\per', result_path_file + '\img',
         result_path_file + '\status'
     ]
     if not os.path.exists(result_path):
         os.mkdir(result_path)
     for file_path in file_list:
         if not os.path.exists(file_path):
             os.mkdir(file_path)
     return result_path_file
Beispiel #12
0
    def install(self, package_name):
        dir = os.path.split(__file__)[0].replace('Public', 'Data')

        ini = U.ConfigIni()
        apk_path = dir + ini.get_ini('apk_location', 'apk_path')

        if not os.listdir(apk_path):
            print "please check you apk folder"
        else:
            print self.find_apks()
            if self.find_apks() != []:
                print "find the file"
                self.install_apks(package_name)
            else:
                print "cannot find apk file"
Beispiel #13
0
def initialization_arrangement_case():
    ini = U.ConfigIni()
    ini.set_ini('minicap', 'minicap_path', main_view + '/data/minicap/bin/{}/minicap')
    ini.set_ini('minicap', 'minitouch_path', main_view + '/data/minicap/minitouch/{}/minitouch')
    ini.set_ini('minicap', 'minicapso_path', main_view + '/data/minicap/shared/android-{}/{}/minicap.so')

    ini.set_ini('test_case', 'case', main_view + '/testcase')
    ini.set_ini('test_case', 'log_file', main_view + '/result')
    ini.set_ini('test_case', 'error_img', main_view + '/data/incidental/error.png')

    ini.set_ini('test_device', 'device', main_view + '/data/incidental/device_info.yaml')

    ini.set_ini('test_db', 'test_result', main_view + '/data/incidental/test.db')

    ini.set_ini('test_install_path', 'path', main_view + '/data/app.apk')
    ini.set_ini('test_info', 'info', main_view + '/data/appium_parameter.yaml')
Beispiel #14
0
def get_device_info():
    """
    获取当前电脑连接的devices
    :return: 返回设备列表
    """
    device_list = []
    ini = U.ConfigIni()
    test_info = ini.get_ini('test_info', 'info')
    test_device = ini.get_ini('test_device', 'device')
    with open(test_info) as f:
        test_dic = yaml.load(f)[0]

    with open(test_device) as f:
        for device in yaml.load(f):
            device_list.append(dict(test_dic.items() + device.items()))

    return device_list
Beispiel #15
0
def set_device_yaml():
    """
    获取当前设备的Android version并且保存到yaml里
    :return:
    """
    device_lst = []
    logging = log()
    for device in get_device():
        adb = lib.adbUtils.ADB(device)
        logging.info(
            'get device:{},Android version:{}'.format(
                device, adb.get_android_version()))
        device_lst.append({'platformVersion': adb.get_android_version(
        ), 'deviceName': device, 'platformName': 'Android'})

    ini = U.ConfigIni()
    with open(ini.get_ini('test_device', 'device'), 'w') as f:
        yaml.dump(device_lst, f)
        f.close()
Beispiel #16
0
def set_device_yaml():
    device_lst = []
    for device in get_device():
        adb = lib.adbUtils.ADB(device)
        U.Logging.success('get device:{},Android version:{}'.format(
            device, adb.get_android_version()))
        device_lst.append({
            'platformVersion': adb.get_android_version(),
            'deviceName': device,
            'platformName': 'Android'
        })

        ini = U.ConfigIni()
        dir = os.path.split(__file__)[0].replace('Public', 'Data')

        print dir
        with open(dir + ini.get_ini('test_device', 'device'), 'w') as f:
            yaml.dump(device_lst, f)
            f.close()
Beispiel #17
0
    def mkdir_file(self):
        """
        :return:log folder
        """
        ini = U.ConfigIni()
        result_file = str(ini.get_ini('test_case', 'log_file'))
        result_file_every = result_file + '/' + \
                            time.strftime("%Y-%m-%d_%H_%M_%S{}".format(random.randint(10, 99)),
                                          time.localtime(time.time()))
        file_list = [
            result_file, result_file_every, result_file_every + '/log',
            result_file_every + '/per', result_file_every + '/img',
            result_file_every + '/status'
        ]
        if not os.path.exists(result_file):
            os.mkdir(result_file)

        for file_path in file_list:
            if not os.path.exists(file_path):
                os.mkdir(file_path)
        return result_file_every
Beispiel #18
0
 def __app_info(self):
     ini = U.ConfigIni()
     package_name = ini.get_ini('test_package_name', 'packageName')
     app_version_name = self.adb.get_app_version(package_name)
     return package_name, app_version_name
Beispiel #19
0
    def __analysis_yaml(self, path_yaml):
        """
        测试用例解释器
        :param path_yaml: 测试用例地址
        1:每执行一条用例会记录下当前的性能


        :return:
        """
        adb = lib.adbUtils.ADB(self.device)
        ini = U.ConfigIni()
        package_name = ini.get_ini('test_package_name', 'package_name')
        cpu_list = []
        mem_list = []
        for dic in self.get_all_case(path_yaml):
            U.Logging.success(str(dic))
            if isinstance(dic, dict):
                if 'test_name' in dic:
                    test_name = str(dic['test_name']).decode('utf-8')
                    U.Logging.info('Start the test_case: {}'.format(test_name))
                range_num = 1

                if 'test_range' in dic:
                    # 循环控制
                    # todo:打印循环相关的日志
                    range_num = dic['test_range']

                for i in xrange(0, range_num):
                    if dic['test_action'] == 'click':
                        # 点击
                        test_control = dic['test_control']
                        test_control_type = dic['test_control_type']

                        U.Logging.success('click {}'.format(test_control))

                        self.dash_page.clickButton(
                            (test_control_type, test_control))

                    elif dic['test_action'] == 'send_keys':
                        # 发送文本
                        test_control_type = dic['test_control_type']
                        test_control = dic['test_control']
                        test_text = dic['test_text']

                        U.Logging.success('send {} to {}'.format(
                            test_text, test_control))
                        self.dash_page.send_keys(
                            (test_control_type, test_control), str(test_text))

                    elif 'swipe' in dic['test_action']:
                        # 滑动
                        test_action = dic['test_action']
                        U.Logging.success('{}'.format(test_action))
                        self.dash_page.swipe_all(test_action)

                    elif 'entity' in dic['test_action']:
                        # 实体按键
                        test_action = dic['test_action']
                        U.Logging.success('{}'.format(test_action))
                        self.dash_page.send_key_event(test_action)

                    elif dic['test_action'] == 'assert':
                        # 断言
                        test_wait = 15
                        test_control = dic['test_control']
                        test_control_type = dic['test_control_type']
                        test_text = dic['test_text']
                        if dic.has_key('test_wait'):
                            test_wait = int(dic['test_wait'])

                        U.Logging.success('assert {}'.format(test_control))

                        el = self.dash_page.find_element(
                            (test_control_type, test_control), wait=test_wait)
                        assert el.text == test_text

                    if 'test_sleep' in dic:
                        # 等待
                        sleep = dic['test_sleep']
                        U.Logging.success('Wait {} seconds'.format(sleep))
                        U.sleep(int(sleep))

                    if True:
                        # todo 增加性能的开关判断
                        # U.Logging.success('Obtaining application performance')

                        cpu = adb.get_cpu(package_name)
                        mem = adb.get_mem(package_name)
                        # U.Logging.success('cpu:{}'.format(cpu))
                        # U.Logging.success('mem:{}'.format(mem))
                        cpu_list.append(cpu)
                        mem_list.append(mem)

            else:
                U.Logging.error(
                    'Yaml file format error, the current {}, you need dict'.
                    format(type(dic)))

        historical_per = self.__select_per(
            self.filename,
            self.device,
        )
        self.__save_sql(self.filename, self.device, cpu_list, mem_list, 1)
        if historical_per is not None:
            h_cpu = historical_per[0]
            h_mem = historical_per[1]
            self.__save_cpu_mem(cpu_list, mem_list, h_cpu, h_mem)
        else:
            self.__save_cpu_mem(cpu_list, mem_list, None, None)

        U.Logging.success('cpu_list:{}'.format(cpu_list))
        U.Logging.success('mem_list:{}'.format(mem_list))
        return True
Beispiel #20
0
    def analysis_yaml(self, yaml_path):
        adb = public.adb.adb(self.device)
        ini = U.ConfigIni()
        packageName = ini.get_ini('test_package_name', 'packageName')
        cpu_list = []
        mem_list = []
        for case in self.get_all_case(yaml_path):
            L.Logging.success('get case %s' % str(case))
            if isinstance(case, dict):
                if 'name' in case:
                    test_name = str(case['name']).decode('utf-8')
                    L.Logging.info('Start the test_case: {}'.format(test_name))
                test_range = 1
                if 'range' in case:
                    test_range = case['range']
                for i in xrange(0, test_range):
                    if case['action'] == 'click':
                        test_control_type = case['type']
                        test_control = case['element']
                        L.Logging.success('click {}'.format(test_control))
                        self.driver.clickButton(test_control_type,
                                                test_control)
######(继续写)                   elif case['test_action'] == 'send_keys'
                    elif case['action'] == 'find':
                        test_control_type = case['type']
                        test_control = case['element']
                        L.Logging.success('find {}'.format(test_control))
                        self.driver.find_element(test_control_type,
                                                 test_control)
                    elif case['action'] == 'keyevent':
                        keys = case['keys']
                        self.driver.keyevent(keys)
                        if case.has_key('assert'):
                            verification = case['assert']
                            verifications = []
                            source = self.driver.assertion()
                            for v in verification.split(','):
                                if v:
                                    verifications.append(v)
                            print verifications
                            for ve in verifications:
                                try:
                                    assert source.find(ve) != -1
                                    L.Logging.success('assert {}'.format(ve))
                                except:
                                    raise Exception(
                                        'not found %s in page!!!!' % ve)
                        elif case.has_key('or_assert'):
                            verification = case['or_assert']
                            source = self.driver.assertion()
                            for v in verification.split(','):
                                if v:
                                    verifications.append(v)
                            result = []
                            for ve in verifications:
                                re = source.find(ve)
                                result.append(re)
                            l = len(result)
                            if result.count('-1') == l:
                                raise Exception(
                                    "can't find any element in %s page" %
                                    verification)
                    elif case['action'] == 'assert':
                        verifications = []
                        verification = case['element']
                        source = self.driver.assertion()
                        for v in verification.split(','):
                            if v:
                                verifications.append(v)
                        for ve in verifications:
                            assert source.find(ve) != -1
                            L.Logging.success('assert {}'.format(ve))
Beispiel #21
0
def get_case_yaml_path():
    ini = U.ConfigIni()
    yaml_path = ini.get_ini('test_case', 'case')
    return get_all_case(yaml_path, '.yaml')
Beispiel #22
0
        (output, err) = p.communicate()
        t = output.decode().split()
        for item in t:
            # print(item)
            match = re.compile("application-label:(\S+)").search(item)
            if match is not None:
                return match.group(1)

    def getApkActivity(self):
        p = subprocess.Popen("aapt dump badging %s" % self.apkPath,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             stdin=subprocess.PIPE,
                             shell=True)
        (output, err) = p.communicate()
        match = re.compile("launchable-activity: name=(\S+)").search(
            output.decode())
        if match is not None:
            Activity = match.group(1).strip('\'')
            self.log.info('activityname:{}'.format(Activity))
            return Activity


if __name__ == '__main__':
    ini = U.ConfigIni()
    path = ini.get_ini('test_info', 'info')
    Apk = ApkInfo(get_apkpath())
    package = Apk.getApkPackage()
    activity = Apk.getApkActivity()
    with open(ini.get_ini('test_info', 'info'), 'r') as f:
        print yaml.load(f)[0]