Example #1
0
 def __init__(self):
     self.info = Information()
     self.my_andriod_poco = MyPocoObject()
     self.eg = EntryGame()
     self.phone_name = self.info.get_phone_name()
     self.use_name = self.info.get_config("Account_Number", "YzTest2")
     self.game_name = self.info.get_config("App_Name", "game_name")
     # 获取设备型号
     self.high = self.info.get_config("Phone_Model", "high")
     self.medium = self.info.get_config("Phone_Model", "medium")
     self.low = self.info.get_config("Phone_Model", "low")
     self.test = self.info.get_config("Phone_Model", "test")
     self.high_touch_x = self.info.get_config("Coordinate", "high_start_x")
     self.high_touch_y = self.info.get_config("Coordinate", "high_start_y")
     self.medium_touch_x = self.info.get_config("Coordinate", "medium_start_x")
     self.medium_touch_y = self.info.get_config("Coordinate", "medium_start_y")
     self.low_touch_x = self.info.get_config("Coordinate", "low_start_x")
     self.low_touch_y = self.info.get_config("Coordinate", "low_start_y")
     self.test_touch_x = self.info.get_config("Coordinate", "test_start_x")
     self.test_touch_y = self.info.get_config("Coordinate", "test_start_y")
     self.high_end_x = self.info.get_config("Coordinate", "high_end_x")
     self.high_end_y = self.info.get_config("Coordinate", "high_end_y")
     self.medium_end_x = self.info.get_config("Coordinate", "medium_end_x")
     self.medium_end_y = self.info.get_config("Coordinate", "medium_end_y")
     self.low_end_x = self.info.get_config("Coordinate", "low_end_x")
     self.low_end_y = self.info.get_config("Coordinate", "low_end_y")
     self.test_end_x = self.info.get_config("Coordinate", "test_end_x")
     self.test_end_y = self.info.get_config("Coordinate", "test_end_y")
     self.game_name = self.info.get_config("App_Name", "game_name")
 def __init__(self):
     self.info = Information()
     self.game_name = self.info.get_config("App_Name", "game_name")
     if self.game_name == "com.youzu.test.qa":
         pass
     else:
         pass
 def __init__(self):
     """
     在if、elif结构中初始化对象
     """
     self.info = Information()
     self.my_poco = MyPocoObject()
     self.game_name = self.info.get_config("App_Name", "game_name")
     if self.game_name == "com.youzu.test.qa":
         self.rgss2 = ResourceGmSs2()
     else:
         pass
Example #4
0
 def __init__(self):
     """
     初始化点击类、信息类、性能类
     """
     self.my_poco = MyPocoObject()
     self.info = Information()
     self.xn = YzTest2Performance()
     self.eg = EntryGame()
     self.fg = Fight()
     self.rg = ResourceGm()
     self.na = NewAccount()
     self.sp = Protocol()
     self.mrc = MyRunCase()
class NewAccountSs2:
    def __init__(self):
        self.info = Information()
        self.rg = ResourceGm()
        self.my_poco = MyPocoObject()
        self.game_name = self.info.get_config("App_Name", "game_name")

    def new_account_ss2(self, resource_dic_input, sever_name_input, play_dic):
        """
        ss2的创建一个符合要求的账号,时间戳账号记录在config.ini.new_game_account字段
        :param dic_input: 字典,账号的数据
        :param sever_name_input: 区服名
        :return:
        """
        home()
        stop_app(self.game_name)
        sleep(2)
        start_app(self.game_name)
        sleep(10)
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        newUser = str(int(time.time()))[3:]  # 时间戳截取账号
        self.info.set_config("Account_Number", "new_game_account",
                             newUser)  # 记录账号
        self.my_poco.find_poco("InputName", find_type="name")
        text(newUser)
        self.my_poco.find_poco("确 认")
        self.my_poco.find_poco("公 告",
                               click_name="AnnoCloseBtn",
                               click_type="name")
        self.my_poco.find_poco("点击选服")
        self.my_poco.find_poco(
            self.poco("List_kind_server").child(text="11 - 20区"),
            find_type="obj",
            click_list=[0.95, 0.15])  # todo 不同游戏可能要改
        sever_name = self.info.get_config("Sever_Name", sever_name_input)
        self.my_poco.find_poco(
            self.poco("List_server").offspring(text=sever_name),
            find_type="obj")
        self.my_poco.find_poco("Txt_guide", find_type="name")  # 关闭新手引导
        self.my_poco.find_poco("Btn_login", find_type="name")  # 开始游戏
        sleep(5)
        self.my_poco.find_poco("进入游戏")  # 创建角色
        sleep(15)
        self.rg.add_resource(resource_dic_input)  # 添加资源
        if "副本" in play_dic.keys():
            self.rg.set_play_fuben_num(play_dic["副本"])
        if "列传" in play_dic.keys():
            self.rg.set_play_liezhuan_num(play_dic["列传"])
        stop_app(self.game_name)  # 操作完毕后关闭游戏
class UnexpectedWin:
    def __init__(self):
        self.info = Information()
        self.game_name = self.info.get_config("App_Name", "game_name")

    def set_poco(self, poco_input):
        """
        :param poco_input: 用于设置和切换不同的poco对象
        :return:
        """
        self.poco = poco_input

    def unexpected_win(self):
        """
        异常弹窗跳过,区分不同的游戏走不同的逻辑
        :param poco_input: poco对象
        :return:
        """

        if self.game_name == "com.youzu.wgame2":
            sxuw = UnexpectedWinSx()
            sxuw.sx_unexpected_win()
        elif self.game_name == "com.youzu.test.qa":
            ss2uw = UnexpectedWinSs2()
            ss2uw.set_poco(self.poco)
            ss2uw.ss2_unexpected_win()
        else:
            pass
Example #7
0
class Fight:
    """
    后续需要废弃,改为gm后台发送经验进行升级,不需要循环打副本
    """
    def __init__(self):
        self.info = Information()
        self.game_name = self.info.get_config("App_Name", "game_name")

    def to_fight(self, sections_name, find_type1, click_name1, ynlist1,
                 click_type1, number_of_times, find_level):
        """
        重复战斗功能,用于练级等需要手动提升等级的操作
        :param 参数列表同find_poco,但不含click_list
        :param number_of_times: 战斗几次
        :param find_level: 到什么等级停止
        :return:
        """
        if self.game_name == "com.youzu.test.qa":
            fgss2 = FightSs2()
            fgss2.ss2_fight(sections_name, find_type1, click_name1, ynlist1,
                            click_type1, number_of_times, find_level)
        elif self.game_name == "com.youzu.wgame2":
            fgsx = FightSx()
            fgsx.sx_fight(sections_name, find_type1, click_name1, ynlist1,
                          click_type1, number_of_times, find_level)

        else:
            pass
class EntryGameSx:
    def __init__(self):
        self.info = Information()
        self.my_poco = MyPocoObject()
        self.game_name = self.info.get_config("App_Name", "game_name")
        self.sever_poco = self.info.get_config("Sever_poco", self.game_name)

    def entry_game_sx(self, sever_name_input, game_account_input):
        """
        sx的登录游戏,游戏已经启动,到游戏主界面的操作
        :param sever_name_input: 服务器名称,和ini中一致
        :param game_account_input: 需要登录的账号,和ini中一致
        :return:
        """
        poco = StdPoco()
        self.my_poco.set_poco(poco)
        game_account = self.info.get_config("Account_Number",
                                            game_account_input)
