diff --git a/percy/lib/cli_wrapper.py b/percy/lib/cli_wrapper.py index 9bdbf26..dfa3a9c 100644 --- a/percy/lib/cli_wrapper.py +++ b/percy/lib/cli_wrapper.py @@ -77,15 +77,14 @@ def post_failed_event(self, error): log(e, on_debug=True) return None - def post_poa_screenshots(self, name, session_id, command_executor_url, capabilities, desired_capabilities, options=None, sync=None): + def post_poa_screenshots(self, name, session_id, command_executor_url, capabilities, desired_capabilities, options=None): body = { 'sessionId': session_id, 'commandExecutorUrl': command_executor_url, 'capabilities': dict(capabilities), 'sessionCapabilites':dict(desired_capabilities), 'snapshotName': name, - 'options': options, - 'sync': sync + 'options': options } body['client_info'] = Environment._get_client_info() diff --git a/percy/lib/percy_automate.py b/percy/lib/percy_automate.py index 6bea167..2d7bee8 100644 --- a/percy/lib/percy_automate.py +++ b/percy/lib/percy_automate.py @@ -10,7 +10,6 @@ IGNORE_ELEMENT_ALT_KEY = 'ignoreRegionAppiumElements' CONSIDER_ELEMENT_KEY = 'consider_region_appium_elements' CONSIDER_ELEMENT_ALT_KEY = 'considerRegionAppiumElements' -SYNC = 'sync' class PercyOnAutomate: def __init__(self, driver): @@ -40,10 +39,8 @@ def screenshot(self, name: str, **kwargs): ignore_region_elements = [element.id for element in options.get(IGNORE_ELEMENT_KEY, [])] consider_region_elements = [element.id for element in options.get(CONSIDER_ELEMENT_KEY, [])] - sync = options.get(SYNC, None) options.pop(IGNORE_ELEMENT_KEY, None) options.pop(CONSIDER_ELEMENT_KEY, None) - options.pop(SYNC, None) return CLIWrapper().post_poa_screenshots( name, @@ -51,7 +48,7 @@ def screenshot(self, name: str, **kwargs): metadata.command_executor_url, metadata.capabilities, metadata.session_capabilities, - { **options, "ignore_region_elements": ignore_region_elements, "consider_region_elements" : consider_region_elements, "sync": sync } + { **options, "ignore_region_elements": ignore_region_elements, "consider_region_elements" : consider_region_elements } ) except Exception as e: log(f'Could not take Screenshot "{name}"') diff --git a/tests/test_app_percy.py b/tests/test_app_percy.py index ad1cc7f..2971077 100644 --- a/tests/test_app_percy.py +++ b/tests/test_app_percy.py @@ -18,6 +18,7 @@ class TestAppPercy(unittest.TestCase): comparison_response = {'link': 'https://snapshot_url', 'success': True} + sync_response = {'link': 'https://snapshot_url', 'data': 'sync-data', 'success': True} @patch('appium.webdriver.webdriver.WebDriver') def setUp(self, mock_webdriver): @@ -171,3 +172,21 @@ def test_invalid_driver(self): with self.assertRaises(Exception) as e: AppPercy(Mock()) self.assertIsInstance(e.exception, DriverNotSupported) + + @patch.object(CLIWrapper, 'post_screenshots', MagicMock(return_value=sync_response)) + @patch.object(GenericProvider, '_write_screenshot', MagicMock(return_value='path-to-png-file')) + @patch.object(AppAutomate, 'execute_percy_screenshot_begin', MagicMock(return_value={'deviceName': 'Google Pixel 4', + 'osVersion': '12.0', + 'buildHash': 'abc', + 'sessionHash': 'def' + })) + @patch.object(AppAutomate, 'execute_percy_screenshot_end', MagicMock(return_value=None)) + @patch.object(Metadata, 'session_id', PropertyMock(return_value='unique_session_id')) + @patch.dict(os.environ, {"PERCY_DISABLE_REMOTE_UPLOADS": "true"}) + def test_android_on_app_automate(self): + with patch('percy.metadata.AndroidMetadata.remote_url', new_callable=PropertyMock) as mock_remote_url: + mock_remote_url.return_value = 'url-of-browserstack-cloud' + app_percy = AppPercy(self.mock_android_webdriver) + self.assertEqual(app_percy.screenshot('screenshot 1', sync = True), 'sync-data') + self.assertTrue(isinstance(app_percy.metadata, AndroidMetadata)) + self.assertTrue(isinstance(app_percy.provider, AppAutomate)) diff --git a/tests/test_screenshot.py b/tests/test_screenshot.py index 4df1454..b43333d 100644 --- a/tests/test_screenshot.py +++ b/tests/test_screenshot.py @@ -68,13 +68,13 @@ def mock_screenshot(fail=False): status=(500 if fail else 200), ) -def mock_poa_screenshot(fail=False): +def mock_poa_screenshot(fail=False, sync=False): + body = '{ "success": ' + ("true" if not fail else 'false, "error": "test"') + "}" + if sync: body = '{ "success": "true", "data": "sync-data" }' httpretty.register_uri( httpretty.POST, "http://localhost:5338/percy/automateScreenshot", - body=( - '{ "success": ' + ("true" if not fail else 'false, "error": "test"') + "}" - ), + body=body, status=(500 if fail else 200), ) @@ -287,5 +287,19 @@ def test_posts_screenshot_poa(self): self.assertEqual(s2['options']['ignore_region_elements'], ['Dummy_id']) self.assertEqual(s2['options']['consider_region_elements'], ['Consider_Dummy_id']) + def test_posts_screenshot_poa_with_sync(self): + mock_healthcheck(type="automate") + mock_poa_screenshot(False, True) + + driver = Mock(spec=WebDriver) + driver.session_id = 'Dummy_session_id' + driver.capabilities = { 'key': 'value' } + driver.desired_capabilities = { 'key': 'value' } + driver.command_executor = Mock() + driver.command_executor._url = 'https://hub-cloud.browserstack.com/wd/hub' + self.mock_webdriver.capabilities = { 'key': 'value' } + + self.assertEqual(percy_screenshot(driver, 'Snapshot 3', options = {'sync': True}), 'sync-data') + if __name__ == "__main__": unittest.main()