2018-07-11 16:14:39 +02:00
|
|
|
from selenium.common.exceptions import NoSuchElementException
|
|
|
|
|
2018-06-01 18:37:44 +02:00
|
|
|
from tests import get_current_time, common_password
|
2018-01-14 19:43:36 +02:00
|
|
|
from views.base_element import BaseButton, BaseEditBox
|
2018-01-03 11:34:40 +02:00
|
|
|
from views.base_view import BaseView
|
2018-03-31 23:05:11 +03:00
|
|
|
|
2018-06-21 18:40:27 +02:00
|
|
|
|
2018-05-02 19:01:17 +03:00
|
|
|
class AccountButton(BaseButton):
|
2017-09-21 20:01:04 +03:00
|
|
|
|
|
|
|
def __init__(self, driver):
|
2018-05-02 19:01:17 +03:00
|
|
|
super(AccountButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[contains(@text,'0x')]")
|
2017-09-21 20:01:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
class PasswordInput(BaseEditBox):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(PasswordInput, self).__init__(driver)
|
2018-03-01 15:22:01 +02:00
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='Password']"
|
|
|
|
"/following-sibling::android.view.ViewGroup/android.widget.EditText")
|
2017-09-21 20:01:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
class SignInButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SignInButton, self).__init__(driver)
|
2018-03-01 15:22:01 +02:00
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='Sign in' or @text='SIGN IN']")
|
2017-09-21 20:01:04 +03:00
|
|
|
|
2018-01-14 19:43:36 +02:00
|
|
|
def navigate(self):
|
|
|
|
from views.home_view import HomeView
|
|
|
|
return HomeView(self.driver)
|
|
|
|
|
2017-09-21 20:01:04 +03:00
|
|
|
|
2017-09-26 13:50:34 +03:00
|
|
|
class RecoverAccessButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(RecoverAccessButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='Recover access']")
|
|
|
|
|
2018-01-03 11:34:40 +02:00
|
|
|
def navigate(self):
|
|
|
|
from views.recover_access_view import RecoverAccessView
|
|
|
|
return RecoverAccessView(self.driver)
|
2017-09-26 13:50:34 +03:00
|
|
|
|
|
|
|
|
2018-03-01 15:22:01 +02:00
|
|
|
class CreateAccountButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(CreateAccountButton, self).__init__(driver)
|
2018-05-02 19:01:17 +03:00
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
"//android.widget.TextView[@text='CREATE ACCOUNT' or @text='CREATE NEW ACCOUNT']")
|
2018-03-01 15:22:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class IHaveAccountButton(RecoverAccessButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(IHaveAccountButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='I ALREADY HAVE AN ACCOUNT']")
|
|
|
|
|
|
|
|
|
|
|
|
class AddExistingAccountButton(RecoverAccessButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(AddExistingAccountButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='ADD EXISTING ACCOUNT']")
|
|
|
|
|
|
|
|
|
|
|
|
class ConfirmPasswordInput(BaseEditBox):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ConfirmPasswordInput, self).__init__(driver)
|
2018-11-30 13:42:48 +02:00
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='Confirm']"
|
|
|
|
"/following-sibling::android.view.ViewGroup/android.widget.EditText")
|
2018-03-01 15:22:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class NameInput(BaseEditBox):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(NameInput, self).__init__(driver)
|
2018-05-02 19:01:17 +03:00
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.EditText")
|
2018-03-01 15:22:01 +02:00
|
|
|
|
|
|
|
|
2018-07-17 18:27:00 +02:00
|
|
|
class OtherAccountsButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(OtherAccountsButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.text_selector('OTHER ACCOUNTS')
|
|
|
|
|
|
|
|
|
2018-09-05 22:50:48 +03:00
|
|
|
class PrivacyPolicyLink(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(PrivacyPolicyLink, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.text_part_selector('Privacy Policy')
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.web_views.base_web_view import BaseWebView
|
|
|
|
return BaseWebView(self.driver)
|
|
|
|
|
|
|
|
|
2018-01-03 11:34:40 +02:00
|
|
|
class SignInView(BaseView):
|
2017-09-21 20:01:04 +03:00
|
|
|
|
2018-08-10 13:09:19 +03:00
|
|
|
def __init__(self, driver, skip_popups=True):
|
2018-01-03 11:34:40 +02:00
|
|
|
super(SignInView, self).__init__(driver)
|
2017-09-21 20:01:04 +03:00
|
|
|
self.driver = driver
|
2018-08-10 13:09:19 +03:00
|
|
|
if skip_popups:
|
|
|
|
self.accept_agreements()
|
2017-09-21 20:01:04 +03:00
|
|
|
|
2018-05-02 19:01:17 +03:00
|
|
|
self.account_button = AccountButton(self.driver)
|
2017-09-21 20:01:04 +03:00
|
|
|
self.password_input = PasswordInput(self.driver)
|
|
|
|
self.sign_in_button = SignInButton(self.driver)
|
2017-09-26 13:50:34 +03:00
|
|
|
self.recover_access_button = RecoverAccessButton(self.driver)
|
2018-03-01 15:22:01 +02:00
|
|
|
|
|
|
|
# new design
|
|
|
|
self.create_account_button = CreateAccountButton(self.driver)
|
|
|
|
self.i_have_account_button = IHaveAccountButton(self.driver)
|
|
|
|
self.add_existing_account_button = AddExistingAccountButton(self.driver)
|
|
|
|
self.confirm_password_input = ConfirmPasswordInput(self.driver)
|
|
|
|
self.name_input = NameInput(self.driver)
|
2018-07-17 18:27:00 +02:00
|
|
|
self.other_accounts_button = OtherAccountsButton(self.driver)
|
2018-09-05 22:50:48 +03:00
|
|
|
self.privacy_policy_link = PrivacyPolicyLink(self.driver)
|
2018-03-01 15:22:01 +02:00
|
|
|
|
2018-06-01 18:37:44 +02:00
|
|
|
def create_user(self, username: str = '', password=common_password):
|
2018-03-01 15:22:01 +02:00
|
|
|
self.create_account_button.click()
|
2018-04-30 12:58:20 +03:00
|
|
|
self.password_input.set_value(password)
|
2018-03-01 15:22:01 +02:00
|
|
|
self.next_button.click()
|
2018-04-30 12:58:20 +03:00
|
|
|
self.confirm_password_input.set_value(password)
|
2018-03-01 15:22:01 +02:00
|
|
|
self.next_button.click()
|
2018-05-16 21:59:36 +02:00
|
|
|
|
2018-09-24 19:22:55 +03:00
|
|
|
self.element_by_text_part('Display name').wait_for_element(60)
|
2018-03-31 23:05:11 +03:00
|
|
|
username = username if username else 'user_%s' % get_current_time()
|
2018-07-11 16:14:39 +02:00
|
|
|
self.name_input.set_value(username)
|
2018-05-16 21:59:36 +02:00
|
|
|
|
2018-03-01 15:22:01 +02:00
|
|
|
self.next_button.click()
|
2018-06-28 20:46:51 +02:00
|
|
|
return self.get_home_view()
|
2018-03-01 15:22:01 +02:00
|
|
|
|
2018-09-17 11:50:01 +03:00
|
|
|
def recover_access(self, passphrase: str, password: str = common_password):
|
2018-10-07 18:12:21 +03:00
|
|
|
if self.other_accounts_button.is_element_displayed():
|
|
|
|
self.other_accounts_button.click()
|
|
|
|
recover_access_view = self.add_existing_account_button.click()
|
|
|
|
else:
|
|
|
|
recover_access_view = self.i_have_account_button.click()
|
2018-04-26 18:05:53 +03:00
|
|
|
recover_access_view.passphrase_input.click()
|
|
|
|
recover_access_view.send_as_keyevent(passphrase)
|
2018-03-01 15:22:01 +02:00
|
|
|
recover_access_view.password_input.click()
|
2018-04-26 18:05:53 +03:00
|
|
|
recover_access_view.send_as_keyevent(password)
|
2018-10-18 11:23:54 +03:00
|
|
|
recover_access_view.sign_in_button.click_until_presence_of_element(recover_access_view.home_button)
|
2018-06-28 20:46:51 +02:00
|
|
|
return self.get_home_view()
|
2018-05-02 19:01:17 +03:00
|
|
|
|
2018-06-01 18:37:44 +02:00
|
|
|
def sign_in(self, password=common_password):
|
2018-07-17 18:27:00 +02:00
|
|
|
if self.ok_button.is_element_displayed():
|
|
|
|
self.ok_button.click()
|
2018-04-26 08:22:11 +02:00
|
|
|
self.password_input.set_value(password)
|
2018-06-21 18:40:27 +02:00
|
|
|
return self.sign_in_button.click()
|
2018-04-26 08:22:11 +02:00
|
|
|
|
2018-05-02 19:01:17 +03:00
|
|
|
def click_account_by_position(self, position: int):
|
2018-07-16 14:57:01 +02:00
|
|
|
if self.ok_button.is_element_displayed():
|
|
|
|
self.ok_button.click()
|
2018-07-11 16:14:39 +02:00
|
|
|
try:
|
|
|
|
self.account_button.find_elements()[position].click()
|
|
|
|
except IndexError:
|
2018-08-15 15:51:52 +03:00
|
|
|
raise NoSuchElementException(
|
|
|
|
'Device %s: Unable to find account by position %s' % (self.driver.number, position)) from None
|