class EntryGame:
    def __init__(self):

        self.info = Information()
        self.game_name = self.info.get_config("App_Name", "game_name")
        self.sever_poco = self.info.get_config("Sever_poco", self.game_name)

    def open_game(self, sever_name_input, game_account_input):
        """
        启动游戏并到游戏主界面,返回一个poco对象,用于用例使用
        :return:
        """
        snapshot(msg="上个脚本结束画面")
        home()
        stop_app(self.game_name)
        sleep(2)
        start_app(self.game_name)
        sleep(20)
        poco = self.entry_game(sever_name_input, game_account_input)
        return poco

    def close_game(self):
        """关闭游戏"""
        snapshot(msg="关闭游戏")
        stop_app(self.game_name)

    # 接口方法,后期拓展游戏使用
    def entry_game(self, sever_name_input, game_account_input):
        """
        登录游戏,从游戏启动到进入游戏主界面的一系列操作
        :return:poco
        """
        if self.game_name == "com.youzu.test.qa":  # ss2
            egss2 = EntryGameSs2()
            poco = egss2.entry_game_ss2(sever_name_input, game_account_input)
            return poco
        elif self.game_name == "com.youzu.wgame2":
            egsx = EntryGameSx()
            poco = egsx.entry_game_sx(sever_name_input, game_account_input)
            return poco
        else:
            pass
Example #10
0
class FightSs2:
    def __init__(self):
        self.info = Information()
        self.my_poco = MyPocoObject()
        self.game_name = self.info.get_config("App_Name", "game_name")
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)

    def ss2_fight(self, sections_name, find_type1, click_name1, ynlist1,
                  click_type1, number_of_times, find_level):

        # 循环
        for i in range(number_of_times):
            # 开始点击战斗之前,判断体力是否足够
            physical_strength_str = self.poco("Comp_res1").child(
                "Label_vit").get_text()
            physical_strength_int = int(physical_strength_str)
            if physical_strength_int <= 10:
                self.my_poco.find_poco(
                    self.poco("Comp_res1").child("Label_vit"), find_type="obj")
                tld_str = self.poco("Comp_base").child("Txt_Num").get_text()
                tld_int = int(tld_str)
                if tld_int == 0:
                    self.my_poco.find_poco("购 买")
                    self.my_poco.find_poco("购 买")
                else:
                    self.my_poco.find_poco("使 用")
            self.my_poco.find_poco(sections_name,
                                   find_type=find_type1,
                                   click_name=click_name1,
                                   ynlist=ynlist1,
                                   click_type=click_type1)
            sleep(1)
            # 点击挑战
            self.my_poco.find_poco(self.poco("Btn_battle").child("icon"),
                                   find_type="obj")
            sleep(4)
            if self.poco("tiaoguo").exists():
                self.poco("tiaoguo").click()
                sleep(1)
            else:
                sleep(20)

            try:
                for i in range(3):
                    sleep(1)
                    self.my_poco.find_poco("点击屏幕继续")
            except PocoNoSuchNodeException:
                pass

            before_level = None  # todo
            if before_level == find_level:
                break
Example #11
0
class FirstFunctionGoRun:
    def __init__(self):
        self.info = Information()
        self.game_name = self.info.get_config("App_Name", "game_name")

    def first_function_go_run(self):
        """
        用来跳过一些功能初次进入的引导动画
        :return:
        """
        if self.game_name == "com.youzu.test.qa":
            ffgrs2 = FirstFunctionGoRunSs2()
            ffgrs2.first_function_go_run_ss2()
        else:
            pass
class MyPocoObject():
    """
    该类存放改写poco框架的方法
    需要先启动游戏,然后调用set_poco
    """
    def __init__(self):

        self.info = Information()
        self.uw = UnexpectedWin()
        self.poco = None

    def set_poco(self, poco_input):
        """
        :param poco_input: 用于设置和切换不同的poco对象
        :return:
        """
        self.poco = poco_input
        self.uw.set_poco(poco_input)

    def get_poco(self):
        return self.poco

    def my_swipe(self, start_poco, end_poco, timein=2):
        """
        传入两个poco对象或者坐标,以对象的中心点坐标进行滑动
        :param start_poco:
        :param end_poco:
        :return:两个poco对象的坐标
        """
        self.uw.unexpected_win()
        if type(start_poco) == list and type(end_poco) == list:
            swipe(start_poco, end_poco, duration=timein)
            return None, None
        else:
            pos_2 = self.get_poco_pos(start_poco)
            pos_3 = self.get_poco_pos(end_poco)
            swipe(pos_2, pos_3, duration=timein)
            return pos_2, pos_3

    def find_poco(self,
                  find_name,
                  find_type="text",
                  click_name=None,
                  ynlist="不翻",
                  direction="竖屏",
                  click_type=None,
                  click_list=None):
        """
        只一个参数时,默认poco(text=find_name)
        :param find_name:需要查找的控件名
        :param find_type:name/text/obj
        :param click_name:需要点击的控件,默认none,表示和find_name是一个控件
        :param ynlist:是否翻页查找(上翻页、下翻页、不翻)
        :param click_type:需要点击的控件的类型,name/text,默认none,表示和find_name是一个控件
        :param click_list:点击UI偏移量[0,0]-[1,1]
        :return:
        """
        sleep(0.5)
        global find_to
        find_to = False
        for i in range(3):
            # 判断是否因为异常弹窗导致找不到
            self.uw.unexpected_win()
            if "翻页" in ynlist:
                self.phone_size = self.info.get_phone_size()
                for i in range(20):
                    i_go = i + 1
                    long_side = self.phone_size[0]
                    short_side = self.phone_size[1]
                    # 循环中找不到时可以继续下次循环
                    try:
                        # 查找的和点击的不一致
                        if click_name is not None:
                            # 判断需要点击的类型,后续可加入其他类型
                            if click_type == "name":
                                if find_type == "name":
                                    if self.poco(name=find_name).exists():
                                        self.poco(
                                            name=click_name).click(click_list)
                                        find_to = True
                                        break
                                if find_type == "text":
                                    if self.poco(text=find_name).exists():
                                        self.poco(
                                            name=click_name).click(click_list)
                                        find_to = True
                                        break
                        else:
                            if find_type == "obj":
                                if find_name.exists():
                                    find_name.click(click_list)
                                    find_to = True
                                    break
                            # 查找和点击是一个,翻页版
                            if find_type == "name":
                                if self.poco(name=find_name).exists():
                                    self.poco(
                                        name=click_name).click(click_list)
                                    find_to = True
                                    break
                            if find_type == "text":
                                if self.poco(text=find_name).exists():
                                    self.poco(text=find_name).click(click_list)
                                    find_to = True
                                    break
                    except PocoNoSuchNodeException:
                        print("第" + str(i_go) + "遍未找到")
                    # 循环结束再找不到报错
                    if i_go == 20:
                        snapshot(msg="翻页查找报错退出时画面")
                        raise PocoNoSuchNodeException(self)
                    if "下" in ynlist:
                        if direction == "横屏":
                            swipe([long_side / 2, short_side * 0.8],
                                  [long_side / 2, short_side * 0.2])
                        else:
                            swipe([short_side / 2, long_side * 0.8],
                                  [short_side / 2, long_side * 0.2])
                    if "上" in ynlist:
                        if direction == "横屏":
                            swipe([long_side / 2, short_side * 0.2],
                                  [long_side / 2, short_side * 0.8])
                        else:
                            swipe([short_side / 2, long_side * 0.2],
                                  [short_side / 2, long_side * 0.8])
                    sleep(3)
            # 不翻页
            else:
                # 查找的和点击的不一致

                if click_name is not None:
                    # 判断需要点击的类型,后续可加入其他类型
                    if click_type == "name":
                        if find_type == "name":
                            if self.poco(name=find_name).exists():
                                self.poco(name=click_name).click(click_list)
                                find_to = True
                                break
                        if find_type == "text":
                            if self.poco(text=find_name).exists():
                                self.poco(name=click_name).click(click_list)
                                find_to = True
                                break
                else:
                    # 查找和点击是一个
                    if find_type == "obj":
                        if find_name.exists():
                            find_name.click(click_list)
                            find_to = True
                            break
                    if find_type == "name":
                        if self.poco(name=find_name).exists():
                            self.poco(name=find_name).click(click_list)
                            find_to = True
                            break
                    else:
                        if self.poco(text=find_name).exists():
                            self.poco(text=find_name).click(click_list)
                            find_to = True
                            break
            if find_to:
                break
            sleep(5)
            if i == 2:
                if not find_to:
                    snapshot(msg="点击报错退出时画面")
                    raise PocoNoSuchNodeException(self)

    def get_poco_pos(self, find_pos_poco):
        """
        识别手机分辨率,换算ui控件的坐标
        :param find_pos_poco:
        :return:
        """
        # [x,y]
        pos_list = find_pos_poco.get_position()
        # [宽,高]
        phone_list = self.poco.get_screen_size()
        x = int(phone_list[0] * pos_list[0])
        y = int(phone_list[1] * pos_list[1])
        return [x, y]
    def __init__(self):

        self.info = Information()
        self.game_name = self.info.get_config("App_Name", "game_name")
        self.sever_poco = self.info.get_config("Sever_poco", self.game_name)
 def __init__(self):
     self.info = Information()
