示例#1
0
def tools_main_run():
    parser = argparse.ArgumentParser(
        description="Get devices info and get apk info.")

    parser.add_argument('--apk', help="apk file path.")

    parser.add_argument(
        '--adb',
        default='adb',
        help="set the `adb` path if ANDROID_HOME not configured. default: adb "
    )

    parser.add_argument(
        '--aapt',
        default='aapt',
        help=
        "set the `aapt` path if ANDROID_HOME not configured. default: aapt ")

    color_print("appuidriver {}".format(__version__), "GREEN")

    args = parser.parse_args()

    if args.apk:
        print(
            Android.gen_capabilities(apk_abs_path=args.apk,
                                     aapt_exe_4path=args.aapt))
    else:
        devices = Android.get_devices(args.adb)
        print(devices)
示例#2
0
    def setUpClass(cls):
        '''
        @note:  adb version 1.0.39;  %ANDROID_HOME% = D:\auto\buffer\test\test_rtsf_web\android; 天天模拟器 v2.5.6
        '''
        platform_tools = r'C:\d_disk\auto\buffer\test\tools\android\platform-tools'
        cls._adb_exe_path = os.path.join(platform_tools, "adb.exe")
        cls._aapt_exe_path = os.path.join(platform_tools, "aapt.exe")
        cls._apk_abs_path = r'C:\d_disk\auto\buffer\test\tools\android\ApiDemos-debug.apk'

        cls.server = AppiumJs(port=4723).bind_device(
            device_id="127.0.0.1:6555")
        cls.server.start_server()

        devices = Android.get_devices(cls._adb_exe_path)
        device_id, properties = devices.popitem()

        desired_cap = Android.gen_capabilities(
            apk_abs_path=cls._apk_abs_path, aapt_exe_4path=cls._aapt_exe_path)
        desired_cap["deviceName"] = device_id
        desired_cap["platformVersion"] = properties.get('android_version')
        #         desired_cap = {
        #             'platformName': 'Android',
        #             'deviceName': '127.0.0.1:6555',
        #             'platformVersion': '4.4.4',
        #             'app': 'C: \\d_disk\\auto\\buffer\\test\\tools\\android\\ApiDemos-debug.apk',
        #             'appPackage': 'io.appium.android.apis',
        #             'appWaitPackage': 'io.appium.android.apis',
        #             'appActivity': 'io.appium.android.apis.ApiDemos',
        #             'unicodeKeyboard': True,
        #             'resetKeyboard': True,
        #             'newCommandTimeout':120000,
        #         }
        App.driver = Android.gen_remote_driver(executor=Android.get_executor(
            "127.0.0.1", 4723),
                                               capabilities=desired_cap)
示例#3
0
    def __init__(self):
        super(LocalDriver, self).__init__(is_local_driver=True)
        desired_cap = Android.gen_capabilities(
            apk_abs_path=LocalDriver._apk_abs_path,
            app_package=LocalDriver._app_package,
            app_activity=LocalDriver._app_activity,
            aapt_exe_4path=LocalDriver._aapt_exe_path)

        devices = Android.get_devices(LocalDriver._adb_exe_path)
        device_id, properties = devices.popitem()
        desired_cap["deviceName"] = device_id
        desired_cap["platformVersion"] = properties.get('android_version')

        self._default_drivers = [
            ("",
             Android.gen_remote_driver(executor=Android.get_executor(
                 "localhost", 4723),
                                       capabilities=desired_cap))
        ]
示例#4
0
    def test_gen_remote_driver(self):
        server = AppiumJs(port=4723).bind_device(device_id="127.0.0.1:6555")
        server.start_server()

        desired_cap = Android.gen_capabilities(
            apk_abs_path=self._apk_abs_path,
            aapt_exe_4path=self._aapt_exe_path)
        self.assertIsInstance(desired_cap, dict)

        devices = Android.get_devices(self._adb_exe_path)
        self.assertIsInstance(devices, dict)

        device_id, properties = devices.popitem()
        desired_cap["deviceName"] = device_id
        desired_cap["platformVersion"] = properties.get('android_version')

        driver = Android.gen_remote_driver(executor=Android.get_executor(
            "localhost", 4723),
                                           capabilities=desired_cap)
        driver.quit()
        server.stop_server()
