def test_start_ping(self): with patch("uiautomator.JsonRPCClient") as JsonRPCClient: JsonRPCClient.return_value.ping.return_value = "pong" server = AutomatorServer() server.adb = MagicMock() server.adb.forward.return_value = 0 self.assertEqual(server.ping(), "pong")
def test_start_success(self): server = AutomatorServer() server.push = MagicMock() server.push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = "pong" server.adb = MagicMock() server.start() server.adb.cmd.assert_valled_onec_with('shell', 'uiautomator', 'runtest', 'bundle.jar', 'uiautomator-stub.jar', '-c', 'com.github.uiautomatorstub.Stub')
def test_start_success(self): server = AutomatorServer() server.push = MagicMock() server.push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = "pong" server.adb = MagicMock() server.start() server.adb.cmd.assert_called_with('shell', 'uiautomator', 'runtest', 'bundle.jar', 'uiautomator-stub.jar', '-c', 'com.github.uiautomatorstub.Stub')
def test_start_error(self): server = AutomatorServer() server.push = MagicMock() server.push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = None server.adb = MagicMock() with patch("time.sleep"): with self.assertRaises(IOError): server.start()
def test_start_success(self): server = AutomatorServer() server.download_and_push = MagicMock() server.download_and_push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = "pong" with patch("uiautomator.adb") as adb: adb.forward.return_value = 0 with patch.dict('os.environ', {'LOCAL_PORT': '9000', 'DEVICE_PORT': '9000'}): server.start() adb.cmd.assert_valled_onec_with('shell', 'uiautomator', 'runtest', 'bundle.jar', 'uiautomator-stub.jar', '-c', 'com.github.uiautomatorstub.Stub') adb.forward.assert_called_once_with(9000, 9000)
def test_start_error(self): server = AutomatorServer() server.download_and_push = MagicMock() server.download_and_push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = None with patch("uiautomator.adb") as adb: adb.forward.return_value = 0 with patch.dict('os.environ', {'LOCAL_PORT': '9000', 'DEVICE_PORT': '9000'}): with patch("time.sleep"): with self.assertRaises(IOError): server.start() adb.forward.assert_called_once_with(9000, 9000)
def test_start_success_over_api_18(self): server = AutomatorServer() server.push = MagicMock() server.push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = "pong" server.sdk_version = MagicMock() server.sdk_version.return_value = 20 server.adb = MagicMock() server.start() server.adb.cmd.assert_called_with( "shell", "am", "instrument", "-w", "com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner" )
def test_start_ping_none(self): with patch("uiautomator.JsonRPCClient") as JsonRPCClient: JsonRPCClient.return_value.ping.side_effect = Exception("error") server = AutomatorServer() self.assertEqual(server.ping(), None)
def test_start_ping_none(self): with patch.dict('os.environ', {'LOCAL_PORT': '9000', 'DEVICE_PORT': '9000'}): with patch("uiautomator.JsonRPCClient") as JsonRPCClient: JsonRPCClient.return_value.ping.side_effect = Exception("error") server = AutomatorServer() self.assertEqual(server.ping(), None)
def test_start_ping(self): with patch.dict('os.environ', {'LOCAL_PORT': '9000', 'DEVICE_PORT': '9000'}): with patch("uiautomator.JsonRPCClient") as JsonRPCClient: JsonRPCClient.return_value.ping.return_value = "pong" server = AutomatorServer() self.assertEqual(server.ping(), "pong")
"""start and quit rpc server on device. """ from uiautomator import AutomatorServer r = AutomatorServer() print "Check the RPC server response ..." if r.ping(): print "You see that." else: print "No response"