Example #15
0
 def __init__(self):
     self.info = Information()
     self.my_poco = MyPocoObject()
     self.uw = UnexpectedWinSs2()
class MyRunCase:
    def __init__(self):
        self.info = Information()

    def make_config_list(self):
        # 获取新鲜的设备列表
        phone_list_devices = ADB().devices()
        self.phone_id_list = []
        # 创建手机设备列表
        if self.info.is_section_exist("Phone_List"):
            self.info.remove_section("Phone_List")
        self.info.add_section("Phone_List")
        if self.info.is_section_exist("Case_defeated__List"):
            self.info.remove_section("Case_defeated__List")
        self.info.add_section("Case_defeated__List")
        if self.info.is_section_exist("Http_path_list"):
            self.info.remove_section("Http_path_list")
        self.info.add_section("Http_path_list")
        if self.info.is_section_exist("Html_path_name_dic"):
            self.info.remove_section("Html_path_name_dic")
        self.info.add_section("Html_path_name_dic")
        for phone in phone_list_devices:
            phone_id = phone[0]
            if phone[1] == 'device':
                self.phone_id_list.append(phone_id)
        # 把所有的设备放到info表里面
        for phone_id in self.phone_id_list:
            self.info.set_config("Phone_List", phone_id, "None")

    def run_case(self, test_cases_name):

        # airtest report auto_ui/got/test_ch1.air --export ${reportDir}
        # 获取yaml文件的路径
        obj_path = os.path.abspath(
            os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
        yml_path = obj_path + "\case.yml"
        print(yml_path)
        with open(yml_path, 'r', encoding='utf-8') as f:
            cases = yaml.load(f)
        air_case_path_list = []
        case_name_dic = {}
        for case_name in cases[test_cases_name]:
            # 拼接yaml下case的路径
            air_case_path = obj_path + '\\' + case_name + ".air"
            case_name_dic[air_case_path] = case_name
            air_case_path_list.append(air_case_path)
        run_phone_id = ""
        # 根据当前手机列表,查找配置文件中空闲状态的手机
        for phone_id in self.phone_id_list:
            phone_status = self.info.get_config("Phone_List", phone_id)
            if phone_status == "None":
                run_phone_id = phone_id
                break
        # 运行开始时设置设备状态
        self.info.set_config("Phone_List", run_phone_id, "Runing")
        # 存放Htlm报告的目录

        name = ""
        defeated_case_list = []
        # 按顺序执行case.yml中的用例
        for i in range(len(air_case_path_list)):
            case_run_path = air_case_path_list[i]
            cmd_run_case = "airtest run " + case_run_path + " --device Android://127.0.0.1:5037:" + run_phone_id + " --log"
            proc = subprocess.Popen(cmd_run_case,
                                    shell=True,
                                    stdout=subprocess.PIPE)
            print(proc.communicate()[0])  # 从线程中获取值
            code = proc.returncode
            if code == 0:
                color = "blue"
                is_success_str = "成功"
            else:
                color = "red"
                # 很蛋疼,没有预留单独的case_name,只能先这样
                for case_name in cases[test_cases_name]:
                    if case_name in case_run_path:
                        defeated_case_list.append(case_name)
                is_success_str = "失败"
                self.info.set_config("Case_defeated__List",
                                     case_name_dic[case_run_path],
                                     is_success_str)
            static_root = "https://ep.yoozoo.com/public/static/airtest"
            cmd_make_html = "airtest report " + case_run_path + " --export " + case_run_path + " --static_root " + static_root + " --lang zh"
            # 执行完用例之后生成报告
            subprocess.Popen(cmd_make_html, shell=True, stdout=subprocess.PIPE)
            if case_run_path != "":
                info = json.loads(get_script_info(case_run_path),
                                  encoding='utf-8')
                name = info.get('title')
                if len(name) == 0:
                    name = case_name_dic[case_run_path]
            html_path = case_run_path
            case_air_log_name = case_name_dic[
                case_run_path] + ".log"  # 日志文件夹的名称
            # html_path_name_dic[name] = [html_path,case_air_log_name,case_name_dic[case_run_path]]
            self.info.set_config(
                "Html_path_name_dic", name,
                str([
                    html_path, case_air_log_name, case_name_dic[case_run_path]
                ]))
            my_html_file_path_new = self.info.get_config(
                "HtlmPath", "log_path")
            html_path = my_html_file_path_new + "/" + case_name_dic[
                case_run_path] + ".log" + "/log.html"
            self.bodys = '''<div><body><a href="''' + html_path + '''">''' + name + is_success_str + '''</a></body></div>'''
            self.info.set_config("Http_path_list",
                                 case_name_dic[case_run_path], self.bodys)
        # 把失败的项写入yml中
        with open(yml_path, 'w', encoding='utf-8') as f:
            cases["defeated_cases"] = defeated_case_list
            yaml.safe_dump(cases, f)

        self.info.set_config("Phone_List", run_phone_id,
                             "None")  # 运行结束后把设备状态改回来
        # self.make_html(html_path_name_dic)
        # os.system(r"airtest run D:\yoozoo_gitlab\autotest\sanguohero2\teat_ss2.air --device Android://127.0.0.1:5037:e42eb94e --log")
        # os.system(r"airtest report D:\yoozoo_gitlab\autotest\sanguohero2\teat_ss2.air  --export D:\yoozoo_gitlab\autotest\sanguohero2\teat_ss2.air  --static_root https://ep.yoozoo.com/public/static/airtest --lang zh")

    def make_html(self):
        """

        :param html_path_name_dic:[运行脚本的路径.air,脚本名称.air.脚本名称log,脚本名称]
        :return:
        """
        html_path_name_dic = {}
        cof_keys = self.info.get_options("Http_path_list")
        for key in cof_keys:
            dic_value = self.info.get_config("Http_path_list", key)
            html_path_name_dic[key] = eval(dic_value)
        log_html_path = self.info.get_config("HtlmPath", "log_path")
        bodys = ""
        for key in cof_keys:
            body_name = html_path_name_dic[key][2]
            body = self.info.get_config("Http_path_list", body_name)
            bodys = bodys + body
            my_html_file_path_old = log_html_path + "\\" + html_path_name_dic[
                key][1]
            case_run_file_path = html_path_name_dic[key][
                0] + "\\" + html_path_name_dic[key][1]
            case_run_file_path_log = html_path_name_dic[key][0] + "\\log"
            my_html_file_path_new = log_html_path
            # 删除之前遗留的旧文件夹
            if os.path.isdir(my_html_file_path_old):  # 判断该文件是否为文件夹
                shutil.rmtree(my_html_file_path_old)  # 若为文件夹,则直接删除
            # 删除遗留的log文件
            if os.path.isdir(case_run_file_path_log):  # 判断该文件是否为文件夹
                shutil.rmtree(case_run_file_path_log)  # 若为文件夹,则直接删除
            sleep(2)
            shutil.move(case_run_file_path, my_html_file_path_new)

            # if is_success:
            #     color_name = "blue"# todo 颜色
            #     is_success_str = "run_success"
            # else:
            #     color_name = "red"
            #     is_success_str = "run_defeated"
            # html_path =my_html_file_path_new +"/"+html_path_name_dic[key][3]+".log"+ "/log.html"
            # bodys = bodys + '''<div><body><a href="''' + html_path + '''"class="''' + color_name + '''">''' + name + is_success_str + '''</a></body></div>'''

        html_txt = '''<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>测试报告</title><style type="text/css">
        a:link{color:red;}
        a:visited { color:#00FF00; text-decoration:none; }
        a:hover { color:#000000; text-decoration:none; }
        a:active { color:#FFFFFF;}
        </style><base target="_blank"></head>
        ''' + bodys + '''</html>'''

        my_html_path = log_html_path + "\index.html"
        # my_html_path = r"C:\Users\v.lidd\Desktop\测试报告.html"
        with open(my_html_path, 'w+', encoding='utf-8') as f:
            f.write(html_txt)
Example #17
0
 def __init__(self):
     self.info = Information()
     self.my_poco = MyPocoObject()
 def __init__(self):
     self.info = Information()
     self.rg = ResourceGm()
     self.my_poco = MyPocoObject()
     self.game_name = self.info.get_config("App_Name", "game_name")
Example #19
0
class MyPoco:
    def __init__(self):
        """
        初始化点击类、信息类、性能类
        """
        self.my_poco = MyPocoObject()
        self.info = Information()
        self.xn = YzTest2Performance()
        self.eg = EntryGame()
        self.fg = Fight()
        self.rg = ResourceGm()
        self.na = NewAccount()
        self.sp = Protocol()
        self.mrc = MyRunCase()

    # todo 装饰器
    def first_function_go_run(self):
        """
        用来跳过一些功能初次进入的引导动画
        :return:
        """
        ffgr = FirstFunctionGoRun()
        ffgr.first_function_go_run()

    def open_game(self, sever_name_input="sever_name", game_account_input="old_game_account"):
        """
        功能向,开始游戏,启动到游戏主界面,广告和签到界面关闭
        :return:返回StdPoco().poco对象,可直接用于脚本的控件点击
        """
        try:
            self.poco = self.eg.open_game(sever_name_input, game_account_input)
            self.set_poco(self.poco)
            return self.poco
        # 如果出现断开连接的报错,就再执行一下该步骤
        except RpcTimeoutError:
            pristr = "poco断开" + str(self.info.game_is_running())
            if not self.info.game_is_running():
                game_name = self.info.get_config("App_Name", "game_name")
                start_app(game_name)
                sleep(2)
                snapshot(msg=pristr)
            snapshot(msg=pristr)
            self.poco = self.eg.open_game(sever_name_input, game_account_input)
            self.set_poco(self.poco)
        except PocoNoSuchNodeException:
            snapshot(msg="找不到控件")
            raise PocoNoSuchNodeException(self)
        except Exception:
            pristr = "报错,游戏" + str(self.info.game_is_running())
            snapshot(msg=pristr)
            raise Exception

    def close_game(self):
        """
        关闭游戏,不区分功能或者性能
        :return:
        """
        self.eg.close_game()

    def set_poco(self, poco_input):
        """

        :param poco_input:传入poco对象,主要用于不经过open_game()情况的控件点击
        :return:
        """
        self.my_poco.set_poco(poco_input)

    def my_swipe(self, start_poco, end_poco, timein=2):
        """
        两个对象中心点之间的滑动
        :param start_poco:poco对象
        :param end_poco:poco对象
        :return:两个对象的坐标
        """
        try:
            pos_2, pos_3 = self.my_poco.my_swipe(start_poco, end_poco, timein)
            return pos_2, pos_3
        # 如果出现断开连接的报错,就再执行一下该步骤
        except RpcTimeoutError:
            pristr = "poco点击断开" + str(self.info.game_is_running())
            if not self.info.game_is_running():
                game_name = self.info.get_config("App_Name", "game_name")
                start_app(game_name)
                sleep(2)
                snapshot(msg=pristr)
            snapshot(msg=pristr)
            pos_2, pos_3 = self.my_poco.my_swipe(start_poco, end_poco, timein)
            return pos_2, pos_3
        except PocoNoSuchNodeException:
            snapshot(msg="找不到控件")
            raise PocoNoSuchNodeException(self)
        except Exception:
            pristr = "点击方法报错,游戏" + str(self.info.game_is_running())
            snapshot(msg=pristr)
            raise Exception


    def find_poco(self, find_name, find_type="text", click_name=None, ynlist="不翻", direction="竖屏", click_type=None,
                  click_list=None):
        """
        查找控件并点击,默认三次内找不到报错,间隔5秒
        :param find_name:查找的控件名
        :param find_type:查找的控件类型 text、name....
        :param click_name:点击的控件名,默认none,表示查找和点击的控件是一个点
        :param click_type:点击的控件类型text、name....
        :param ynlist:是否翻页查找,默认x:1/2 ,y1/5-4/5范围,建议使用my_swipe方法
        :param direction:和翻页相关,横屏还是竖屏范围翻页
        :param click_list:控件点击偏移点[0,0]-[1,1]范围
        :return:PocoNoSuchNodeException
        """
        try:
            self.my_poco.find_poco(find_name, find_type=find_type, click_name=click_name, ynlist=ynlist,
                                   direction=direction, click_type=click_type,
                                   click_list=click_list)
        # 如果出现断开连接的报错,就再执行一下该步骤
        except RpcTimeoutError:
            pristr = "poco点击断开" + str(self.info.game_is_running())
            if not self.info.game_is_running():
                game_name = self.info.get_config("App_Name", "game_name")
                start_app(game_name)
                sleep(2)
                snapshot(msg=pristr)
            snapshot(msg=pristr)
            self.poco = StdPoco()  # todo 需要根据游戏不同区分
            self.set_poco(self.poco)
            self.my_poco.find_poco(find_name, find_type=find_type, click_name=click_name, ynlist=ynlist,
                                   direction=direction, click_type=click_type,
                                   click_list=click_list)
        except PocoNoSuchNodeException:
            snapshot(msg="找不到控件")
            raise PocoNoSuchNodeException(self)
        except Exception:
            pristr = "点击方法报错,游戏" + str(self.info.game_is_running())
            snapshot(msg=pristr)
            raise Exception

    def fight(self, sections_name, find_type1="text", click_name1=None, ynlist="不翻", click_type1=None,
              number_of_times=1, find_level=None):
        """
        少三2循环战斗
        :param sections_name:要进入的关卡的名称
        :param find_type1:查找的控件类型 text、name....
        :param click_name1:点击的控件名,默认none,表示查找和点击的控件是一个点
        :param click_type1:点击的控件类型text、name....
        :param ynlist1:是否翻页查找,默认x:1/2 ,y1/5-4/5范围,建议使用my_swipe方法
        :param number_of_times:循环战斗几次
        :param find_level:到几级之后不再打了
        :return:
        """
        self.fg.to_fight(sections_name, find_type1=find_type1, click_name1=click_name1, ynlist1=ynlist,
                         click_type1=click_type1,
                         number_of_times=number_of_times, find_level=find_level)

    def add_resource(self, dic_input):
        """
        添加各种资源
        :param name:资源名称
        :param size:资源数量
        :return:
        """
        self.rg.add_resource(dic_input)

    def set_play_fuben_num(self, num):
        self.rg.set_play_fuben_num(num)
    def set_play_liezhuan_num(self, num):
        self.rg.set_play_liezhuan_num(num)
    def delete_resource(self, dic_input):
        """
        添加各种资源
        :param name:资源名称
        :param size:资源数量
        :return:
        """
        self.rg.delete_resource(dic_input)

    def get_resource_quantity(self, list_input):
        """
        获取某资源数量
        :return:字典,资源名称和数量
        """
        dic_res = self.rg.get_resource_num(list_input)
        return dic_res

    def get_sever_time(self):
        """
        输入包含时间戳的poco对象,获取当前服务器时间
        :param input_str:需要输入的文本
        :return:int [年月日,时分秒,星期]
        """
        return self.rg.get_sever_time()

    def get_config(self, list_name, key):
        """
        获取配置文件信息
        :param list_name:模块名
        :param key:键
        :return:value
        """
        value = self.info.get_config(list_name, key)
        return value

    def add_section(self, section_name):
        '''
        在配置文件中添加项
        :param section_name:项名称
        :return:
        '''
        self.info.add_section(section_name)

    def remove_section(self, section_name):
        '''
        删除配置文件中的项
        :param section_name:项名称
        :return:
        '''
        self.info.remove_section(section_name)

    def set_config(self, list_name, key, value):
        """
        设置配置文件信息
        :param list_name:模块名
        :param key:键
        :param value:值
        :return:
        """
        self.info.set_config(list_name, key, value)

    def get_time_str(self, str_time_input):
        """
        根据时间戳字符串换算日期和星期
        :param poco_time_input:包含时间戳text的poco对象
        :return: [int(ymd),int(hms),int(week)]
        """
        int_list = self.info.get_time_str(str_time_input)
        return int_list

    def get_game_number_l(self, find_number_poco, subscript):
        """
        不同游戏不同实现,获取游戏text属性中的数字 one/two
        :param find_number_poco:poco对象
        :param subscript:0/1
        :return:int
        """
        return self.info.get_game_number_l(find_number_poco, subscript)

    def get_game_number_c(self, find_number_poco):
        """
        不同游戏不同实现,获取游戏text属性中的数字 ]int[
        :param find_number_poco:poco对象
        :return:int
        """
        return self.info.get_game_number_c(find_number_poco)

    def get_game_number_cc(self, find_number_poco):
        """
        不同游戏不同实现,获取游戏text属性中的str数字,]int)
        :param find_number_poco:poco对象
        :return:int
        """
        return self.info.get_game_number_cc(find_number_poco)

    def get_game_number(self, find_number_poco):
        """
        获取游戏text属性中的str数字
        :param find_number_poco:poco对象
        :return:int
        """
        return self.info.get_game_number(find_number_poco)

    def get_game_number_instr(self, find_number_poco):
        """
        只获取poco对象中text属性中的数字
        :param find_number_poco:poco对象
        :return:int
        """
        return self.info.get_game_number_instr(find_number_poco)

    def get_poco_visible(self, find_visible_poco):
        """
        不同游戏不同实现,获取游戏visible属性中的str值
        :param find_visible_poco:poco对象
        :return:str true/false
        """

        return self.info.get_poco_visible(find_visible_poco)

    def get_poco_anyvalue(self, find_name_poco, value_name_str):
        """
        获取游戏poco对象value_name_str属性中的值,需要自行判断类型
        :param find_number_poco:poco对象
        :return:value
        """

        return self.info.get_poco_anyvalue(find_name_poco, value_name_str)

    def get_poco_pos(self, find_pos_poco):
        """
        获取poco对象的坐标,经过分辨率转换
        :param find_pos_poco:poco对象
        :return:[,]
        """
        return self.my_poco.get_poco_pos(find_pos_poco)

    def get_phone_name(self):
        """
        获取当前手机的名字,区分三挡机使用
        :return:str
        """
        return self.info.get_phone_name()

    def get_phone_size(self):
        """
        获取当前手机的分辨率
        :return:list_int[宽,高]
        """
        return self.info.get_phone_size()

    def add_log(self, first, second, msg=""):
        """
        对比结果值,并在报告连接中添加日志信息,比如资源变化前后的对比
        :param first:对比值one
        :param second:对比值two
        :param msg:日志的描述,==/!=、正常/异常
        :return:
        """
        self.info.add_log(first, second, msg=msg)

    def first_open_yztest(self):
        """
        启动性能工具,在开始测试步骤前结束
        :return:
        """
        self.xn.first_open_yztest()

    def start_test_xn(self, sever_name_input="sever_name", game_account_input="new_game_account"):
        """
        性能,点击开始测试按钮,启动游戏并在游戏界面停止
        :return:poco对象
        """
        self.poco = self.xn.start_test(sever_name_input, game_account_input)
        self.set_poco(self.poco)
        return self.poco

    def touch_tab_xn(self):
        """
        点击标记按钮
        :return:
        """
        self.xn.touch_tab()

    def end_tab_xn(self):
        """
        结束测试并上传报告,在开始测试界面结束
        :return:
        """
        self.xn.end_tab()

    def close_test_xn(self):
        """
        停止性能测试,关闭性能软件和游戏
        :return:
        """
        self.xn.close_test()

    def text(self, input_str):  # 废弃
        """
        输入文本,没有回车键
        :param input_str:需要输入的文本
        :return:
        """
        self.info.text_str(input_str)

    def text_str(self, input_str):
        """
        输入文本,没有回车键,接受汉字
        :param input_str:需要输入的文本
        :return:
        """
        self.info.text_str(input_str)

    def new_account(self,  resource_dic_input, sever_name_input,play_dic):
        """
        根据输入的要求在sever_name区创建一个账号
        :param dic_input: 字典,需要添加的各种资源
        :param sever_name_input: 区服名
        :param play_dic: 副本列表dic{"副本":80,"列传":12}
        :return:
        """
        self.na.new_game_account(resource_dic_input, sever_name_input,play_dic)

    def send_game_protocol(self, send_protocol_dic, find_name):
        """
        发送后会回到当前界面,只发一条,
        :param add_name_input_list: dic {"message":协议id,"ages":,...}
        :param find_name:协议返回值中需要查询值的key,可以为none
        :return:value
        """
        find_name_value = self.rg.send_game_protocol(send_protocol_dic, find_name)
        return find_name_value

    def test_game_protocol(self, add_name_input_list):
        """
        发送后会回到当前界面,只发一条,发完自行查看结果,用于协议测试
        :param add_name_input_list: list [协议用例id,arges....]
        :return:
        """
        self.rg.test_game_protocol(add_name_input_list)

    def is_exist_poco_log(self, poco_obj, is_exist_str):
        """
        判断传入的控件是否处于显示状态,在报告中体现,用来验证按钮点击后的状态
        :param poco_obj: 需要验证的控件对象
        :param is_exist_str:"显示"or"隐藏"
        :return: bool  True or False
        """
        is_exist = self.info.is_exist_poco_log(poco_obj, is_exist_str)
        return is_exist
    def is_exist_poco(self, poco_obj):
        """
        判断传入的控件是否处于显示状态,在报告中体现,用来验证按钮点击后的状态
        :param poco_obj: 需要验证的控件对象

        :return: bool  True or False
        """
        is_exist = self.info.is_exist_poco(poco_obj)
        return is_exist

    def my_run_case(self, yml_cases_name_list):
        '''
        传入需要执行case.yml中用例的项名的列表
        :param yml_cases_name_list: ["debug","debug1"]
        :return:
        '''
        self.mrc.make_config_list()
        self.mrc.thread_run_case(yml_cases_name_list)
Example #20
0
class FightSx:
    def __init__(self):
        self.info = Information()
        self.my_poco = MyPocoObject()
        self.game_name = self.info.get_config("App_Name", "game_name")
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)

    def sx_fight(self,
                 sections_name,
                 find_type1="text",
                 click_name1=None,
                 ynlist1="不翻",
                 click_type1=None,
                 number_of_times=1,
                 find_level=None):
        # 仅适用于少西
        # 循环
        for i in range(number_of_times):
            # 开始点击战斗之前,判断体力是否足够
            physical_strength_int = 100
            if self.poco("Node_top_res1").offspring(
                    "Label_res_amount").exists():
                physical_strength_str = self.poco("Node_top_res1").offspring(
                    "Label_res_amount").get_text()
                physical_strength_list = physical_strength_str.split("/")
                physical_strength = physical_strength_list[0]
                physical_strength_int = int(physical_strength)
            # 体力小于10,吃体力丹
            if physical_strength_int <= 10:
                self.my_poco.find_poco("Image_top_bar", find_type="name")
                self.poco("Node_vit").child("Button_add").click()
                sleep(1)
                # self.MyPoco.find_poco(self.poco("Panel_6").child("Node_confirm").child("Text_btn_desc"), find_type="obj")
                self.my_poco.find_poco("购 买")
                sleep(1)
                # self.MyPoco.find_poco(self.poco("Panel_6").child("Node_cancel").child("Text_btn_desc"), find_type="obj")
                self.my_poco.find_poco("使 用")
                sleep(1)
                # self.MyPoco.find_poco(self.poco("Panel_info").child("Node_confirm").child("Text_btn_desc"), find_type="obj")
                self.my_poco.find_poco("确 认")
                sleep(1)
                self.my_poco.find_poco("Button_close",
                                       find_type="name")  # 回到关卡界面 todo

            self.my_poco.find_poco(sections_name,
                                   find_type=find_type1,
                                   click_name=click_name1,
                                   ynlist=ynlist1,
                                   click_type=click_type1)
            sleep(1)
            self.my_poco.find_poco("挑战")
            sleep(3)
            # self.MyPoco.find_poco(self.poco("<Layer | Tag = -1>").child("<Menu | Tag = -1>")[0].child("<MenuItem | tag = -1>")[0],click_type="obj")
            self.poco("<Layer | Tag = -1>").child("<Menu | Tag = -1>")[
                0].child("<MenuItem | tag = -1>")[1].click()
            sleep(5)
            # 在结算界面可看到等级
            number_str = self.poco("Text_level").get_text()
            number_list = number_str.split(":")
            number = number_list[1]
            level = int(number)

            try:
                for i in range(3):
                    sleep(1)
                    self.my_poco.find_poco("点击屏幕继续")
            except PocoNoSuchNodeException:
                pass
            # 判断等级,终止循环
            if level == find_level:
                break
