def setUp(self): platform_tools = r'C:\d_disk\auto\buffer\test\tools\android\platform-tools' self._adb_exe_path = os.path.join(platform_tools, "adb.exe") self._aapt_exe_path = os.path.join(platform_tools, "aapt.exe") self._apk_abs_path = r'C:\d_disk\auto\buffer\test\tools\android\ApiDemos-debug.apk' jar_path = r'C:\d_disk\auto\buffer\test\tools\seleniumjar\selenium-server-standalone-3.14.0.jar' java_path = "java" self._hub = SeleniumJar(jar_path, java_path).hub(4444)
def node_main_run(): parser = argparse.ArgumentParser(description="selenium server jar with node mode.") parser.add_argument( '--java-path', default='java', help="path of java. default is `java` if JAVA_HOME is configured. ") parser.add_argument( '--port', type = int, default = 5555, help="listen port for node mode. default port: 5555") parser.add_argument( '--hub-ip', default = "localhost", help="hub host or hub ip which need to connect. default host: localhost") parser.add_argument( '--hub-port', type = int, default = 4444, help="hub port which need to connect. default: 4444") parser.add_argument( 'server_jar', help="selenium server jar path for selenium grid mode") color_print("webuidriver {}".format(__version__), "GREEN") args = parser.parse_args() SeleniumJar(args.server_jar, args.java_path).node(args.port,(args.hub_ip, args.hub_port)).start_server()
def hub_main_run(): parser = argparse.ArgumentParser(description="selenium server jar with hub mode.") parser.add_argument( '--java-path', default='java', help="path of java. default is `java` if JAVA_HOME is configured. ") parser.add_argument( '--port', type = int, default = 4444, help="listen port for hub mode. default port: 4444") parser.add_argument( 'server_jar', help="selenium server jar path for selenium grid mode") color_print("webuidriver {}".format(__version__), "GREEN") args = parser.parse_args() SeleniumJar(args.server_jar, args.java_path).hub(args.port).start_server()
def node_main_run(): parser = argparse.ArgumentParser(description="selenium server jar with node mode.") parser.add_argument( '--java-path', default='java', help="path of java. default is `java` if JAVA_HOME is configured. ") # VPN网络或者计算机有多个IP的情况(如VMware Network Adapter VMnet1),就会出现探测的IP不准确的情况 # 使用host 参数可以用于这种情况,指定要注册的IP。通常情况不需要指定 parser.add_argument( '--host', default="", help=""" IP or hostname : usually determined automatically. Most commonly useful in exotic network configurations (e.g. network with VPN) """) parser.add_argument( '--port', type=int, default=5555, help="listen port for node mode. default port: 5555") parser.add_argument( '--hub-ip', default="localhost", help="hub host or hub ip which need to connect. default host: localhost") parser.add_argument( '--hub-port', type=int, default=4444, help="hub port which need to connect. default: 4444") parser.add_argument( '--background', action="store_true", help="run this command in the background") parser.add_argument( 'server_jar', help="selenium server jar path for selenium grid mode") color_print("webuidriver {}".format(__version__), "GREEN") args = parser.parse_args() SeleniumJar(args.server_jar, args.java_path)\ .node((args.host, args.port), (args.hub_ip, args.hub_port)).start_server(block=not args.background)
def test_RemoteDriver(self): RemoteDriver._aapt_exe_path = self._aapt_exe_path RemoteDriver._apk_abs_path = self._apk_abs_path RemoteDriver._app_package = self._app_package RemoteDriver._app_activity = self._app_activity hub = SeleniumJar(self.jar_path, self.java_path).hub(4444) hub.start_server() node = AppiumJs(port=4723).bind_device( device_id="127.0.0.1:6555", platform_version="4.4.4").node("localhost", hub_address=("localhost", 4444)) node.start_server() runner = TestRunner(runner=RemoteDriver).run(self.case_file) html_report = runner.gen_html_report() print(html_report) self.assertIsInstance(html_report, (list, tuple)) node.stop_server() hub.stop_server()
def test_RemoteDriver_to_be_runner(self): hub = SeleniumJar(self.jar_path, self.java_path).hub(4444) hub.start_server() node = SeleniumJar(self.jar_path, self.java_path).node(5555, ("localhost", 4444)) node.start_server() runner = TestRunner(runner=RemoteDriver).run(self.case_file) html_report = runner.gen_html_report() print(html_report) self.assertIsInstance(html_report, (list, tuple)) hub.stop_server() node.stop_server()
def test_RemoteDriver(self): hub = SeleniumJar(self.jar_path, self.java_path).hub(4444) hub.start_server() node = SeleniumJar(self.jar_path, self.java_path).node(5555, ("localhost", 4444)) node.start_server() obj = RemoteDriver() device_id, driver = obj.drivers[0][0], obj.drivers[0][1] print("id:{0}, driver:{1}".format(device_id, driver)) self.assertIn("wdhub", device_id) driver.get('http://www.baidu.com') driver.close() driver.quit() hub.stop_server() node.stop_server()
def setUpClass(cls): jar_path = r'D:\auto\buffer\test\test_rtsf_web\selenium-server-standalone-3.14.0.jar' java_path = "java" cls.hub = SeleniumJar(jar_path, java_path).hub(4444) cls.node = SeleniumJar(jar_path, java_path).node(5555, ("localhost", 4444))
def test_webuidriver_remote(self): """ Selenium grid mode. You can use SeleniumJar to start service. Also, you can use command lines if you installed rtsf-web, like this: wrhub selenium-server-standalone-3.14.0.jar --port 4444 wrnode selenium-server-standalone-3.14.0.jar --port 5555 --hub-ip 10.154.123.74 --hub-port 4444 """ hub = SeleniumJar(self.jar_path, self.java_path).hub(4444) hub.start_server() node = SeleniumJar(self.jar_path, self.java_path).node(5555, ("localhost", 4444)) node.start_server() executors = SeleniumHatch.get_remote_executors("localhost", 4444) # self.driver = webuidriver.Remote(executor, options=self.opt) 与下面语句效果是一样的 self.driver = webuidriver.Remote(executors[0], desired_capabilities=self.opt.to_capabilities()) self.driver.get('http://www.baidu.com') time.sleep(1) # webuidriver.Remote 是 webdriver.Chrome 的子类 self.assertTrue(issubclass(webuidriver.Chrome, webdriver.Remote)) self.assertIsInstance(self.driver, webdriver.Remote) self.driver.close() self.driver.quit() hub.stop_server() node.stop_server()
class TestAndroid(unittest.TestCase): def setUp(self): platform_tools = r'C:\d_disk\auto\buffer\test\tools\android\platform-tools' self._adb_exe_path = os.path.join(platform_tools, "adb.exe") self._aapt_exe_path = os.path.join(platform_tools, "aapt.exe") self._apk_abs_path = r'C:\d_disk\auto\buffer\test\tools\android\ApiDemos-debug.apk' jar_path = r'C:\d_disk\auto\buffer\test\tools\seleniumjar\selenium-server-standalone-3.14.0.jar' java_path = "java" self._hub = SeleniumJar(jar_path, java_path).hub(4444) 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') 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) 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() 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()