From 8978e92042b7ececd8cf89c8b4a637ce1f050b5b Mon Sep 17 00:00:00 2001 From: Yevheniia Berdnyk Date: Tue, 4 Jul 2023 20:26:05 +0300 Subject: [PATCH] e2e: nightly fixes --- test/appium/tests/__init__.py | 4 +- test/appium/tests/base_test_case.py | 58 ++++++++++--------- .../critical/chats/test_1_1_public_chats.py | 5 +- .../critical/test_public_chat_browsing.py | 1 + 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/test/appium/tests/__init__.py b/test/appium/tests/__init__.py index bf87fa2e7a..706e37ee75 100644 --- a/test/appium/tests/__init__.py +++ b/test/appium/tests/__init__.py @@ -12,7 +12,7 @@ from support.appium_container import AppiumContainer from support.test_data import TestSuiteData -async def start_threads(quantity: int, func: type, returns: dict, *args): +async def start_threads(test_name: str, quantity: int, func: type, returns: dict, *args): loop = asyncio.get_event_loop() # from tests.conftest import sauce # for _ in range(60): @@ -26,7 +26,7 @@ async def start_threads(quantity: int, func: type, returns: dict, *args): returns[k] = await returns[k] break except MaxRetryError: - print("MaxRetryError when creating a driver") + print("MaxRetryError when creating a driver for %s" % test_name) time.sleep(10) return returns diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 7e23f9b034..f8d9dc9faa 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -299,7 +299,8 @@ def create_shared_drivers(quantity): capabilities = {'maxDuration': 3600} print('SC Executor: %s' % executor_sauce_lab) try: - drivers = loop.run_until_complete(start_threads(quantity, + drivers = loop.run_until_complete(start_threads(test_suite_data.current_test.name, + quantity, Driver, drivers, executor_sauce_lab, @@ -310,7 +311,7 @@ def create_shared_drivers(quantity): if len(drivers) < quantity: test_suite_data.current_test.testruns[-1].error = "Not all %s drivers are created" % quantity return drivers, loop - except MaxRetryError as e: + except (MaxRetryError, AttributeError) as e: test_suite_data.current_test.testruns[-1].error += "%s" % e.reason raise e @@ -394,31 +395,34 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase): from tests.conftest import sauce requests_session = requests.Session() requests_session.auth = (sauce_username, sauce_access_key) - if cls.drivers: - for _, driver in cls.drivers.items(): - session_id = driver.session_id - try: - sauce.jobs.update_job(username=sauce_username, job_id=session_id, name=cls.__name__) - except (RemoteDisconnected, SauceException): - pass - try: - driver.quit() - except WebDriverException: - pass - url = 'https://api.%s/rest/v1/%s/jobs/%s/assets/%s' % (apibase, sauce_username, session_id, "log.json") - try: - WebDriverWait(driver, 60, 2).until(lambda _: requests_session.get(url).status_code == 200) - commands = requests_session.get(url).json() - for command in commands: - try: - if command['message'].startswith("Started "): - for test in test_suite_data.tests: - if command['message'] == "Started %s" % test.name: - test.testruns[-1].first_commands[session_id] = commands.index(command) + 1 - except KeyError: - continue - except (RemoteDisconnected, requests.exceptions.ConnectionError): - pass + try: + cls.drivers + except AttributeError: + pass + for _, driver in cls.drivers.items(): + session_id = driver.session_id + try: + sauce.jobs.update_job(username=sauce_username, job_id=session_id, name=cls.__name__) + except (RemoteDisconnected, SauceException): + pass + try: + driver.quit() + except WebDriverException: + pass + url = 'https://api.%s/rest/v1/%s/jobs/%s/assets/%s' % (apibase, sauce_username, session_id, "log.json") + try: + WebDriverWait(driver, 60, 2).until(lambda _: requests_session.get(url).status_code == 200) + commands = requests_session.get(url).json() + for command in commands: + try: + if command['message'].startswith("Started "): + for test in test_suite_data.tests: + if command['message'] == "Started %s" % test.name: + test.testruns[-1].first_commands[session_id] = commands.index(command) + 1 + except KeyError: + continue + except (RemoteDisconnected, requests.exceptions.ConnectionError): + pass if cls.loop: cls.loop.close() for test in test_suite_data.tests: diff --git a/test/appium/tests/critical/chats/test_1_1_public_chats.py b/test/appium/tests/critical/chats/test_1_1_public_chats.py index 09545d6385..c1c2045ee2 100644 --- a/test/appium/tests/critical/chats/test_1_1_public_chats.py +++ b/test/appium/tests/critical/chats/test_1_1_public_chats.py @@ -1285,8 +1285,7 @@ class TestOneToOneChatMultipleSharedDevicesNewUi(MultipleSharedDeviceTestCase): self.home_2.just_fyi('Device2 checks "Sending" status when sending message from offline') self.chat_2.send_message(message_1) - chat_element = self.chat_2.chat_element_by_text(message_1) - status = chat_element.status + status = self.chat_2.chat_element_by_text(message_1).status if not (status == 'Sending' or status == 'Sent'): self.errors.append('Message status is not "Sending", it is "%s"!' % status) @@ -1304,7 +1303,7 @@ class TestOneToOneChatMultipleSharedDevicesNewUi(MultipleSharedDeviceTestCase): self.home_2.just_fyi('Device1 goes back online and checks that 1-1 chat will be fetched') try: - chat_element.wait_for_status_to_be(expected_status='Delivered', timeout=120) + self.chat_2.chat_element_by_text(message_1).wait_for_status_to_be(expected_status='Delivered', timeout=120) except TimeoutException as e: self.errors.append('%s after back up online!' % e.msg) self.errors.verify_no_errors() diff --git a/test/appium/tests/critical/test_public_chat_browsing.py b/test/appium/tests/critical/test_public_chat_browsing.py index d7c781a30a..45cd61c9b5 100644 --- a/test/appium/tests/critical/test_public_chat_browsing.py +++ b/test/appium/tests/critical/test_public_chat_browsing.py @@ -399,6 +399,7 @@ class TestCommunityOneDeviceMerged(MultipleSharedDeviceTestCase): if not pytest_config_global['pr_number']: self.home.just_fyi("Perform back up") + self.home.click_system_back_button_until_element_is_shown() self.home.profile_button.click() profile.sync_settings_button.click() profile.backup_settings_button.click()