Example #21
0
 def __init__(self):
     self.info = Information()
     self.my_poco = MyPocoObject()
     self.game_name = self.info.get_config("App_Name", "game_name")
     self.poco = StdPoco()
     self.my_poco.set_poco(self.poco)
class EntryGameSs2:
    def __init__(self):

        self.info = Information()
        self.my_poco = MyPocoObject()
        self.game_name = self.info.get_config("App_Name", "game_name")
        self.sever_poco = self.info.get_config("Sever_poco", self.game_name)

    def entry_game_ss2(self, sever_name_input, game_account_input):
        """
        ss2的登录游戏,游戏已经启动,到游戏主界面的操作
        :param sever_name_input: 服务器名称,和ini一致
        :param game_account_input: 需要登录的账号,和ini一致
        :return:
        """

        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        game_account = self.info.get_config("Account_Number",
                                            game_account_input)
        self.my_poco.find_poco("InputName", find_type="name")
        text(game_account)
        # self.poco("InputName").set_text(game_account)
        self.my_poco.find_poco("确 认")
        self.my_poco.find_poco("公 告",
                               click_name="AnnoCloseBtn",
                               click_type="name")
        self.my_poco.find_poco("点击选服")
        self.my_poco.find_poco(
            self.poco("List_kind_server").child(text="11 - 20区"),
            find_type="obj",
            click_list=[0.95, 0.15])  # todo 不同游戏可能要改
        sever_name = self.info.get_config("Sever_Name", sever_name_input)
        self.my_poco.find_poco(
            self.poco("List_server").offspring(text=sever_name),
            find_type="obj")
        self.my_poco.find_poco("Txt_guide", find_type="name")  # 关闭新手引导
        self.my_poco.find_poco("Btn_login", find_type="name")  # 开始游戏
        if self.poco("LoginLawPop").child("__view").child("btn_ok").exists():
            self.poco("LoginLawPop").child("__view").child("btn_ok").click()
            self.my_poco.find_poco("Btn_login", find_type="name")  # 开始游戏

        sleep(15)
        if self.poco("RedPacketRainReceiveLayer").child("__view").child(
                "Comp_effect").exists():  # 红包雨
            self.poco("RedPacketRainReceiveLayer").child("__view").child(
                "Comp_effect").click()
            sleep(2)
            stop_app(self.game_name)
            sleep(1)
            home()
            sleep(1)
            start_app(self.game_name)
            sleep(10)
            self.poco = StdPoco()
            self.my_poco.set_poco(self.poco)
            game_account = self.info.get_config("Account_Number",
                                                game_account_input)
            self.my_poco.find_poco("InputName", find_type="name")
            text(game_account)
            # self.poco("InputName").set_text(game_account)
            self.my_poco.find_poco("确 认")
            self.my_poco.find_poco("公 告",
                                   click_name="AnnoCloseBtn",
                                   click_type="name")
            self.my_poco.find_poco("点击选服")
            self.my_poco.find_poco(
                self.poco("List_kind_server").child(text="1 - 10区"),
                find_type="obj",
                click_list=[0.95, 0.95])  # todo 不同游戏可能要改
            sever_name = self.info.get_config("Sever_Name", sever_name_input)
            self.my_poco.find_poco(
                self.poco("List_server").offspring(text=sever_name),
                find_type="obj")
            self.my_poco.find_poco("Txt_guide", find_type="name")  # 关闭新手引导
            self.my_poco.find_poco("Btn_login", find_type="name")  # 开始游戏
            sleep(15)
        for i in range(15):
            if self.poco("Btn_goto").exists():  # 广告
                self.poco("Btn_close").click()
            if self.poco("Comp_day1").exists():  # 签到
                self.poco("__view").child("n3").child("img0").click()
            if self.poco("RedPacketRainPop").child("__view").child(
                    "Btn_close").exists():  # 红包雨锦鲤
                self.poco("RedPacketRainPop").child("__view").child(
                    "Btn_close").click()
            if self.poco("GodboxPop").exists():  # 天公赐福
                self.poco("Btn_close").click()
        return self.poco
