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
|
2018-07-18 12:19:52 +00:00
|
|
|
from views.base_element import BaseButton, BaseText, BaseElement
|
2018-01-14 17:43:36 +00:00
|
|
|
from views.base_view import BaseView
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
def navigate(self):
|
2018-02-13 17:22:41 +00:00
|
|
|
from views.start_new_chat_view import StartNewChatView
|
|
|
|
return StartNewChatView(self.driver)
|
2018-01-14 17:43:36 +00:00
|
|
|
|
2018-03-15 20:01:08 +00:00
|
|
|
def click(self):
|
|
|
|
from views.start_new_chat_view import StartNewChatButton
|
|
|
|
desired_element = StartNewChatButton(self.driver)
|
|
|
|
self.click_until_presence_of_element(desired_element=desired_element)
|
|
|
|
return self.navigate()
|
|
|
|
|
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)
|
2018-11-15 10:09:07 +00:00
|
|
|
locator_str = "/../../android.view.ViewGroup/*[@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-03 18:50:18 +00:00
|
|
|
def swipe_and_delete(self):
|
|
|
|
counter = 0
|
|
|
|
while counter < 10:
|
|
|
|
self.swipe_element()
|
|
|
|
if self.swipe_delete_button.is_element_present():
|
|
|
|
break
|
|
|
|
time.sleep(10)
|
|
|
|
counter += 1
|
|
|
|
self.swipe_delete_button.click()
|
|
|
|
|
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)
|
|
|
|
locator_str = "//*[@content-desc='unread-messages-count-text']"
|
|
|
|
self.locator = self.Locator.xpath_selector(parent_locator + locator_str)
|
|
|
|
|
|
|
|
return UnreadMessagesCountText(self.driver, self.locator.value)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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)
|
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
|
|
|
|
|
|
|
|
def get_chat_with_user(self, username):
|
2018-06-30 12:17:38 +00:00
|
|
|
return ChatElement(self.driver, username[:25])
|
2018-01-26 11:07:09 +00:00
|
|
|
|
|
|
|
def add_contact(self, public_key):
|
|
|
|
start_new_chat = self.plus_button.click()
|
2018-09-24 16:22:55 +00:00
|
|
|
start_new_chat.start_new_chat_button.click_until_presence_of_element(start_new_chat.public_key_edit_box)
|
2018-11-30 11:42:48 +00:00
|
|
|
start_new_chat.public_key_edit_box.click()
|
|
|
|
start_new_chat.public_key_edit_box.send_keys(public_key)
|
2018-03-15 20:01:08 +00:00
|
|
|
one_to_one_chat = self.get_chat_view()
|
2018-08-07 13:23:31 +00:00
|
|
|
start_new_chat.confirm_until_presence_of_element(one_to_one_chat.chat_message_input)
|
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):
|
|
|
|
start_new_chat = self.plus_button.click()
|
|
|
|
start_new_chat.start_new_chat_button.click()
|
|
|
|
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'):
|
|
|
|
start_new_chat = self.plus_button.click()
|
|
|
|
start_new_chat.new_group_chat_button.click()
|
|
|
|
for user_name in user_names_to_add:
|
2018-02-19 18:39:54 +00:00
|
|
|
user_contact = start_new_chat.get_username_checkbox(user_name)
|
2018-01-26 11:07:09 +00:00
|
|
|
user_contact.scroll_to_element()
|
|
|
|
user_contact.click()
|
|
|
|
start_new_chat.next_button.click()
|
2018-02-19 18:39:54 +00:00
|
|
|
start_new_chat.chat_name_editbox.send_keys(group_chat_name)
|
2018-07-19 09:57:45 +00:00
|
|
|
start_new_chat.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):
|
|
|
|
start_new_chat = self.plus_button.click()
|
|
|
|
start_new_chat.join_public_chat_button.click()
|
2018-11-30 11:42:48 +00:00
|
|
|
start_new_chat.chat_name_editbox.click()
|
|
|
|
start_new_chat.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()
|
|
|
|
start_new_chat.confirm_until_presence_of_element(chat_view.chat_message_input)
|
|
|
|
return chat_view
|
2018-10-07 15:12:21 +00:00
|
|
|
|
|
|
|
def open_status_test_dapp(self):
|
|
|
|
profile_view = self.profile_button.click()
|
|
|
|
profile_view.advanced_button.click()
|
|
|
|
profile_view.debug_mode_toggle.click()
|
|
|
|
home_view = profile_view.home_button.click()
|
|
|
|
start_new_chat_view = home_view.plus_button.click()
|
|
|
|
start_new_chat_view.open_d_app_button.click()
|
|
|
|
start_new_chat_view.status_test_dapp_button.scroll_to_element()
|
|
|
|
status_test_dapp = start_new_chat_view.status_test_dapp_button.click()
|
|
|
|
start_new_chat_view.open_button.click()
|
|
|
|
return status_test_dapp
|