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
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.base_element import Button, Text, BaseElement, SilentButton
|
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
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ChatButton(Button):
|
|
|
|
def __init__(self, driver, **kwargs):
|
|
|
|
super().__init__(driver, **kwargs)
|
2019-04-05 13:05:23 +00:00
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
def navigate(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.chat_view import ChatView
|
|
|
|
return ChatView(self.driver)
|
2019-11-20 16:27:29 +00:00
|
|
|
|
2020-04-06 16:21:23 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ChatElement(SilentButton):
|
2018-05-16 19:59:36 +00:00
|
|
|
def __init__(self, driver, username_part):
|
2018-06-28 18:46:51 +00:00
|
|
|
self.username = username_part
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, xpath="//*[@content-desc='chat-name-text'][starts-with(@text,'%s')]/.." % username_part)
|
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):
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.chat_view import ChatView
|
|
|
|
desired_element = ChatView(self.driver).chat_message_input
|
2018-05-25 17:29:07 +00:00
|
|
|
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-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-07-19 09:57:45 +00:00
|
|
|
@property
|
|
|
|
def new_messages_counter(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
class UnreadMessagesCountText(Text):
|
2018-07-19 09:57:45 +00:00
|
|
|
def __init__(self, driver, parent_locator: str):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, xpath="(%s//android.widget.TextView)[last()]" % parent_locator)
|
2019-11-07 13:38:14 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
return UnreadMessagesCountText(self.driver, self.locator)
|
2018-07-19 09:57:45 +00:00
|
|
|
|
2020-03-03 12:06:55 +00:00
|
|
|
@property
|
|
|
|
def new_messages_public_chat(self):
|
|
|
|
class UnreadMessagesPublicChat(BaseElement):
|
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, 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
|
|
|
|
|
|
|
class HomeView(BaseView):
|
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver)
|
2018-01-14 17:43:36 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.plus_button = Button(self.driver, accessibility_id="new-chat-button")
|
|
|
|
self.chat_name_text = Text(self.driver, accessibility_id="chat-name-text")
|
|
|
|
self.start_new_chat_button = ChatButton(self.driver, accessibility_id="start-1-1-chat-button")
|
|
|
|
self.new_group_chat_button = ChatButton(self.driver, accessibility_id="start-group-chat-button")
|
|
|
|
self.join_public_chat_button = ChatButton(self.driver, accessibility_id="join-public-chat-button")
|
|
|
|
self.universal_qr_scanner_button = Button(self.driver, accessibility_id="universal-qr-scanner")
|
|
|
|
self.invite_friends_button = Button(self.driver, accessibility_id="invite-friends-button")
|
|
|
|
self.stop_status_service_button = Button(self.driver, accessibility_id="STOP")
|
|
|
|
|
|
|
|
# Options on long tap
|
|
|
|
self.chats_menu_invite_friends_button = Button(self.driver, accessibility_id="chats-menu-invite-friends-button")
|
|
|
|
self.delete_chat_button = Button(self.driver, accessibility_id="delete-chat-button")
|
|
|
|
self.clear_history_button = Button(self.driver, accessibility_id="clear-history-button")
|
|
|
|
self.mark_all_messages_as_read_button = Button(self.driver, accessibility_id="mark-all-read-button")
|
2019-04-05 13:05:23 +00:00
|
|
|
|
2018-01-14 17:43:36 +00:00
|
|
|
def wait_for_syncing_complete(self):
|
2021-01-25 16:35:40 +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):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Looking for chat '%s'**" % 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):
|
2021-01-25 16:35:40 +00:00
|
|
|
return Text(self.driver, xpath="//*[@content-desc='enter-contact-code-input']/../..//*[starts-with(@text,'%s')]" % username_part)
|
2020-03-19 16:34:20 +00:00
|
|
|
|
2020-11-02 15:21:33 +00:00
|
|
|
def add_contact(self, public_key, add_in_contacts=True, nickname=''):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Starting 1-1 chat, add in contacts:%s**" % str(add_in_contacts))
|
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()
|
2020-11-02 15:21:33 +00:00
|
|
|
if nickname:
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Setting nickname '%s'**" % nickname)
|
2020-11-02 15:21:33 +00:00
|
|
|
one_to_one_chat.chat_options.click()
|
|
|
|
one_to_one_chat.view_profile_button.click()
|
|
|
|
one_to_one_chat.set_nickname(nickname)
|
|
|
|
one_to_one_chat.back_button.click()
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**1-1 chat is created successfully!**")
|
2018-06-21 16:40:27 +00:00
|
|
|
return one_to_one_chat
|
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'):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Creating group chat '%s'**" % group_chat_name)
|
2019-04-05 13:05:23 +00:00
|
|
|
self.plus_button.click()
|
2021-01-25 16:35:40 +00:00
|
|
|
chat_view = self.new_group_chat_button.click()
|
2020-11-03 16:15:14 +00:00
|
|
|
if user_names_to_add:
|
|
|
|
for user_name in user_names_to_add:
|
|
|
|
if len(user_names_to_add) > 5:
|
2021-01-25 16:35:40 +00:00
|
|
|
chat_view.search_by_keyword(user_name[:4])
|
|
|
|
chat_view.get_username_checkbox(user_name).click()
|
|
|
|
chat_view.search_input.clear()
|
2020-11-03 16:15:14 +00:00
|
|
|
else:
|
2021-01-25 16:35:40 +00:00
|
|
|
chat_view.get_username_checkbox(user_name).click()
|
|
|
|
chat_view.next_button.click()
|
|
|
|
chat_view.chat_name_editbox.send_keys(group_chat_name)
|
|
|
|
chat_view.create_button.click()
|
|
|
|
self.driver.info("**Group chat %s is created successfully!**" % group_chat_name)
|
|
|
|
return chat_view
|
2018-01-26 11:07:09 +00:00
|
|
|
|
2018-02-14 13:48:18 +00:00
|
|
|
def join_public_chat(self, chat_name: str):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Creating group chat %s**" % chat_name)
|
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)
|
2021-01-25 16:35:40 +00:00
|
|
|
chat_view = self.join_public_chat_button.click()
|
|
|
|
chat_view.chat_name_editbox.click()
|
|
|
|
chat_view.chat_name_editbox.send_keys(chat_name)
|
2018-05-23 13:02:45 +00:00
|
|
|
time.sleep(2)
|
2019-04-05 13:05:23 +00:00
|
|
|
self.confirm_until_presence_of_element(chat_view.chat_message_input)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Public chat %s is created successfully!**" % chat_name)
|
2018-08-07 13:23:31 +00:00
|
|
|
return chat_view
|
2018-10-07 15:12:21 +00:00
|
|
|
|
2020-10-14 09:34:53 +00:00
|
|
|
def open_status_test_dapp(self, url=test_dapp_url, allow_all=True):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Open dapp '%s', allow all:%s**" % (test_dapp_url, str(allow_all)))
|
2019-03-19 12:35:15 +00:00
|
|
|
dapp_view = self.dapp_tab_button.click()
|
2020-10-14 09:34:53 +00:00
|
|
|
dapp_view.open_url(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)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Dapp is opened!**")
|
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):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Deleting chat %s by long press**" % 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
|
|
|
|
2020-04-10 10:25:46 +00:00
|
|
|
def leave_chat_long_press(self, username):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Leaving chat %s by long press**" % username)
|
2020-04-10 10:25:46 +00:00
|
|
|
self.get_chat(username).long_press_element()
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.chat_view import ChatView
|
|
|
|
ChatView(self.driver).leave_chat_button.click()
|
|
|
|
ChatView(self.driver).leave_button.click()
|
2020-04-10 10:25:46 +00:00
|
|
|
|
2020-03-17 17:27:10 +00:00
|
|
|
def clear_chat_long_press(self, username):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Clearing history in chat %s by long press**" % username)
|
2020-03-17 17:27:10 +00:00
|
|
|
self.get_chat(username).long_press_element()
|
|
|
|
self.clear_history_button.click()
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.chat_view import ChatView
|
|
|
|
ChatView(self.driver).clear_button.click()
|