Esempio n. 1
0
 def test_return_home_fails(self, install_app, device: Device,
                            support_app: str):
     app = install_app(Application, support_app)
     app.start(activity=".MainActivity")
     assert device.foreground_activity() == app.package_name
     with pytest.raises(expected_exception=Exception) as excinfo:
         # Nobody would ever really pass a negative number, but our test app has only one activity screen. So
         # need to pass -1 to force the function to reach its back button key-press limit
         DeviceInteraction(device).return_home(keycode_back_limit=-1)
     assert "Max number of back button presses" in str(excinfo.value)
Esempio n. 2
0
 def test_return_home_succeeds(self, install_app, device: Device,
                               support_app: str):
     app = install_app(Application, support_app)
     with patch(
             'androidtestorchestrator.device.DeviceInteraction.home_screen_active',
             new_callable=Mock) as mock_home_screen_active:
         # Have to mock out call since inputting the KEYCODE_BACK event doesn't work for all devices/emulators
         mock_home_screen_active.return_value = True
         app.start(activity=".MainActivity")
         assert device.foreground_activity() == app.package_name
         device_nav = DeviceInteraction(device)
         device_nav.return_home()
         assert device_nav.home_screen_active()
 def test_clean_kill_throws_exception_when_home_screen_not_active(
         self, install_app, device: Device, support_app: str):
     app = install_app(Application, support_app)
     with patch('androidtestorchestrator.device.DeviceInteraction.home_screen_active', new_callable=Mock) as mock_home_screen_active, \
         patch('androidtestorchestrator.application.Application.pid', new_callable=PropertyMock) as mock_pid:
         mock_pid.return_value = "21445"
         # Force home_screen_active to be false to indicate clean_kill failed
         mock_home_screen_active.return_value = False
         app.start(".MainActivity")
         time.sleep(3)  # Give app time to come up
         assert device.foreground_activity() == app.package_name
         with pytest.raises(Exception) as exc_info:
             app.clean_kill()
         assert "Failed to background current foreground app" in str(
             exc_info.value)
 def test_clean_kill_succeeds(self, install_app, device: Device,
                              support_app: str):
     app = install_app(Application, support_app)
     with patch(
             'androidtestorchestrator.device.DeviceInteraction.home_screen_active',
             new_callable=Mock) as mock_home_screen_active:
         with patch('androidtestorchestrator.application.Application.pid',
                    new_callable=PropertyMock) as mock_pid:
             # Force home_screen_active to be True to indicate clean_kill made it to the home screen
             mock_home_screen_active.return_value = True
             # Force pid to return None to make it seem like the process was actually killed
             mock_pid.return_value = None
             app.start(".MainActivity")
             time.sleep(3)  # Give app time to come up
             assert device.foreground_activity() == app.package_name
             # clean_kill doesn't return anything, so just make sure no exception is raised
             app.clean_kill()
 def test_clean_kill_throws_exception_when_pid_still_existing(
         self, install_app, device: Device, support_app: str):
     app = install_app(Application, support_app)
     with patch(
             'androidtestorchestrator.device.DeviceInteraction.home_screen_active',
             new_callable=Mock) as mock_home_screen_active:
         with patch('androidtestorchestrator.application.Application.pid',
                    new_callable=PropertyMock) as mock_pid:
             # Force home_screen_active to be True to indicate clean_kill made it to the home screen
             mock_home_screen_active.return_value = True
             # Force pid to return a fake process id to indicate clean_kill failed
             mock_pid.return_value = 1234
             app.start(".MainActivity")
             time.sleep(3)  # Give app time to come up
             assert device.foreground_activity() == app.package_name
             with pytest.raises(Exception) as exc_info:
                 app.clean_kill()
             assert "Detected app process is still running" in str(
                 exc_info.value)