Example #23
0
class YzTest2Performance:
    """
    性能测试类
    """

    def __init__(self):
        self.info = Information()
        self.my_andriod_poco = MyPocoObject()
        self.eg = EntryGame()
        self.phone_name = self.info.get_phone_name()
        self.use_name = self.info.get_config("Account_Number", "YzTest2")
        self.game_name = self.info.get_config("App_Name", "game_name")
        # 获取设备型号
        self.high = self.info.get_config("Phone_Model", "high")
        self.medium = self.info.get_config("Phone_Model", "medium")
        self.low = self.info.get_config("Phone_Model", "low")
        self.test = self.info.get_config("Phone_Model", "test")
        self.high_touch_x = self.info.get_config("Coordinate", "high_start_x")
        self.high_touch_y = self.info.get_config("Coordinate", "high_start_y")
        self.medium_touch_x = self.info.get_config("Coordinate", "medium_start_x")
        self.medium_touch_y = self.info.get_config("Coordinate", "medium_start_y")
        self.low_touch_x = self.info.get_config("Coordinate", "low_start_x")
        self.low_touch_y = self.info.get_config("Coordinate", "low_start_y")
        self.test_touch_x = self.info.get_config("Coordinate", "test_start_x")
        self.test_touch_y = self.info.get_config("Coordinate", "test_start_y")
        self.high_end_x = self.info.get_config("Coordinate", "high_end_x")
        self.high_end_y = self.info.get_config("Coordinate", "high_end_y")
        self.medium_end_x = self.info.get_config("Coordinate", "medium_end_x")
        self.medium_end_y = self.info.get_config("Coordinate", "medium_end_y")
        self.low_end_x = self.info.get_config("Coordinate", "low_end_x")
        self.low_end_y = self.info.get_config("Coordinate", "low_end_y")
        self.test_end_x = self.info.get_config("Coordinate", "test_end_x")
        self.test_end_y = self.info.get_config("Coordinate", "test_end_y")
        self.game_name = self.info.get_config("App_Name", "game_name")

    def first_open_yztest(self):
        '''
        首次启动时使用该方法,不会因为游戏不同而改变
        :return:
        '''
        clear_app("com.youzu.yztest_nosdk")
        home()
        stop_app("com.youzu.yztest_nosdk")
        sleep(2)
        start_app("com.youzu.yztest_nosdk")
        sleep(10)
        poco_android = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
        self.my_andriod_poco.set_poco(poco_android)
        sleep(1)
        self.my_andriod_poco.find_poco("请输入用户名")
        sleep(1)
        os.system("adb shell input text " + self.use_name)  # 没有输入框也执行的话也不影响
        self.my_andriod_poco.find_poco("登录")
        sleep(3)
        # self.my_andriod_poco.find_poco("总是允许")  # todo 三挡机
        sleep(3)
        self.my_andriod_poco.find_poco("选择应用")
        sleep(2)
        self.my_andriod_poco.find_poco(self.game_name, ynlist="下翻页")
        sleep(2)
        self.my_andriod_poco.find_poco("自动截图", click_name="com.youzu.yztest_nosdk:id/auto_screen_shot",
                                       click_type="name")  # 每次打开软件是默认关闭的
        # os.system("start /b adb shell sh /data/local/tmp/yztest_sh.sh") 需要平台启动该服务
        sleep(2)

    def start_test(self, sever_name_input, game_account_input):
        """
        开始测试,游戏启动完毕,并返回一个poco对象,用于用例使用
        :return:
        """
        stop_app(self.game_name)
        sleep(1)
        poco_android = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
        self.my_andriod_poco.set_poco(poco_android)
        self.my_andriod_poco.find_poco("开始测试")
        phone_name = self.info.get_phone_name()
        phone_name_low = self.info.get_config("Phone_Model", "low")
        if phone_name == phone_name_low:
            sleep(20)
        else:
            sleep(10)
        game_poco = self.eg.entry_game(sever_name_input, game_account_input)

        return game_poco

    # 点击标记测试按钮
    def touch_tab(self):
        """点击开始或结束标记按钮
        """
        sleep(1)
        if self.phone_name == self.low:
            touch([int(self.low_touch_x), int(self.low_touch_y)])
        if self.phone_name == self.medium:
            touch([int(self.medium_touch_x), int(self.medium_touch_y)])
        if self.phone_name == self.high:
            touch([int(self.high_touch_x), int(self.high_touch_y)])
        if self.phone_name == self.test:
            touch([int(self.test_touch_x), int(self.test_touch_y)])

    def end_tab(self):
        """
        会直接结束性能测试,需要先结束标记
        """
        sleep(1)
        # 点击退出测试按钮
        if self.phone_name == self.low:
            touch([int(self.low_end_x), int(self.low_end_y)])
        if self.phone_name == self.medium:
            touch([int(self.medium_end_x), int(self.medium_end_y)])
        if self.phone_name == self.high:
            touch([int(self.high_end_x), int(self.high_end_y)])
        if self.phone_name == self.test:
            touch([int(self.test_end_x), int(self.test_end_y)])

        # 点击弹出的确认框
        self.my_andriod_poco.find_poco("退出")
        os.system(
            "adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0")
        os.system(
            "adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0")
        self.my_andriod_poco.find_poco("上传报告")
        sleep(10)
        # 返回主界面
        self.my_andriod_poco.find_poco("转到上一层级", find_type="name")
        os.system(
            "adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:1")
        sleep(1)

    def close_test(self):
        """测试结束关闭软件,关闭游戏"""
        stop_app("com.youzu.yztest_nosdk")
        sleep(2)
        stop_app(self.game_name)
    def __init__(self):

        self.info = Information()
        self.uw = UnexpectedWin()
        self.poco = None