示例#5
0
    def test_get_devices(self):
        devices = Android.get_devices(self._adb_exe_path)
        #print("devices:",devices)

        if devices:
            device_id, properties = devices.popitem()
            self.assertIsNotNone(device_id)
            for prop in ("model", "linux_version", "ip", "cpu",
                         "android_version", "pad_version"):
                self.assertIn(prop, properties)
        else:
            self.assertIsInstance(devices, dict)
示例#6
0
    def __init__(self):
        super(RemoteDriver, self).__init__(is_local_driver=False)
        desired_cap = Android.gen_capabilities(
            apk_abs_path=RemoteDriver._apk_abs_path,
            app_package=RemoteDriver._app_package,
            app_activity=RemoteDriver._app_activity,
            aapt_exe_4path=RemoteDriver._aapt_exe_path)
        self._default_devices = []
        self._default_drivers = []
        executors = Android.get_remote_executors(
            hub_ip=RemoteDriver._remote_ip, port=RemoteDriver._remote_port)
        for udid, udversion, executor in executors:
            fn = FileSystemUtils.get_legal_filename(executor)
            self._default_devices.append(fn)

            cap = desired_cap.copy()
            cap["deviceName"] = udid
            cap["platformVersion"] = udversion
            self._default_drivers.append(
                (fn,
                 Android.gen_remote_driver(executor=executor,
                                           capabilities=cap)))
示例#7
0
    def test_gen_capabilities(self):
        # e.g.1 with apk file
        desired_cap = Android.gen_capabilities(
            apk_abs_path=self._apk_abs_path,
            aapt_exe_4path=self._aapt_exe_path)
        #print("caps: ",desired_cap)
        self.assertIsInstance(desired_cap, dict)
        self.assertEqual(desired_cap["app"], self._apk_abs_path)
        self.assertEqual(desired_cap["appPackage"], 'io.appium.android.apis')
        self.assertEqual(desired_cap["appWaitPackage"],
                         'io.appium.android.apis')
        self.assertEqual(desired_cap["appActivity"],
                         'io.appium.android.apis.ApiDemos')

        self.assertEqual(desired_cap["platformName"], "Android")
        self.assertEqual(desired_cap["deviceName"], None)
        self.assertEqual(desired_cap["platformVersion"], None)

        # e.g.2 with apk file and specify activity
        desired_cap = Android.gen_capabilities(
            apk_abs_path=self._apk_abs_path,
            app_activity='.animation.BouncingBalls',
            aapt_exe_4path=self._aapt_exe_path)
        self.assertEqual(desired_cap["app"], self._apk_abs_path)
        self.assertEqual(desired_cap["appPackage"], 'io.appium.android.apis')
        self.assertEqual(desired_cap["appActivity"],
                         '.animation.BouncingBalls')

        # e.g.3  without apk file
        desired_cap = Android.gen_capabilities(
            app_package='io.appium.android.apis',
            app_activity='.animation.BouncingBalls',
            aapt_exe_4path=self._aapt_exe_path)
        self.assertEqual(desired_cap["app"], None)
        self.assertEqual(desired_cap["appPackage"], 'io.appium.android.apis')
        self.assertEqual(desired_cap["appActivity"],
                         '.animation.BouncingBalls')
示例#8
0
    def test_gen_remote_driver_grid(self):
        self._hub.start_server()

        device_name = "127.0.0.1:6555"
        device_version = "4.4.4"
        node_ip = "localhost"
        port = 4723

        server = AppiumJs(port=port).bind_device(
            device_id=device_name,
            platform_version=device_version).node(node_ip,
                                                  hub_address=("localhost",
                                                               4444))
        server.start_server()

        drivers = []
        desired_cap = Android.gen_capabilities(
            apk_abs_path=self._apk_abs_path,
            aapt_exe_4path=self._aapt_exe_path)
        executors = Android.get_remote_executors(hub_ip="localhost", port=4444)
        for udid, udversion, executor in executors:
            cap = desired_cap.copy()
            cap["deviceName"] = udid
            cap["platformVersion"] = udversion

            driver = Android.gen_remote_driver(executor=executor,
                                               capabilities=cap)
            drivers.append(driver)
            driver.quit()

        self.assertEqual(len(drivers), 1)
        self.assertEqual(udid, device_name)
        self.assertEqual(udversion, device_version)
        self.assertEqual(executor, "http://{}:{}/wd/hub".format(node_ip, port))

        server.stop_server()
        self._hub.stop_server()