From 05a810b051605bd15cc92c502e955a896f98d26f Mon Sep 17 00:00:00 2001 From: Yevheniia Berdnyk Date: Fri, 23 Feb 2024 18:13:57 +0200 Subject: [PATCH] e2e: updated method for a profile picture changing --- .../activity_center/test_activity_center.py | 1 + .../critical/chats/test_1_1_public_chats.py | 2 -- test/appium/views/base_view.py | 20 +++++++++++++++---- test/appium/views/profile_view.py | 17 ++++++++++------ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/test/appium/tests/activity_center/test_activity_center.py b/test/appium/tests/activity_center/test_activity_center.py index 9b0a604468..99c95bd565 100644 --- a/test/appium/tests/activity_center/test_activity_center.py +++ b/test/appium/tests/activity_center/test_activity_center.py @@ -59,6 +59,7 @@ class TestActivityCenterContactRequestMultipleDevicePR(MultipleSharedDeviceTestC self.errors.append("Push notification with text was received for new message in activity centre") self.device_1.click_system_back_button() self.device_1.driver.activate_app(app_package) + self.device_1.wait_for_application_to_be_running(app_package) self.device_1.just_fyi('Device1 verifies pending contact request') self.home_1.contacts_tab.click() 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 26e6f082bd..4fc4367170 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 @@ -271,8 +271,6 @@ class TestOneToOneChatMultipleSharedDevicesNewUi(MultipleSharedDeviceTestCase): self.home_1.jump_to_messages_home() self.home_1.profile_button.click() self.profile_1.edit_profile_picture(image_index=2) - self.profile_1.navigate_back_to_home_view() - self.profile_1.chats_tab.click() self.chat_2.just_fyi("Send messages with non-latin symbols") self.home_1.jump_to_card_by_text(self.username_2) diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index 78a174d6cb..dbf1615cfb 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -6,6 +6,7 @@ import time from datetime import datetime from appium.webdriver import WebElement +from appium.webdriver.applicationstate import ApplicationState from appium.webdriver.common.touch_action import TouchAction from selenium.common.exceptions import NoSuchElementException, TimeoutException from selenium.webdriver.support import expected_conditions @@ -658,13 +659,24 @@ class BaseView(object): self.click_on_floating_jump_to() self.element_by_text(text).click() + def wait_for_application_to_be_running(self, app_package: str, wait_time: int = 3): + for _ in range(wait_time): + if self.driver.query_app_state(app_package) == ApplicationState.RUNNING_IN_FOREGROUND: + return + time.sleep(1) + raise TimeoutException(msg="Status app is not running in foreground after %s sec" % wait_time) + + def wait_for_application_to_not_run(self, app_package: str, wait_time: int = 3): + for _ in range(wait_time): + if self.driver.query_app_state(app_package) == ApplicationState.NOT_RUNNING: + return + time.sleep(1) + raise TimeoutException(msg="Status app is not terminated after %s sec" % wait_time) + def reopen_app(self, password=common_password, sign_in=True): app_package = self.driver.current_package self.driver.terminate_app(app_package) - for _ in range(3): - if self.driver.query_app_state(app_package) == 1: - break - time.sleep(1) + self.wait_for_application_to_not_run(app_package=app_package) self.driver.activate_app(app_package) if sign_in: sign_in_view = self.get_sign_in_view() diff --git a/test/appium/views/profile_view.py b/test/appium/views/profile_view.py index bc17c85d02..c7d4e76cce 100644 --- a/test/appium/views/profile_view.py +++ b/test/appium/views/profile_view.py @@ -199,9 +199,9 @@ class ProfileView(BaseView): self.online_indicator = Button(self.driver, accessibility_id="online-profile-photo-dot") self.edit_picture_button = Button(self.driver, accessibility_id="edit-profile-photo-button") self.confirm_edit_button = Button(self.driver, accessibility_id="done-button") - self.select_from_gallery_button = Button(self.driver, translation_id="profile-pic-pick") + self.select_from_gallery_button_old = Button(self.driver, translation_id="profile-pic-pick") self.capture_button = Button(self.driver, translation_id="image-source-make-photo") - self.take_photo_button = Button(self.driver, accessibility_id="take-photo") + self.take_photo_button_old = Button(self.driver, accessibility_id="take-photo") self.crop_photo_button = Button(self.driver, accessibility_id="Crop") self.decline_photo_crop = Button(self.driver, accessibility_id="Navigate up") self.shutter_button = Button(self.driver, accessibility_id="Shutter") @@ -354,6 +354,12 @@ class ProfileView(BaseView): self.confirm_logout_button = Button(self.driver, translation_id="logout", uppercase=True) # New profile + self.edit_profile_button = Button(self.driver, accessibility_id="icon, Edit Profile, label-component, icon") + self.change_profile_photo_button = Button( + self.driver, + xpath="//*[@content-desc='user-avatar']/following-sibling::android.view.ViewGroup[@content-desc='icon']") + self.take_photo_button = Button(self.driver, accessibility_id="take-photo-button") + self.select_from_gallery_button = Button(self.driver, accessibility_id="select-from-gallery-button") self.profile_password_button = Button(self.driver, accessibility_id="icon, Password, label-component, icon") self.profile_legacy_button = Button(self.driver, accessibility_id="icon, Legacy settings, label-component, icon") @@ -438,10 +444,8 @@ class ProfileView(BaseView): self.driver.info("## Setting custom profile image", device=False) if not AbstractTestCase().environment == 'sauce': raise NotImplementedError('Test case is implemented to run on SauceLabs only') - ## pointing to legacy profile until new feature is implemented - self.logout_button.scroll_to_element() - self.profile_legacy_button.click() - self.profile_picture.click() + self.edit_profile_button.click() + self.change_profile_photo_button.click() if update_by == "Gallery": self.select_from_gallery_button.click() self.select_photo_from_gallery_by_index(image_index) @@ -454,6 +458,7 @@ class ProfileView(BaseView): self.accept_photo_button.click() self.crop_photo_button.click() self.driver.info("## Custom profile image has been set", device=False) + self.click_system_back_button() def take_photo(self): self.take_photo_button.click()