Example #25
0
class ResourceGmSs2:
    def __init__(self):
        self.info = Information()
        self.my_poco = MyPocoObject()
        self.uw = UnexpectedWinSs2()

    def add_resource_ss2(self, add_name_input_dic):  # todo
        """
        从开始到结束都在当前界面,添加一些资源
        :return:
        """
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        mes = MessageSs2()
        # 将传入的字典的key转换成列表
        keys_list = list(add_name_input_dic.keys())
        order_str = """{"message":10140,"awards":["""
        counter_num = 0
        for key in keys_list:
            if counter_num == 0:
                pass
            else:
                order_str = order_str + ","
            size = add_name_input_dic.get(key)
            value = mes.get_resource_value(key)
            order_str = order_str + "{" + value + ""","size":""" + str(size) + "}"
            counter_num += 1
        order_str = order_str + "]}"
        order_str.replace(" ", "")
        self.my_poco.find_poco("Comp_res3", find_type="name")  # 点击元宝进入gm
        self.my_poco.find_poco("自动测试")
        self.my_poco.find_poco("input1", find_type="name")
        self.info.text_str(order_str)
        self.my_poco.find_poco("btn1", find_type="name")
        self.my_poco.find_poco("close", find_type="name")
        self.my_poco.find_poco("close1", find_type="name")  # 回到主界面

    def delete_resource_ss2(self, del_name_input_dic):
        """
        从开始到结束都在当前界面,删除一些资源
        :return:
        """
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        mes = MessageSs2()
        # 将传入的字典的key转换成列表
        keys_list = list(del_name_input_dic.keys())
        order_str = """{"message":10140,"consumes":["""
        counter_num = 0
        for key in keys_list:
            if counter_num == 0:
                pass
            else:
                order_str = order_str + ","
            size = del_name_input_dic.get(key)
            value = mes.get_resource_value(key)
            order_str = order_str + "{" + value + ""","size":""" + str(size) + "}"
            counter_num += 1
        order_str = order_str + "]}"
        order_str.replace(" ", "")
        self.my_poco.find_poco("Comp_res3", find_type="name")  # 点击元宝进入gm
        self.my_poco.find_poco("自动测试")
        self.my_poco.find_poco("input1", find_type="name")
        self.info.text_str(order_str)
        self.my_poco.find_poco("btn1", find_type="name")
        self.my_poco.find_poco("close", find_type="name")
        self.my_poco.find_poco("close1", find_type="name")  # 回到主界面

    def get_resource_num_ss2(self, get_name_input_list):
        """
        从开始到结束都在当前界面,查询身上的资源数量
        :return:返回字典,道具的名称和数量
        """
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        mes = MessageSs2()
        s = "["
        for key_num in range(len(get_name_input_list)):
            s = s + "{" + mes.get_resource_value(get_name_input_list[key_num]) + "}"
            if key_num == len(get_name_input_list) - 1:
                pass
            else:
                s = s + ","
        s = s + "]"
        self.my_poco.find_poco("Comp_res3", find_type="name")
        self.my_poco.find_poco("自动测试")
        self.my_poco.find_poco("input2", find_type="name")
        self.info.text_str(s)
        self.my_poco.find_poco("btn2", find_type="name")
        str_txt = self.poco("txt").get_text()
        number_list = str_txt.split(",")  # 将获取到的字符串解析成列表
        resource_dic = {}
        for i in range(len(number_list)):
            key_name = get_name_input_list[i]
            value_name = int(number_list[i])
            resource_dic.update({key_name: value_name})

        self.my_poco.find_poco("close", find_type="name")
        self.my_poco.find_poco("close1", find_type="name")
        return resource_dic

    def get_sever_time_ss2(self):
        """
        从开始到结束都在当前界面,服务器时间
        :return: int [日期,时间,星期]
        """
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        time.sleep(2)
        self.my_poco.find_poco("Comp_res3", find_type="name")
        self.my_poco.find_poco("自动测试")
        game_time_str = self.poco("time").get_text()
        time_list = self.info.get_time_str(game_time_str)
        self.my_poco.find_poco("close", find_type="name")
        self.my_poco.find_poco("close1", find_type="name")
        return time_list
    def get_resource_id_ss2(self, get_name_input_list):# todo
        """
        从开始到结束都在当前界面,查询身上的资源数量
        :return:返回字典,道具的名称和id
        """
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        mes = MessageSs2()
        s = "["
        for key_num in range(len(get_name_input_list)):
            s = s + "{" + mes.get_resource_value(get_name_input_list[key_num]) + "}"
            if key_num == len(get_name_input_list) - 1:
                pass
            else:
                s = s + ","
        s = s + "]"
        self.my_poco.find_poco("Comp_res3", find_type="name")
        self.my_poco.find_poco("自动测试")
        self.my_poco.find_poco("input2", find_type="name")
        self.info.text_str(s)
        self.my_poco.find_poco("btn2", find_type="name")
        str_txt = self.poco("txt").get_text()
        number_list = str_txt.split(",")  # 将获取到的字符串解析成列表
        resource_dic = {}
        for i in range(len(number_list)):
            key_name = get_name_input_list[i]
            value_name = int(number_list[i])
            resource_dic.update({key_name: value_name})

        self.my_poco.find_poco("close", find_type="name")
        self.my_poco.find_poco("close1", find_type="name")
        return resource_dic

    def test_protocol_ss2(self, add_name_input_list):
        """
        只发一条,发完查看结果,用于协议测试
        :param add_name_input_list: [协议id,arges....]
        :return:
        """
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        mes = ProtocolDicTestSs2()
        value_list = mes.get_protocol_value(add_name_input_list[0])
        protocol_str = value_list[0]
        for i in range(1, len(add_name_input_list)):
            protocol_str = protocol_str + value_list[i] + str(add_name_input_list[i])
        protocol_str = protocol_str + value_list[len(value_list) - 1]
        self.my_poco.find_poco("Comp_res3", find_type="name")  # 点击元宝进入gm
        self.my_poco.find_poco("自动测试")
        self.my_poco.find_poco("input1", find_type="name")
        self.info.text_str(protocol_str)
        self.my_poco.find_poco("btn1", find_type="name")
        self.my_poco.find_poco("close", find_type="name")
        self.my_poco.find_poco("close1", find_type="name")  # 回到主界面

    def send_game_protocol(self, send_protocol_dic,find_name):# todo
        """
        使用协议对游戏进行操作,例如穿戴装备,强化装备等
        发送后会回到当前界面,只发一条
        :param add_name_input_list: list [协议id,arges....]
        :param find_name:协议返回值中需要查询值的key,可以为none
        :return:value
        """
        self.poco = StdPoco()
        self.my_poco.set_poco(self.poco)
        self.my_poco.find_poco("Comp_res3", find_type="name")  # 点击元宝进入gm
        self.my_poco.find_poco("自动测试")
        self.my_poco.find_poco("input2", find_type="name")
        protocol_str = str(send_protocol_dic).replace(" ","").replace("'",'''"''') # 要发送的协议
        self.info.text_str(protocol_str)
        s = self.poco("Comp_scroll").get_text()  # 获取到的返回值
        s = s[6:]
        s1 = re.sub('(\w+) = ([^\{ ]+)', "\"\\1\":\\2,", s)
        s1 = s1.replace("false", "False")
        s1 = s1.replace("ture", "Ture")
        s2 = re.sub("\s{2,}", "", s1)
        s3 = re.sub("(\w+) = {", "\"\\1\" : {", s2)
        s4 = re.sub("}", "},", s3)
        s = s4[0:-1]
        ret_dic = eval(s) # todo
        self.my_poco.find_poco("btn2", find_type="name")
        self.my_poco.find_poco("close", find_type="name")
        self.my_poco.find_poco("close1", find_type="name")  # 回到主界面
        if find_name != None:
            find_name_value = None #todo
            return find_name_value


    def set_play_fuben_num(self, num):
        print("开始一键功能")
        nums = str(num)
        poco = StdPoco()
        self.uw.set_poco(poco)
        self.my_poco.set_poco(poco)
        self.my_poco.find_poco("Comp_res3", find_type="name")
        self.my_poco.find_poco("一键功能")
        self.my_poco.find_poco(poco("OnekeyLayer").child("__view").child("n21"), find_type="obj")
        self.info.text_str(nums)
        self.my_poco.find_poco("btn_challenge", find_type="name")#一键主线
        if num>10:
            num = int(num/7)*3
        for i in range(num):
            time.sleep(6)
            self.uw.ss2_unexpected_win()
            self.my_poco.find_poco(poco("OnekeyLayer").child("__view").child("btn_challenge"), find_type="obj")#一键主线
        self.my_poco.find_poco(poco("OnekeyLayer").child("__view").child("btn0"), find_type="obj")
        self.my_poco.find_poco("close1", find_type="name")

    def set_play_liezhuan_num(self, num):
        print("开始一键名将")
        nums = str(num)
        poco = StdPoco()
        self.uw.set_poco(poco)
        self.my_poco.set_poco(poco)
        self.my_poco.find_poco("Comp_res3", find_type="name")
        self.my_poco.find_poco("一键功能")
        self.my_poco.find_poco("一键名将")
        self.my_poco.find_poco(poco("OnekeyLayer").child("__view").child("n21"), find_type="obj")
        self.info.text_str(nums)
        for i in range(num*11):
            self.uw.ss2_unexpected_win()
            self.my_poco.find_poco(poco("OnekeyLayer").child("__view").child("btn_challenge"), find_type="obj")#一键主线
            time.sleep(1.5)
            print("列传")
        # self.my_poco.find_poco("btn_challenge", find_type="name")  # 一键主线
        # sleep(num * 4)
        self.my_poco.find_poco(poco("OnekeyLayer").child("__view").child("btn0"), find_type="obj")
        self.my_poco.find_poco("close1", find_type="name")
 def __init__(self):
     self.info = Information()
     self.game_name = self.info.get_config("App_Name", "game_name")
