status-react/test/appium/views/sign_in_view.py

179 lines
8.6 KiB
Python
Raw Normal View History

2023-07-24 18:25:36 +03:00
from selenium.common.exceptions import NoSuchElementException
2024-12-30 21:10:54 +01:00
from tests import common_password
from views.base_element import Button, EditBox, Text
from views.base_view import BaseView
2023-07-24 18:25:36 +03:00
2021-11-18 16:16:48 +01:00
class MultiAccountButton(Button):
class Username(Text):
def __init__(self, driver, locator_value):
2024-06-07 21:21:29 +03:00
super(MultiAccountButton.Username, self).__init__(
driver,
xpath="%s//android.widget.TextView[@content-desc='username']" % locator_value)
2021-11-18 16:16:48 +01:00
def __init__(self, driver, position=1):
super(MultiAccountButton, self).__init__(driver,
xpath="//*[@content-desc='select-account-button-%s']" % position)
self.username = self.Username(driver, self.locator)
2017-09-21 20:01:04 +03:00
class MultiAccountOnLoginButton(Button):
def __init__(self, driver, position=1):
super(MultiAccountOnLoginButton, self).__init__(driver,
xpath="(//*[@content-desc='chat-icon'])[%s]/.." % position)
@property
def account_logo(self):
class AccountLogo(Text):
def __init__(self, driver, parent_locator: str):
super().__init__(driver, xpath="%s//*[@content-desc='chat-icon']" % parent_locator)
return AccountLogo(self.driver, self.locator)
class LogInButton(Button):
2017-09-21 20:01:04 +03:00
def __init__(self, driver):
super().__init__(driver, accessibility_id="login-button")
2017-09-21 20:01:04 +03:00
def navigate(self):
from views.home_view import HomeView
return HomeView(self.driver)
2023-05-04 16:26:59 +02:00
class UserProfileElement(Button):
2024-06-07 21:21:29 +03:00
def __init__(self, driver, username: str = None, index: int = None):
2023-05-04 16:26:59 +02:00
self.username = username
2024-06-07 21:21:29 +03:00
self.index = index
if username:
super().__init__(
driver,
xpath="//*[@text='%s']//ancestor::android.view.ViewGroup[@content-desc='profile-card']" % self.username)
elif index:
super().__init__(driver, xpath="(//*[@content-desc='profile-card'])[%s]" % self.index)
else:
raise AttributeError("Either username or profile index should be defined")
2023-05-04 16:26:59 +02:00
def open_user_options(self):
Button(self.driver, xpath='%s//*[@content-desc="profile-card-options"]' % self.locator).click()
class SignInView(BaseView):
2017-09-21 20:01:04 +03:00
def __init__(self, driver):
super().__init__(driver)
2017-09-21 20:01:04 +03:00
self.driver = driver
# intro screen
self.i_m_new_in_status_button = Button(self.driver, accessibility_id="new-to-status-button")
self.explore_new_status_button = Button(self.driver, accessibility_id="explore-new-status")
self.create_profile_button = Button(self.driver, accessibility_id='new-to-status-button')
2024-11-13 16:35:59 +02:00
self.log_in_button = Button(self.driver, accessibility_id='log-in')
2024-11-26 20:37:44 +02:00
self.maybe_later_button = Button(self.driver, accessibility_id="maybe-later-button")
2024-11-27 15:47:12 +02:00
self.log_in_by_syncing_button = Button(self.driver, accessibility_id="log-in-by-syncing-icon-card")
2024-10-03 16:34:43 +03:00
self.enter_sync_code_button = Button(self.driver, accessibility_id="Enter sync code")
self.enter_sync_code_input = EditBox(self.driver, accessibility_id="enter-sync-code-input")
self.progress_screen_title = Text(self.driver, accessibility_id="progress-screen-title")
self.try_seed_phrase_button = Button(self.driver, accessibility_id="try-seed-phrase-button")
# migrate multiaccount
self.options_button = Button(self.driver, xpath="//androidx.appcompat.widget.LinearLayoutCompat")
self.manage_keys_and_storage_button = Button(self.driver, accessibility_id="manage-keys-and-storage-button")
2023-03-30 15:14:27 +02:00
# New onboarding
2024-11-22 18:35:46 +02:00
self.start_fresh_lets_go_button = Button(self.driver, accessibility_id="start-fresh-main-card")
self.profile_title_input = EditBox(self.driver, accessibility_id="profile-title-input")
self.profile_confirm_password_button = Button(self.driver, accessibility_id="Confirm password")
2024-11-22 18:35:46 +02:00
self.use_recovery_phrase_button = Button(self.driver, accessibility_id="use-a-recovery-phrase-icon-card")
2023-05-04 16:26:59 +02:00
self.passphrase_edit_box = EditBox(self.driver, accessibility_id="passphrase-input")
2023-07-24 18:25:36 +03:00
self.show_profiles_button = Button(self.driver, accessibility_id="show-profiles")
self.plus_profiles_button = Button(self.driver, accessibility_id="show-new-account-options")
self.create_new_profile_button = Button(self.driver, accessibility_id="create-new-profile")
2024-10-03 16:34:43 +03:00
self.sync_or_recover_new_profile_button = Button(self.driver, accessibility_id="multi-profile")
2023-05-04 16:26:59 +02:00
self.remove_profile_button = Button(self.driver, accessibility_id="remove-profile")
2023-03-30 15:14:27 +02:00
def set_password(self, password: str):
2024-04-05 18:46:23 +03:00
input_elements = self.password_input.wait_for_elements()
input_elements[0].send_keys(password)
input_elements[1].click()
input_elements[1].send_keys(password)
2023-03-30 15:14:27 +02:00
self.profile_confirm_password_button.click()
def create_user(self, password=common_password, first_user=True, enable_notifications=False):
self.driver.info("## Creating new multiaccount with password:'%s'" % password, device=False)
2023-11-06 14:12:04 +02:00
if first_user:
2024-11-22 18:35:46 +02:00
self.create_profile_button.click_until_presence_of_element(self.start_fresh_lets_go_button)
2024-11-26 20:37:44 +02:00
self.maybe_later_button.wait_and_click()
2023-11-03 15:34:33 +02:00
else:
2023-11-06 14:12:04 +02:00
if self.show_profiles_button.is_element_displayed(20):
self.show_profiles_button.click()
self.plus_profiles_button.click()
self.create_new_profile_button.click()
2024-11-22 18:35:46 +02:00
self.start_fresh_lets_go_button.click_until_presence_of_element(self.profile_title_input)
2023-03-30 15:14:27 +02:00
self.set_password(password)
self.chats_tab.wait_for_visibility_of_element(30)
self.driver.info("## New multiaccount is created successfully!", device=False)
home_view = self.get_home_view()
if enable_notifications:
profile_view = home_view.profile_button.click()
profile_view.switch_push_notifications()
profile_view.click_system_back_button(times=2)
return home_view
2018-03-01 15:22:01 +02:00
def recover_access(self, passphrase: str, password: str = common_password, enable_notifications=False,
second_user=False, after_sync_code=False):
self.driver.info("## Recover access (password:%s)" % password, device=False)
2023-03-30 15:14:27 +02:00
2024-10-03 16:34:43 +03:00
if not after_sync_code:
if not second_user:
2024-11-22 18:35:46 +02:00
self.create_profile_button.click_until_presence_of_element(self.start_fresh_lets_go_button)
2024-11-26 20:37:44 +02:00
self.maybe_later_button.wait_and_click()
2024-10-03 16:34:43 +03:00
else:
self.plus_profiles_button.click()
self.create_new_profile_button.click()
self.use_recovery_phrase_button.click()
2023-09-06 06:07:12 +03:00
self.passphrase_edit_box.send_keys(passphrase)
self.continue_button.click_until_presence_of_element(self.profile_title_input)
2023-03-30 15:14:27 +02:00
self.set_password(password)
self.chats_tab.wait_for_visibility_of_element(30)
self.driver.info("## Multiaccount is recovered successfully!", device=False)
home_view = self.get_home_view()
if enable_notifications:
profile_view = home_view.profile_button.click()
profile_view.switch_push_notifications()
return home_view
2024-10-03 16:34:43 +03:00
def sync_profile(self, sync_code: str, first_user: bool = True):
if first_user:
2024-11-13 16:35:59 +02:00
self.log_in_button.click()
2024-11-27 15:47:12 +02:00
self.maybe_later_button.click()
2024-10-03 16:34:43 +03:00
else:
self.plus_profiles_button.click()
self.sync_or_recover_new_profile_button.click()
2024-11-27 15:47:12 +02:00
self.log_in_by_syncing_button.click()
2024-10-03 16:34:43 +03:00
for checkbox in self.checkbox_button.find_elements():
checkbox.click()
self.continue_button.click()
self.enter_sync_code_button.click()
self.enter_sync_code_input.send_keys(sync_code)
self.confirm_button.click()
def sign_in(self, user_name, password=common_password):
2023-12-26 13:52:10 +02:00
self.driver.info("## Sign in (password: %s)" % password, device=False)
self.get_user_profile_by_name(user_name).click()
2023-12-26 13:52:10 +02:00
self.password_input.wait_for_visibility_of_element(10)
self.password_input.send_keys(password)
self.login_button.click()
self.driver.info("## Signed in successfully!", device=False)
return self.get_home_view()
2024-06-07 21:21:29 +03:00
def get_user_profile_by_name(self, username: str):
2023-05-04 16:26:59 +02:00
self.driver.info("Getting username card by '%s'" % username)
2024-06-07 21:21:29 +03:00
expected_element = UserProfileElement(self.driver, username=username)
2024-12-10 19:26:53 +02:00
if expected_element.is_element_displayed(10):
return expected_element
else:
raise NoSuchElementException(msg="User %s is not found!" % username)
2024-06-07 21:21:29 +03:00