2018-02-14 13:48:18 +00:00
|
|
|
import time
|
|
|
|
from selenium.common.exceptions import TimeoutException
|
2018-01-26 11:07:09 +00:00
|
|
|
from tests import info
|
2018-01-14 17:43:36 +00:00
|
|
|
from views.base_element import BaseButton, BaseEditBox, BaseText
|
|
|
|
from views.base_view import BaseView
|
2018-01-03 09:34:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ChatMessageInput(BaseEditBox):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ChatMessageInput, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id('chat-message-input')
|
|
|
|
|
|
|
|
|
|
|
|
class AddToContacts(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(AddToContacts, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Add to contacts']")
|
|
|
|
|
|
|
|
|
|
|
|
class UserNameText(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(UserNameText, self).__init__(driver)
|
|
|
|
self.locator = \
|
2018-01-14 17:43:36 +00:00
|
|
|
self.Locator.xpath_selector('(//android.view.ViewGroup[@content-desc="toolbar-back-button"]'
|
|
|
|
'//..//android.widget.TextView)[1]')
|
2018-01-03 09:34:40 +00:00
|
|
|
|
|
|
|
|
2018-02-09 15:16:07 +00:00
|
|
|
class TransactionPopupText(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(TransactionPopupText, self).__init__(driver)
|
2018-02-19 11:51:53 +00:00
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Specify amount']")
|
2018-02-09 15:16:07 +00:00
|
|
|
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class SendCommand(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SendCommand, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='/send']")
|
|
|
|
|
|
|
|
|
|
|
|
class RequestCommand(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(RequestCommand, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='/request']")
|
|
|
|
|
|
|
|
|
2018-01-26 11:07:09 +00:00
|
|
|
class ChatOptions(BaseButton):
|
2018-01-03 09:34:40 +00:00
|
|
|
def __init__(self, driver):
|
2018-01-26 11:07:09 +00:00
|
|
|
super(ChatOptions, self).__init__(driver)
|
2018-03-01 13:22:01 +00:00
|
|
|
self.locator = self.Locator.xpath_selector('(//android.view.ViewGroup[@content-desc="icon"])[2]')
|
2018-01-26 11:07:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MembersButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(MembersButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector('(//android.view.ViewGroup[@content-desc="action"])[1]')
|
2018-01-03 09:34:40 +00:00
|
|
|
|
|
|
|
|
2018-02-14 13:48:18 +00:00
|
|
|
class DeleteChatButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(DeleteChatButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector('//*[@text="Delete chat"]')
|
|
|
|
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class ChatSettings(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ChatSettings, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='Settings']")
|
|
|
|
|
|
|
|
|
|
|
|
class UserOptions(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(UserOptions, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector('//android.widget.ImageView[@content-desc="chat-icon"]'
|
|
|
|
'/../..//android.view.View')
|
|
|
|
|
|
|
|
|
|
|
|
class RemoveButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(RemoveButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='Remove']")
|
|
|
|
|
|
|
|
|
|
|
|
class FirstRecipient(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(FirstRecipient, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Choose recipient']/.."
|
|
|
|
"//android.widget.ImageView[@content-desc='chat-icon']")
|
|
|
|
|
|
|
|
|
2018-01-26 11:07:09 +00:00
|
|
|
class MessageByUsername(BaseText):
|
|
|
|
def __init__(self, driver, username):
|
|
|
|
super(MessageByUsername, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector('//*[@text="' + username + '"]'
|
|
|
|
'/following-sibling::android.widget.TextView')
|
|
|
|
|
|
|
|
|
|
|
|
class MoreUsersButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(MoreUsersButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//android.widget.TextView[contains(@text, 'MORE')]")
|
|
|
|
|
|
|
|
|
2018-02-13 17:22:41 +00:00
|
|
|
class UserProfileDetails(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(UserProfileDetails, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Profile']")
|
|
|
|
|
|
|
|
|
2018-02-14 13:48:18 +00:00
|
|
|
class OpenInBrowserButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(OpenInBrowserButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//*[@text='Open in browser']")
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.web_views.base_web_view import BaseWebView
|
|
|
|
return BaseWebView(self.driver)
|
|
|
|
|
|
|
|
|
2018-02-19 11:51:53 +00:00
|
|
|
class CommandsButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(CommandsButton, self).__init__(driver)
|
2018-03-15 20:01:08 +00:00
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
'//*[@content-desc="chat-message-input"]/..//android.view.ViewGroup[@content-desc="icon"]')
|
2018-02-19 11:51:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ViewProfileButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ViewProfileButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector('//*[@text="View profile"]')
|
|
|
|
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class ChatView(BaseView):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ChatView, self).__init__(driver)
|
|
|
|
|
|
|
|
self.chat_message_input = ChatMessageInput(self.driver)
|
|
|
|
self.add_to_contacts = AddToContacts(self.driver)
|
|
|
|
self.user_name_text = UserNameText(self.driver)
|
|
|
|
|
2018-02-19 11:51:53 +00:00
|
|
|
self.commands_button = CommandsButton(self.driver)
|
2018-01-03 09:34:40 +00:00
|
|
|
self.send_command = SendCommand(self.driver)
|
|
|
|
self.request_command = RequestCommand(self.driver)
|
|
|
|
|
2018-01-26 11:07:09 +00:00
|
|
|
self.chat_options = ChatOptions(self.driver)
|
|
|
|
self.members_button = MembersButton(self.driver)
|
2018-02-14 13:48:18 +00:00
|
|
|
self.delete_chat_button = DeleteChatButton(self.driver)
|
2018-01-26 11:07:09 +00:00
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
self.chat_settings = ChatSettings(self.driver)
|
2018-02-19 11:51:53 +00:00
|
|
|
self.view_profile_button = ViewProfileButton(self.driver)
|
2018-01-26 11:07:09 +00:00
|
|
|
self.more_users_button = MoreUsersButton(self.driver)
|
2018-01-03 09:34:40 +00:00
|
|
|
self.user_options = UserOptions(self.driver)
|
|
|
|
self.remove_button = RemoveButton(self.driver)
|
|
|
|
|
|
|
|
self.first_recipient_button = FirstRecipient(self.driver)
|
|
|
|
|
2018-02-13 17:22:41 +00:00
|
|
|
self.user_profile_details = UserProfileDetails(self.driver)
|
|
|
|
|
2018-02-14 13:48:18 +00:00
|
|
|
self.open_in_browser_button = OpenInBrowserButton(self.driver)
|
2018-02-13 17:22:41 +00:00
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
def wait_for_syncing_complete(self):
|
2018-01-26 11:07:09 +00:00
|
|
|
info('Waiting for syncing complete:')
|
2018-01-03 09:34:40 +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-03 09:34:40 +00:00
|
|
|
except TimeoutException:
|
|
|
|
break
|
2018-01-26 11:07:09 +00:00
|
|
|
|
2018-02-14 13:48:18 +00:00
|
|
|
def wait_for_message_in_one_to_one_chat(self, expected_message: str, errors: list):
|
|
|
|
try:
|
|
|
|
self.find_full_text(expected_message, wait_time=20)
|
|
|
|
except TimeoutException:
|
|
|
|
errors.append('Message with text "%s" was not received' % expected_message)
|
|
|
|
|
|
|
|
def wait_for_messages_by_user(self, username: str, expected_messages: list, errors: list, wait_time: int = 30):
|
|
|
|
expected_messages = expected_messages if type(expected_messages) == list else [expected_messages]
|
|
|
|
repeat = 0
|
|
|
|
while repeat <= wait_time:
|
|
|
|
received_messages = [element.text for element in MessageByUsername(self.driver, username).find_elements()]
|
|
|
|
if not set(expected_messages) - set(received_messages):
|
|
|
|
break
|
|
|
|
time.sleep(3)
|
|
|
|
repeat += 3
|
|
|
|
if set(expected_messages) - set(received_messages):
|
2018-03-15 20:01:08 +00:00
|
|
|
errors.append('Not received messages from user %s: "%s"' % (username, ', '.join(
|
|
|
|
[i for i in list(set(expected_messages) - set(received_messages))])))
|
|
|
|
|
|
|
|
def wait_for_messages(self, username: str, expected_messages: list, errors: list, wait_time: int = 30):
|
|
|
|
expected_messages = expected_messages if type(expected_messages) == list else [expected_messages]
|
|
|
|
repeat = 0
|
|
|
|
received_messages = list()
|
|
|
|
while repeat <= wait_time:
|
|
|
|
for message in expected_messages:
|
|
|
|
if self.element_by_text(message, 'text').is_element_present(1):
|
|
|
|
received_messages.append(message)
|
|
|
|
if not set(expected_messages) - set(received_messages):
|
|
|
|
break
|
|
|
|
time.sleep(3)
|
|
|
|
repeat += 3
|
|
|
|
if set(expected_messages) - set(received_messages):
|
2018-02-14 13:48:18 +00:00
|
|
|
errors.append('Not received messages from user %s: "%s"' % (username, ', '.join(
|
|
|
|
[i for i in list(set(expected_messages) - set(received_messages))])))
|
2018-02-09 15:16:07 +00:00
|
|
|
|
|
|
|
def send_eth_to_request(self, request, sender_password):
|
2018-02-19 11:51:53 +00:00
|
|
|
gas_popup = self.element_by_text_part('Specify amount')
|
2018-02-09 15:16:07 +00:00
|
|
|
request.click_until_presence_of_element(gas_popup)
|
|
|
|
send_transaction = self.get_send_transaction_view()
|
|
|
|
self.send_message_button.click_until_presence_of_element(send_transaction.sign_transaction_button)
|
|
|
|
send_transaction.sign_transaction(sender_password)
|
2018-03-15 16:07:25 +00:00
|
|
|
|
|
|
|
def delete_chat(self, chat_name: str, errors: list):
|
|
|
|
self.chat_options.click()
|
|
|
|
self.delete_chat_button.click()
|
|
|
|
self.delete_button.click()
|
|
|
|
from views.home_view import HomeView
|
|
|
|
if not HomeView(self.driver).plus_button.is_element_present() or \
|
|
|
|
self.element_by_text(chat_name).is_element_present():
|
|
|
|
errors.append('Chat was not deleted')
|