class ResourceGm:
    def __init__(self):
        """
        在if、elif结构中初始化对象
        """
        self.info = Information()
        self.my_poco = MyPocoObject()
        self.game_name = self.info.get_config("App_Name", "game_name")
        if self.game_name == "com.youzu.test.qa":
            self.rgss2 = ResourceGmSs2()
        else:
            pass

    def add_resource(self, add_name_input_dic):
        """
        添加资源,区分不同的游戏走不同的逻辑
        :param add_name_input_dic: {资源名称:数量}
        :return:
        """
        if self.game_name == "com.youzu.test.qa":
            self.rgss2.add_resource_ss2(add_name_input_dic)
        else:
            pass

    def delete_resource(self, del_name_input_dic):
        """
        添加资源,区分不同的游戏走不同的逻辑
        :param add_name_input_dic: {资源名称:数量}
        :return:
        """
        if self.game_name == "com.youzu.test.qa":
            self.rgss2.delete_resource_ss2(del_name_input_dic)
        else:
            pass

    def get_resource_num(self, get_name_input_list):
        """
        查询资源,区分不同的游戏走不同的逻辑
        :param get_name_input_list: [资源名称]
        :return: {资源名称:数量}
        """
        if self.game_name == "com.youzu.test.qa":
            dic_res = self.rgss2.get_resource_num_ss2(get_name_input_list)
            return dic_res
        else:
            pass

    def get_sever_time(self):
        """
        获取服务器时间,区分不同的游戏走不同的逻辑
        :return:
        """
        if self.game_name == "com.youzu.test.qa":
            time_list = self.rgss2.get_sever_time_ss2()
            return time_list
        else:
            pass

    def test_game_protocol(self, add_name_input_list):
        """
        发送协议,发送后会回到当前界面,只发一条,发完查看结果
        主要用于协议测试
        :param add_name_input_list: list [协议编号,arges....] 编号查询协议用例表
        :return:
        """
        if self.game_name == "com.youzu.test.qa":  # ss2
            self.rgss2.test_protocol_ss2(add_name_input_list)
        else:
            pass

    def send_game_protocol(self, send_protocol_dic, find_name):
        """
        发送后会回到当前界面,只发一条,
        :param add_name_input_list: list [协议id,arges....]
        :param find_name:协议返回值中需要查询值的key,可以为none
        :return:value
        """
        if self.game_name == "com.youzu.test.qa":  # ss2
            find_name_value = self.rgss2.send_game_protocol(
                send_protocol_dic, find_name)
            return find_name_value
        else:
            pass

    def set_play_fuben_num(self, num):
        """
        添加资源,区分不同的游戏走不同的逻辑
        :param add_name_input_dic: {资源名称:数量}
        :return:
        """
        if self.game_name == "com.youzu.test.qa":
            self.rgss2.set_play_fuben_num(num)
        else:
            pass

    def set_play_liezhuan_num(self, num):
        """
        添加资源,区分不同的游戏走不同的逻辑
        :param add_name_input_dic: {资源名称:数量}
        :return:
        """
        if self.game_name == "com.youzu.test.qa":
            self.rgss2.set_play_liezhuan_num(num)
        else:
            pass