2018-01-26 11:07:09 +00:00
|
|
|
import time
|
2018-07-03 18:50:18 +00:00
|
|
|
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
2019-03-12 08:29:20 +00:00
|
|
|
from views.base_element import BaseButton, BaseText, BaseElement, BaseEditBox
|
2018-01-14 17:43:36 +00:00
|
|
|
from views.base_view import BaseView
|
2019-10-18 13:23:36 +00:00
|
|
|
from tests import test_dapp_url
|
2018-01-14 17:43:36 +00:00
|
|
|
|
|
|
|
|
2018-07-18 12:19:52 +00:00
|
|
|
class WelcomeImageElement(BaseElement):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(WelcomeImageElement, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector('//android.widget.ImageView')
|
|
|
|
|
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
class PlusButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(PlusButton, self).__init__(driver)
|
2018-03-28 10:21:39 +00:00
|
|
|
self.locator = self.Locator.accessibility_id("new-chat-button")
|
2018-01-14 17:43:36 +00:00
|
|
|
|
2019-05-20 12:16:15 +00:00
|
|
|
class DeleteChatButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(DeleteChatButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id("delete-chat-button")
|
|
|
|
|
2020-03-17 17:27:10 +00:00
|
|
|
class ClearHistoryButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ClearHistoryButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id("clear-history-button")
|
2019-04-05 13:05:23 +00:00
|
|
|
|
|
|
|
class StartNewChatButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(StartNewChatButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('start-1-1-chat-button')
|
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
def navigate(self):
|
2019-04-05 13:05:23 +00:00
|
|
|
from views.contacts_view import ContactsView
|
|
|
|
return ContactsView(self.driver)
|
2018-01-14 17:43:36 +00:00
|
|
|
|
2019-04-05 13:05:23 +00:00
|
|
|
|
|
|
|
class NewGroupChatButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(NewGroupChatButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('start-group-chat-button')
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.contacts_view import ContactsView
|
|
|
|
return ContactsView(self.driver)
|
|
|
|
|
|
|
|
|
|
|
|
class JoinPublicChatButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(JoinPublicChatButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('join-public-chat-button')
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.contacts_view import ContactsView
|
|
|
|
return ContactsView(self.driver)
|
|
|
|
|
|
|
|
|
|
|
|
class InviteFriendsButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(InviteFriendsButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('invite-friends-button')
|
2018-03-15 20:01:08 +00:00
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
|
2019-11-20 16:27:29 +00:00
|
|
|
class ChatsMenuInviteFriendsButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ChatsMenuInviteFriendsButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('chats-menu-invite-friends-button')
|
|
|
|
|
2020-03-19 16:34:20 +00:00
|
|
|
class UserNameBelowNewChatButton(BaseButton):
|
|
|
|
def __init__(self, driver, username_part):
|
|
|
|
super(UserNameBelowNewChatButton, self).__init__(driver)
|
|
|
|
self.username = username_part
|
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
"//*[@content-desc='enter-contact-code-input']/../..//*[starts-with(@text,'%s')]" % self.username)
|
2019-11-20 16:27:29 +00:00
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
class ChatElement(BaseButton):
|
2018-05-16 19:59:36 +00:00
|
|
|
def __init__(self, driver, username_part):
|
2018-01-14 17:43:36 +00:00
|
|
|
super(ChatElement, self).__init__(driver)
|
2018-06-28 18:46:51 +00:00
|
|
|
self.username = username_part
|
2018-07-03 18:50:18 +00:00
|
|
|
self.locator = self.Locator.xpath_selector(
|
2018-11-14 16:15:06 +00:00
|
|
|
"//*[@content-desc='chat-name-text'][starts-with(@text,'%s')]/.." % self.username)
|
2018-01-14 17:43:36 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
2018-07-23 11:38:47 +00:00
|
|
|
from views.chat_view import ChatView
|
|
|
|
return ChatView(self.driver)
|
2018-01-14 17:43:36 +00:00
|
|
|
|
2018-05-25 17:29:07 +00:00
|
|
|
def click(self):
|
|
|
|
from views.chat_view import ChatMessageInput
|
|
|
|
desired_element = ChatMessageInput(self.driver)
|
|
|
|
self.click_until_presence_of_element(desired_element=desired_element)
|
|
|
|
return self.navigate()
|
|
|
|
|
2018-07-03 18:50:18 +00:00
|
|
|
def find_element(self):
|
2018-08-15 12:51:52 +00:00
|
|
|
self.driver.info('Looking for %s' % self.name)
|
2018-07-13 10:56:36 +00:00
|
|
|
for i in range(2):
|
2018-07-03 18:50:18 +00:00
|
|
|
try:
|
|
|
|
return super(ChatElement, self).find_element()
|
2018-07-13 10:56:36 +00:00
|
|
|
except NoSuchElementException as e:
|
|
|
|
if i == 0:
|
|
|
|
HomeView(self.driver).reconnect()
|
|
|
|
else:
|
2018-08-15 12:51:52 +00:00
|
|
|
e.msg = 'Device %s: Unable to find chat with user %s' % (self.driver.number, self.username)
|
2018-07-13 10:56:36 +00:00
|
|
|
raise e
|
2018-07-03 18:50:18 +00:00
|
|
|
|
2018-03-15 16:07:25 +00:00
|
|
|
@property
|
|
|
|
def swipe_delete_button(self):
|
|
|
|
class DeleteButton(BaseButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super(DeleteButton, self).__init__(driver)
|
2019-03-04 12:38:41 +00:00
|
|
|
locator_str = "/../..//*[@content-desc='icon']"
|
2018-03-15 16:07:25 +00:00
|
|
|
self.locator = self.Locator.xpath_selector(parent_locator + locator_str)
|
|
|
|
|
|
|
|
return DeleteButton(self.driver, self.locator.value)
|
|
|
|
|
2018-07-19 09:57:45 +00:00
|
|
|
@property
|
|
|
|
def new_messages_counter(self):
|
|
|
|
class UnreadMessagesCountText(BaseText):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super(UnreadMessagesCountText, self).__init__(driver)
|
2019-11-07 13:38:14 +00:00
|
|
|
# TODO: commented until accessibility-id will be added back
|
|
|
|
# locator_str = "//*[@content-desc='unread-messages-count-text']"
|
|
|
|
# self.locator = self.Locator.xpath_selector(parent_locator + locator_str)
|
2020-02-05 18:20:24 +00:00
|
|
|
locator_str = "//android.widget.TextView)[last()]"
|
|
|
|
self.locator = self.Locator.xpath_selector("(" + parent_locator + locator_str)
|
2019-11-07 13:38:14 +00:00
|
|
|
|
2018-07-19 09:57:45 +00:00
|
|
|
return UnreadMessagesCountText(self.driver, self.locator.value)
|
|
|
|
|
2020-03-03 12:06:55 +00:00
|
|
|
@property
|
|
|
|
def new_messages_public_chat(self):
|
|
|
|
class UnreadMessagesPublicChat(BaseElement):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(UnreadMessagesPublicChat, self).__init__(driver)
|
2020-04-03 11:01:55 +00:00
|
|
|
self.locator = self.Locator.accessibility_id('unviewed-messages-public')
|
2020-03-03 12:06:55 +00:00
|
|
|
|
|
|
|
return UnreadMessagesPublicChat(self.driver)
|
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
|
2018-03-28 10:21:39 +00:00
|
|
|
class ChatNameText(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ChatNameText, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('chat-name-text')
|
|
|
|
|
|
|
|
|
|
|
|
class ChatUrlText(BaseText):
|
2018-02-13 17:22:41 +00:00
|
|
|
def __init__(self, driver):
|
2018-03-28 10:21:39 +00:00
|
|
|
super(ChatUrlText, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('chat-url-text')
|
2018-02-13 17:22:41 +00:00
|
|
|
|
|
|
|
|
2019-03-12 08:29:20 +00:00
|
|
|
class SearchChatInput(BaseEditBox):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super().__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector('//android.widget.EditText')
|
|
|
|
|
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
class HomeView(BaseView):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(HomeView, self).__init__(driver)
|
2018-07-18 12:19:52 +00:00
|
|
|
self.welcome_image = WelcomeImageElement(self.driver)
|
2018-01-14 17:43:36 +00:00
|
|
|
self.plus_button = PlusButton(self.driver)
|
2018-03-28 10:21:39 +00:00
|
|
|
self.chat_name_text = ChatNameText(self.driver)
|
|
|
|
self.chat_url_text = ChatUrlText(self.driver)
|
2019-03-12 08:29:20 +00:00
|
|
|
self.search_chat_input = SearchChatInput(self.driver)
|
2018-01-14 17:43:36 +00:00
|
|
|
|
2019-04-05 13:05:23 +00:00
|
|
|
self.start_new_chat_button = StartNewChatButton(self.driver)
|
|
|
|
self.new_group_chat_button = NewGroupChatButton(self.driver)
|
|
|
|
self.join_public_chat_button = JoinPublicChatButton(self.driver)
|
|
|
|
self.invite_friends_button = InviteFriendsButton(self.driver)
|
2019-11-20 16:27:29 +00:00
|
|
|
self.chats_menu_invite_friends_button = ChatsMenuInviteFriendsButton(self.driver)
|
2019-05-20 12:16:15 +00:00
|
|
|
self.delete_chat_button = DeleteChatButton(self.driver)
|
2020-03-17 17:27:10 +00:00
|
|
|
self.clear_history_button = ClearHistoryButton(self.driver)
|
2019-04-05 13:05:23 +00:00
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
def wait_for_syncing_complete(self):
|
2018-08-15 12:51:52 +00:00
|
|
|
self.driver.info('Waiting for syncing complete:')
|
2018-01-14 17:43:36 +00:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
sync = self.find_text_part('Syncing', 10)
|
2018-08-15 12:51:52 +00:00
|
|
|
self.driver.info(sync.text)
|
2018-01-14 17:43:36 +00:00
|
|
|
except TimeoutException:
|
|
|
|
break
|
|
|
|
|
2020-03-17 17:27:10 +00:00
|
|
|
def get_chat(self, username):
|
2018-06-30 12:17:38 +00:00
|
|
|
return ChatElement(self.driver, username[:25])
|
2018-01-26 11:07:09 +00:00
|
|
|
|
2020-03-19 16:34:20 +00:00
|
|
|
def get_username_below_start_new_chat_button(self, username_part):
|
|
|
|
return UserNameBelowNewChatButton(self.driver, username_part)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-23 17:17:54 +00:00
|
|
|
def add_contact(self, public_key, add_in_contacts=True):
|
2019-07-29 23:32:29 +00:00
|
|
|
self.plus_button.click_until_presence_of_element(self.start_new_chat_button)
|
2019-04-05 13:05:23 +00:00
|
|
|
contacts_view = self.start_new_chat_button.click()
|
|
|
|
contacts_view.public_key_edit_box.click()
|
|
|
|
contacts_view.public_key_edit_box.send_keys(public_key)
|
2018-03-15 20:01:08 +00:00
|
|
|
one_to_one_chat = self.get_chat_view()
|
2019-04-05 13:05:23 +00:00
|
|
|
contacts_view.confirm_until_presence_of_element(one_to_one_chat.chat_message_input)
|
2019-10-23 17:17:54 +00:00
|
|
|
if add_in_contacts:
|
|
|
|
one_to_one_chat.add_to_contacts.click()
|
2018-06-21 16:40:27 +00:00
|
|
|
return one_to_one_chat
|
2018-01-26 11:07:09 +00:00
|
|
|
|
2018-04-26 06:22:11 +00:00
|
|
|
def start_1_1_chat(self, username):
|
2019-04-05 13:05:23 +00:00
|
|
|
self.plus_button.click()
|
|
|
|
self.start_new_chat_button.click()
|
2018-04-26 06:22:11 +00:00
|
|
|
self.element_by_text(username).click()
|
|
|
|
from views.chat_view import ChatView
|
|
|
|
return ChatView(self.driver)
|
|
|
|
|
2018-01-26 11:07:09 +00:00
|
|
|
def create_group_chat(self, user_names_to_add: list, group_chat_name: str = 'new_group_chat'):
|
2019-04-05 13:05:23 +00:00
|
|
|
self.plus_button.click()
|
|
|
|
contacts_view = self.new_group_chat_button.click()
|
2018-01-26 11:07:09 +00:00
|
|
|
for user_name in user_names_to_add:
|
2019-04-05 13:05:23 +00:00
|
|
|
user_contact = contacts_view.get_username_checkbox(user_name)
|
2018-01-26 11:07:09 +00:00
|
|
|
user_contact.scroll_to_element()
|
|
|
|
user_contact.click()
|
2019-04-05 13:05:23 +00:00
|
|
|
contacts_view.next_button.click()
|
|
|
|
contacts_view.chat_name_editbox.send_keys(group_chat_name)
|
|
|
|
contacts_view.create_button.click()
|
2018-12-03 09:57:22 +00:00
|
|
|
from views.chat_view import ChatView
|
|
|
|
return ChatView(self.driver)
|
2018-01-26 11:07:09 +00:00
|
|
|
|
2018-02-14 13:48:18 +00:00
|
|
|
def join_public_chat(self, chat_name: str):
|
2019-07-23 23:10:55 +00:00
|
|
|
self.plus_button.click_until_presence_of_element(self.join_public_chat_button, attempts=5)
|
2019-07-01 18:10:11 +00:00
|
|
|
self.join_public_chat_button.wait_for_visibility_of_element(5)
|
2019-04-05 13:05:23 +00:00
|
|
|
contacts_view = self.join_public_chat_button.click()
|
|
|
|
contacts_view.chat_name_editbox.click()
|
|
|
|
contacts_view.chat_name_editbox.send_keys(chat_name)
|
2018-05-23 13:02:45 +00:00
|
|
|
time.sleep(2)
|
2018-08-07 13:23:31 +00:00
|
|
|
chat_view = self.get_chat_view()
|
2019-04-05 13:05:23 +00:00
|
|
|
self.confirm_until_presence_of_element(chat_view.chat_message_input)
|
2018-08-07 13:23:31 +00:00
|
|
|
return chat_view
|
2018-10-07 15:12:21 +00:00
|
|
|
|
2019-01-09 14:54:58 +00:00
|
|
|
def open_status_test_dapp(self, allow_all=True):
|
2019-03-19 12:35:15 +00:00
|
|
|
dapp_view = self.dapp_tab_button.click()
|
2019-10-18 13:23:36 +00:00
|
|
|
dapp_view.open_url(test_dapp_url)
|
2019-03-19 12:35:15 +00:00
|
|
|
status_test_dapp = dapp_view.get_status_test_dapp_view()
|
2019-12-06 09:49:01 +00:00
|
|
|
status_test_dapp.allow_button.wait_for_element(20)
|
2019-11-21 10:26:53 +00:00
|
|
|
if allow_all:
|
|
|
|
status_test_dapp.allow_button.click_until_absense_of_element(status_test_dapp.allow_button)
|
|
|
|
else:
|
|
|
|
status_test_dapp.deny_button.click_until_absense_of_element(status_test_dapp.deny_button)
|
2018-10-07 15:12:21 +00:00
|
|
|
return status_test_dapp
|
2019-05-20 12:16:15 +00:00
|
|
|
|
|
|
|
def delete_chat_long_press(self, username):
|
2020-03-17 17:27:10 +00:00
|
|
|
self.get_chat(username).long_press_element()
|
2019-05-20 12:16:15 +00:00
|
|
|
self.delete_chat_button.click()
|
|
|
|
self.delete_button.click()
|
2020-03-17 17:27:10 +00:00
|
|
|
|
|
|
|
def clear_chat_long_press(self, username):
|
|
|
|
self.get_chat(username).long_press_element()
|
|
|
|
self.clear_history_button.click()
|
|
|
|
from views.chat_view import ClearButton
|
|
|
|
self.clear_button = ClearButton(self.driver)
|
|
|
|
self.clear_button.click()
|