Ejemplo n.º 1
0
def start_game():
    #检测adb设备是否连接
    logger.debug("connect device name:{0},android version:{1}".format(
        CheckDevices.getDeviceName(), CheckDevices.getAndroidVersion()))

    # 步骤 1 ,本地环境准备,清楚数据,拉起游戏
    device._clear_user_info(local_package)
    device.launch_app(local_package)
    time.sleep(10)

    #步骤 2 ,点击任意位置跳过开场动画
    excute_adb("shell input tap 10 10")

    version = engine.get_sdk_version()
    logger.debug("Version Information:{0}".format(version))

    # 步骤 3 , 设置ip和登录名
    name = find_element_wait(
        "/UGUIRoot/Canvas/uilogin_new_v1/canvas_topui/login/input_account")
    engine.input(name, player_name)

    result = engine.call_registered_handler("AutoSetIp", ip)
    logger.debug(result)

    enterBtn = engine.find_element(
        "/UGUIRoot/Canvas/uilogin_new_v1/canvas_topui/login/button_login")
    engine.click(enterBtn)

    startBtn = find_element_wait(
        "/UGUIRoot/Canvas/uilogin_new_v1/canvas_topui/entergame/btn_begin",
        max_count=3,
        sleeptime=1)
    if startBtn is None:
        logger.debug(u"登录失败")
        return
    else:
        screen_shot_click(startBtn, sleeptime=0, exception=True)

    enterGame = find_element_wait(
        "/UGUIRoot/Canvas1/uiselectrole_v1/right_panel/btn_entry",
        max_count=5,
        sleeptime=1)
    if enterGame is None:
        logger.debug(u"登录失败")
        return
    else:
        engine.click(enterGame)

    mainpage = find_element_wait("/UGUIRoot/Canvas/uimainpage_subsys_v1")
    if mainpage is None:
        logger.debug(u"登录失败")
    else:
        logger.debug(u"登录成功")
Ejemplo n.º 2
0
class TestInfo(object):
    r = readConfig()
    PACKAGE = r.getValues("package")  # test package name
    DEVICES = r.getValues("devices")
    if isinstance(DEVICES, str):
        if "127" in DEVICES:
            file = excute_adb("connect {}".format(DEVICES))
    elif isinstance(DEVICES, list):
        for device in DEVICES:
            if "127" in device:
                file = excute_adb("connect {}".format(device))

    TESTCASE = r.getValues("testcase")
Ejemplo n.º 3
0
    def launch_app(self, package, activity="android.intent.category.LAUNCHER"):
        """
        启动游戏,游戏启动后返回。返回启动后的Pid和拉起时间,device实例会保存Pid的值
        :param package:
        :return:(234,2341)分别代表打起后的pid和拉起时间
        """
        result = self.adb.cmd_wait("shell", "monkey", "-p", package, "-c",
                                   activity, "1")
        if result:
            content = result
            logger.debug(content)
        result = excute_adb("shell ps")

        if result:
            pattern_str = r"(?P<user>\S+)\s+(?P<pid>\d+)\s+(?P<ppid>\d+)\s.*{0}\s+".format(
                package)
            pattern = re.compile(pattern_str)
            line = result.readline()
            while line:
                match = pattern.search(line)
                if match:
                    pid = match.groupdict().get("pid")
                    pid = int(pid)
                    return pid, 0
                line = result.readline()
Ejemplo n.º 4
0
 def _clear_user_info(self, package):
     if package == None:
         raise WeTestInvaildArg("Package Name can't be none")
     logger.debug("adb shell pm clear {0}".format(package))
     result = excute_adb("shell pm clear {0}".format(package))
     if result:
         content = result.read()
         logger.debug(content)
Ejemplo n.º 5
0
 def _clear_user_info(self, package):
     if package == None:
         raise WeTestInvaildArg("Package Name can't be none")
     logger.debug("adb shell pm clear {0}".format(package))
     result = excute_adb("shell pm clear {0}".format(package))
     if result:
         content = result.read()
         logger.debug(content)
Ejemplo n.º 6
0
    def excute_adb(self, cmd):
        """
            Open a pipe to/from a adb command returning a file object,when command is end

            if testcat is run on wetest platorm,you can put your file to UPLOADDIR,and download from reporter
        :Usage:
            >>> import wpyscripts.manager as manager
            >>> device=manager.get_device()
            >>> device.excute_adb_shell("pull /data/local/tmp {0}/perform.txt".format(os.environ.get("UPLOADDIR",".")))
        :param cmd: adb command
        :return:a file object
        """
        return excute_adb(cmd)
Ejemplo n.º 7
0
    def excute_adb(self, cmd):
        """
            Open a pipe to/from a adb command returning a file object,when command is end

            if testcat is run on wetest platorm,you can put your file to UPLOADDIR,and download from reporter
        :Usage:
            >>> import wpyscripts.manager as manager
            >>> device=manager.get_device()
            >>> device.excute_adb_shell("pull /data/local/tmp {0}/perform.txt".format(os.environ.get("UPLOADDIR",".")))
        :param cmd: adb command
        :return:a file object
        """
        return excute_adb(cmd)
Ejemplo n.º 8
0
    def launch_app(self, package, activity="android.intent.category.LAUNCHER"):
        """
        启动游戏,游戏启动后返回。返回启动后的Pid和拉起时间,device实例会保存Pid的值
        :param package:
        :return:(234,2341)分别代表打起后的pid和拉起时间
        """
        result = self.adb.cmd_wait("shell", "monkey", "-p", package, "-c", activity, "1")
        if result:
            content = result
            logger.debug(content)
        result = excute_adb("shell ps")

        if result:
            pattern_str = r"(?P<user>\S+)\s+(?P<pid>\d+)\s+(?P<ppid>\d+)\s.*{0}\s+".format(package)
            pattern = re.compile(pattern_str)
            line = result.readline()
            while line:
                match = pattern.search(line)
                if match:
                    pid = match.groupdict().get("pid")
                    pid = int(pid)
                    return pid, 0
                line = result.readline()