2018-01-26 11:07:09 +00:00
|
|
|
from tests import info
|
|
|
|
import time
|
2018-02-09 15:16:07 +00:00
|
|
|
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
2018-02-13 17:22:41 +00:00
|
|
|
from views.base_element import BaseButton, BaseText
|
2018-01-14 17:43:36 +00:00
|
|
|
from views.base_view import BaseView
|
|
|
|
|
|
|
|
|
|
|
|
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 ConsoleButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ConsoleButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
"//*[@text='Console']")
|
|
|
|
|
|
|
|
|
|
|
|
class ChatElement(BaseButton):
|
|
|
|
def __init__(self, driver, username):
|
|
|
|
super(ChatElement, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='%s']" % username)
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.chat_view import ChatView
|
|
|
|
return ChatView(self.driver)
|
|
|
|
|
2018-03-15 16:07:25 +00:00
|
|
|
@property
|
|
|
|
def swipe_delete_button(self):
|
2018-03-28 10:21:39 +00:00
|
|
|
|
2018-03-15 16:07:25 +00:00
|
|
|
class DeleteButton(BaseButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super(DeleteButton, self).__init__(driver)
|
|
|
|
locator_str = "/../../following-sibling::*[1][name()='android.view.ViewGroup']/*[@content-desc='icon']"
|
|
|
|
self.locator = self.Locator.xpath_selector(parent_locator + locator_str)
|
|
|
|
|
|
|
|
return DeleteButton(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)
|
|
|
|
|
|
|
|
self.plus_button = PlusButton(self.driver)
|
|
|
|
self.console_button = ConsoleButton(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-01-26 11:07:09 +00:00
|
|
|
info('Waiting for syncing complete:')
|
2018-01-14 17:43:36 +00:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
sync = self.find_text_part('Syncing', 10)
|
2018-01-26 11:07:09 +00:00
|
|
|
info(sync.text)
|
2018-01-14 17:43:36 +00:00
|
|
|
except TimeoutException:
|
|
|
|
break
|
|
|
|
|
|
|
|
def get_chat_with_user(self, username):
|
|
|
|
return ChatElement(self.driver, username)
|
2018-01-26 11:07:09 +00:00
|
|
|
|
|
|
|
def add_contact(self, public_key):
|
|
|
|
start_new_chat = self.plus_button.click()
|
2018-03-15 20:01:08 +00:00
|
|
|
start_new_chat.start_new_chat_button.click()
|
|
|
|
start_new_chat.public_key_edit_box.set_value(public_key)
|
2018-01-26 11:07:09 +00:00
|
|
|
start_new_chat.confirm()
|
2018-03-15 20:01:08 +00:00
|
|
|
one_to_one_chat = self.get_chat_view()
|
|
|
|
one_to_one_chat.chat_message_input.wait_for_element(60)
|
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)
|
|
|
|
start_new_chat.confirm_button.click()
|
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-03-01 13:22:01 +00:00
|
|
|
start_new_chat.chat_name_editbox.send_keys(chat_name)
|
2018-02-19 11:51:53 +00:00
|
|
|
start_new_chat.confirm()
|
2018-02-14 13:48:18 +00:00
|
|
|
|
2018-01-26 11:07:09 +00:00
|
|
|
def get_public_key(self):
|
|
|
|
profile_view = self.profile_button.click()
|
|
|
|
profile_view.share_my_contact_key_button.click()
|
|
|
|
time.sleep(4)
|
|
|
|
public_key = profile_view.get_text_from_qr()
|
|
|
|
profile_view.cross_icon.click()
|
|
|
|
return public_key
|
2018-03-15 16:07:25 +00:00
|
|
|
|
|
|
|
def swipe_and_delete_chat(self, chat_name: str):
|
|
|
|
chat_element = self.get_chat_with_user(chat_name)
|
|
|
|
location = chat_element.find_element().location
|
|
|
|
x, y = location['x'], location['y']
|
|
|
|
size = chat_element.find_element().size
|
|
|
|
width, height = size['width'], size['height']
|
2018-03-28 10:21:39 +00:00
|
|
|
counter = 0
|
|
|
|
while counter < 10:
|
|
|
|
self.driver.swipe(start_x=x + width / 2, start_y=y + height / 2, end_x=x, end_y=y + height / 2)
|
|
|
|
if chat_element.swipe_delete_button.is_element_present():
|
|
|
|
break
|
|
|
|
time.sleep(10)
|
|
|
|
counter += 1
|
2018-03-15 16:07:25 +00:00
|
|
|
chat_element.swipe_delete_button.click()
|