Esempio n. 1
0
    def testInit(cls):
        '''
                安装atx和apk

                :return:
                '''
        # 获取连接方式
        connect_type = getTest_info('connect_type', 'connect_type')
        if connect_type == 'ip':
            subprocess.Popen(
                ['adb', 'connect',
                 getTest_info('connect_type', 'ip')])
        elif connect_type == 'usb':
            subprocess.Popen(
                ['adb', 'disconnect',
                 getTest_info('connect_type', 'ip')])
        else:
            pass

        warnings.simplefilter('ignore', ResourceWarning)
        package_name = getTest_info('test_package_name', 'package_name')
        package_atx = getTest_info('test_package_name', 'package_atx')

        if not ADB().is_install(package_name):
            ADB().install_app(
                getTest_info('test_package_name', 'package_name_path'))
            Logging.info('install' + package_name + 'success')

        if not ADB().is_install(package_atx):
            os.system('python -m uiautomator2 init')
            Logging.info('install' + package_atx + 'success')
        else:
            pass
Esempio n. 2
0
    def __init__(self, serial, pkgname, apk_path, mode, runningminutes, throttle, pctuiautomatormix):
        self.serial = serial
        self.apk_path = apk_path
        self.mode = mode
        self.adb = ADB(serial)
        self.runningminutes = runningminutes
        self.throttle = throttle
        self.pctuiautomatormix = pctuiautomatormix
        self.process = None
        if apk_path:
            self.package = pkg.Package(self.apk_path)
            self.pkgname = self.package.name
        else:
            self.pkgname = pkgname
            self.package = None

        self.dl = l.DeviceLog(serial, self.pkgname)
Esempio n. 3
0
    def test_Sale200(self):
        driver = u2.connect('10.172.24.71')
        package_name = getTest_info('test_package_name', 'package_name')
        test_ScbQR_path = 'D:\pycharm\PycharmWorkSpase\AtxMultidevice\yamlsTestCase\Sale200Tester\Sale200.yaml'
        page = PagePo(driver, test_ScbQR_path)
        driver.shell('logcat -c')
        time.sleep(1)
        Logging.info('电池电量:' + str(ADB().get_battery_level()))
        Logging.info('磁盘信息' + str(ADB().get_disk()))
        # page.main()
        num = 2
        for i in range(num):
            # 单个用例执行次数
            page.main()
            # # 返回主页面从头开始
            driver.session(package_name)

        CPURate = ADB().get_cpu(package_name)
        Logging.info('CPU使用率为' + str(CPURate))
        Logging.info('电池电量:' + str(ADB().get_battery_level()))
        Logging.info('磁盘信息' + str(ADB().get_disk()))
        driver.shell('logcat -d > /sdcard/logcat.txt')
        driver.pull('/sdcard/logcat.txt',
                    'D:\pycharm\PycharmWorkSpase\AtxMultidevice\logcat.txt')
