2018-01-14 17:43:36 +00:00
|
|
|
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 SendMessageButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SendMessageButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.accessibility_id("send-message-button")
|
|
|
|
|
|
|
|
def click(self):
|
|
|
|
self.find_element().click()
|
2018-01-26 11:07:09 +00:00
|
|
|
info('Tap on %s' % self.name)
|
2018-01-03 09:34:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
self.locator = self.Locator.accessibility_id('chat-menu')
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
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-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.send_message_button = SendMessageButton(self.driver)
|
|
|
|
self.add_to_contacts = AddToContacts(self.driver)
|
|
|
|
self.user_name_text = UserNameText(self.driver)
|
|
|
|
|
|
|
|
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-01-03 09:34:40 +00:00
|
|
|
self.chat_settings = ChatSettings(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)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
def get_messages_sent_by_user(self, username):
|
|
|
|
return MessageByUsername(self.driver, username).find_elements()
|