Esempio n. 4
0
class RunMonkey(object):
    def __init__(self, serial, pkgname, apk_path, mode, runningminutes, throttle, pctuiautomatormix):
        self.serial = serial
        self.apk_path = apk_path
        self.mode = mode
        self.adb = ADB(serial)
        self.runningminutes = runningminutes
        self.throttle = throttle
        self.pctuiautomatormix = pctuiautomatormix
        self.process = None
        if apk_path:
            self.package = pkg.Package(self.apk_path)
            self.pkgname = self.package.name
        else:
            self.pkgname = pkgname
            self.package = None

        self.dl = l.DeviceLog(serial, self.pkgname)


    def __del__(self):
        # windows adb不会释放logc.log需要强制释放一下
        if system is "Windows":
            U.cmd("taskkill /im adb.exe /f")

    def __start_back_strategy(self):
        U.Logging.info("start the thread of getback_strategy")
        self.man_talk_event = threading.Event()
        test_run = getback_strategy.r(self.serial, int(self.runningminutes), self.throttle, self.package, self.man_talk_event)
        test_run.start()

    def __start_new_monkey(self):
        U.Logging.info("run the AI monkey cmd")
        if self.mode == '--uiautomatormix':
            cmd = 'adb -s %s shell "CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey ' \
                  '-p %s --%s --running-minutes %s --pct-uiautomatormix %s --ignore-crashes --ignore-timeouts --throttle %s -v -v -v -v > /sdcard/monkeyout.txt 2>/sdcard/monkeyerr.txt" ' % (
                      self.serial, self.pkgname, self.mode, self.runningminutes, self.pctuiautomatormix, self.throttle)
        else:
            cmd = 'adb -s %s shell "CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey ' \
                  '-p %s --%s --running-minutes %s --ignore-crashes --ignore-timeouts --throttle %s -v -v -v -v > /sdcard/monkeyout.txt 2>/sdcard/monkeyerr.txt"' % (
                      self.serial, self.pkgname, self.mode, self.runningminutes, self.throttle)
        U.Logging.info(cmd)
        process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        U.Logging.info("waiting for 10s")
        return process

    def __initialization_arrangement(self):
        #初始化log
        U.Logging.info("init logs in device %s" % self.serial)
        self.dl.init()
        al = l.Al(self.serial)
        al.main(self.dl.log_path)

        # 推送必要的jar包和配置文件到手机
        U.Logging.info("push the monkey jars to %s" % self.serial)
        process = self.adb.adb('push conf/lib/framework.jar /sdcard/')
        stdout, stderr = process.communicate()
        if 'error' in stdout:
            U.Logging.error(stdout)
            return False
        self.adb.adb('push conf/lib/monkey.jar /sdcard/')
        self.adb.adb('push conf/lib/max.config /sdcard/')
        self.adb.adb('shell rm /sdcard/crash-dump.log')

        return True


    def __install_app(self):
        if self.apk_path:
            if self.package.boolpkg:
                install = InstallApp(self.serial, self.package)
                login = LoginApp(self.serial, self.package)
                return install.run_install() and login.login_app()
            else:
                U.Logging.error('get package name failed and skip')
                return False
        else:
            U.Logging.info("apk_path is null so start app only")
            return True

    """
        启动遍历程序过程
        执行步骤:
            1:安装应用
            2:登录
            3:开启back逻辑
            4:执行遍历命令
        :return:
    """

    def run(self):
        if self.__initialization_arrangement() and self.__install_app():
            self.__start_back_strategy()
            self.process = self.__start_new_monkey()
            return True
        else:
            U.Logging.error("install failed skip other process")
            return False
Esempio n. 5
0
 def testEnd(cls):
     # 退出app,返回apk主页面
     ADB().quit_app(getTest_info('test_package_name', 'package_name'))
Esempio n. 6
0
 def __init__(self, serial, package):
     self.serial = serial
     self.package = package
     self.adb = ADB(serial)
Esempio n. 7
0
class LoginApp:
    def __init__(self, serial, package):
        self.serial = serial
        self.package = package
        self.adb = ADB(serial)

    def login_app(self):
        d = Device('{}'.format(self.serial))
        component = "%s/%s" % (self.package.name, self.package.activity)
        self.adb.start_activity(component)
        time.sleep(15)

        try:
            if self.package.name == "com.cmcm.shorts":
                click_premission(d)
                d(resourceId="com.cmcm.shorts:id/home_bottom_user").click()
                d(resourceId="com.cmcm.shorts:id/layout_login_second").click()
                click_premission(d)
                # d(text="Guoliang Ren").click()
                d(resourceId="com.google.android.gms:id/account_name").click()
                time.sleep(15)
                click_premission(d)
                d.press.home()
            elif self.package.name == "com.cmcm.live":
                click_premission(d)
                d(resourceId="com.cmcm.live:id/layout_login_fifth").click()
                d(resourceId="com.cmcm.live:id/id_google_plus").click()
                click_premission(d)
                # d(text="Guoliang Ren").click()
                d(resourceId="com.google.android.gms:id/account_name").click()
                time.sleep(20)
                click_premission(d)
                d.press.home()
            elif self.package.name == "panda.keyboard.emoji.theme":
                d.click(770, 2100)
                time.sleep(2)
                d.press.back()
                time.sleep(2)
                d(text=' Cheetah Keyboard ❤ ❤ ❤ ').click()
                d(text='OK').click()
                d(text='OK').click()
                time.sleep(5)
                d.click(770, 2100)
                d(text=' Cheetah Keyboard ❤ ❤ ❤ ').click()
                time.sleep(5)
                click_premission(d)
                d.press.back()
                d.press.back()
                d.press.back()
            elif self.package.name == 'com.ksmobile.launcher':
                self.adb.quit_app(self.package.name)
                time.sleep(3)
                self.adb.start_activity(component)
                time.sleep(3)
                self.adb.send_key_event(3)
                d(resourceId="android:id/title").click()
                time.sleep(3)
                d(text="CM Launcher").click()
                time.sleep(3)
                d(resourceId="android:id/button_always").click()
            else:
                U.Logging.info("Don't need login")

            self.adb.quit_app('com.github.uiautomator')
            return True
        except Exception as e:
            U.Logging.error(e)
            U.Logging.error("login failed please check")
            return False