2021-07-08 08:32:08 +00:00
|
|
|
import re
|
2022-11-21 04:49:53 +00:00
|
|
|
import time
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from time import sleep
|
2018-06-21 23:57:54 +00:00
|
|
|
|
2022-11-21 04:49:53 +00:00
|
|
|
import dateutil.parser
|
2023-02-28 12:44:13 +00:00
|
|
|
from appium.webdriver.common.touch_action import TouchAction
|
2023-02-24 19:05:30 +00:00
|
|
|
from selenium.common.exceptions import NoSuchElementException, TimeoutException
|
2018-09-17 08:50:01 +00:00
|
|
|
|
2020-08-14 16:05:41 +00:00
|
|
|
from tests import emojis
|
2021-01-25 16:35:40 +00:00
|
|
|
from views.base_element import Button, EditBox, Text, BaseElement, SilentButton
|
2021-04-30 09:31:39 +00:00
|
|
|
from views.base_view import BaseView
|
2021-07-08 08:32:08 +00:00
|
|
|
from views.home_view import HomeView
|
2022-11-21 04:49:53 +00:00
|
|
|
from views.profile_view import ProfilePictureElement
|
2018-01-03 09:34:40 +00:00
|
|
|
|
|
|
|
|
2021-02-19 13:46:29 +00:00
|
|
|
class CommandsButton(Button):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super().__init__(driver, accessibility_id="show-extensions-icon")
|
|
|
|
|
|
|
|
def click(self):
|
|
|
|
self.click_until_presence_of_element(SendCommand(self.driver))
|
|
|
|
return self.navigate()
|
|
|
|
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class SendCommand(Button):
|
2018-01-03 09:34:40 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, translation_id="send-transaction")
|
2020-03-24 15:45:15 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.send_transaction_view import SendTransactionView
|
|
|
|
return SendTransactionView(self.driver)
|
2018-01-03 09:34:40 +00:00
|
|
|
|
2018-08-29 14:04:12 +00:00
|
|
|
def click(self):
|
|
|
|
self.wait_for_element().click()
|
|
|
|
return self.navigate()
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class RequestCommand(Button):
|
2018-01-03 09:34:40 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, translation_id="request-transaction")
|
2020-04-02 10:30:20 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.send_transaction_view import SendTransactionView
|
|
|
|
return SendTransactionView(self.driver)
|
2018-01-03 09:34:40 +00:00
|
|
|
|
2018-08-29 14:04:12 +00:00
|
|
|
def click(self):
|
|
|
|
self.wait_for_element().click()
|
|
|
|
return self.navigate()
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class GroupInfoButton(Button):
|
2018-12-05 14:11:50 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, translation_id="group-info")
|
2018-12-05 14:11:50 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
return GroupChatInfoView(self.driver)
|
|
|
|
|
2020-04-10 10:25:46 +00:00
|
|
|
def click(self):
|
|
|
|
self.wait_for_element().click()
|
|
|
|
return self.navigate()
|
|
|
|
|
2019-10-23 17:17:54 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class UnblockContactButton(Button):
|
2019-10-23 17:17:54 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, accessibility_id="Unblock-item-button")
|
2019-04-19 15:29:35 +00:00
|
|
|
|
2020-09-18 15:26:27 +00:00
|
|
|
def click(self):
|
|
|
|
self.scroll_to_element()
|
|
|
|
self.wait_for_element().click()
|
|
|
|
|
2018-05-23 13:02:45 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class OpenInStatusButton(Button):
|
2018-02-14 13:48:18 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, translation_id="browsing-open-in-status")
|
2018-02-14 13:48:18 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.web_views.base_web_view import BaseWebView
|
|
|
|
return BaseWebView(self.driver)
|
|
|
|
|
2019-03-12 12:18:03 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ViewProfileButton(Button):
|
2018-02-19 11:51:53 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, translation_id="view-profile")
|
2018-02-19 11:51:53 +00:00
|
|
|
|
2020-12-03 12:59:20 +00:00
|
|
|
def navigate(self):
|
|
|
|
return ChatView(self.driver)
|
|
|
|
|
2021-02-19 13:46:29 +00:00
|
|
|
|
2021-02-08 12:52:20 +00:00
|
|
|
class ChatOptionsButton(Button):
|
|
|
|
def __init__(self, driver):
|
2022-05-30 11:49:30 +00:00
|
|
|
super().__init__(driver, accessibility_id="chat-menu-button")
|
2021-10-22 17:23:27 +00:00
|
|
|
|
2021-02-08 12:52:20 +00:00
|
|
|
def click(self):
|
2021-08-02 15:00:18 +00:00
|
|
|
self.click_until_presence_of_element(HomeView(self.driver).mark_all_messages_as_read_button)
|
2021-02-08 12:52:20 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
return ChatView(self.driver)
|
|
|
|
|
2018-04-26 06:22:11 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ProfileSendMessageButton(Button):
|
2018-05-02 16:01:17 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, accessibility_id="Chat-item-button")
|
2018-05-02 16:01:17 +00:00
|
|
|
|
2020-10-20 15:34:52 +00:00
|
|
|
def navigate(self):
|
|
|
|
return ChatView(self.driver)
|
2018-05-02 16:01:17 +00:00
|
|
|
|
2019-07-11 15:44:12 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ProfileBlockContactButton(Button):
|
2019-04-19 15:29:35 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super(ProfileBlockContactButton, self).__init__(driver, accessibility_id="Block-item-button")
|
2018-05-02 16:01:17 +00:00
|
|
|
|
2020-09-18 15:26:27 +00:00
|
|
|
def click(self):
|
|
|
|
self.scroll_to_element()
|
|
|
|
self.wait_for_element().click()
|
|
|
|
|
2022-11-21 04:49:53 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ChatElementByText(Text):
|
2018-06-21 16:40:27 +00:00
|
|
|
def __init__(self, driver, text):
|
2018-07-03 18:50:18 +00:00
|
|
|
self.message_text = text
|
2021-07-23 08:02:42 +00:00
|
|
|
if text in ["image", "sticker", "audio"]:
|
|
|
|
self.message_locator = "//android.view.ViewGroup[@content-desc='%s-message']" % text
|
|
|
|
else:
|
|
|
|
self.message_locator = "//*[starts-with(@text,'%s')]" % text
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, prefix=self.message_locator,
|
|
|
|
xpath="/ancestor::android.view.ViewGroup[@content-desc='chat-item']")
|
2018-06-21 16:40:27 +00:00
|
|
|
|
2018-07-03 18:50:18 +00:00
|
|
|
def find_element(self):
|
|
|
|
for _ in range(2):
|
|
|
|
try:
|
|
|
|
return super(ChatElementByText, self).find_element()
|
|
|
|
except NoSuchElementException:
|
2021-02-16 14:57:20 +00:00
|
|
|
self.wait_for_visibility_of_element(20)
|
2018-07-03 18:50:18 +00:00
|
|
|
|
2020-06-12 15:32:06 +00:00
|
|
|
@property
|
|
|
|
def image_in_reply(self):
|
|
|
|
class ImageInReply(BaseElement):
|
2021-01-25 16:35:40 +00:00
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="//android.widget.ImageView")
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2020-06-12 15:32:06 +00:00
|
|
|
try:
|
2021-01-25 16:35:40 +00:00
|
|
|
return ImageInReply(self.driver, self.locator)
|
2020-06-12 15:32:06 +00:00
|
|
|
except NoSuchElementException:
|
|
|
|
return ''
|
|
|
|
|
2020-03-24 15:45:15 +00:00
|
|
|
@property
|
2021-12-29 16:10:22 +00:00
|
|
|
def timestamp_command_message(self):
|
2021-12-21 13:57:13 +00:00
|
|
|
class TimeStampText(Button):
|
2020-03-24 15:45:15 +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)
|
2020-03-24 15:45:15 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
return TimeStampText(self.driver, self.locator)
|
2020-03-24 15:45:15 +00:00
|
|
|
|
2021-12-29 16:10:22 +00:00
|
|
|
@property
|
2022-10-28 12:57:18 +00:00
|
|
|
def timestamp(self):
|
|
|
|
class TimeStampText(Button):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, xpath="%s//*[@content-desc='message-timestamp']" % parent_locator)
|
2022-11-21 04:49:53 +00:00
|
|
|
|
2022-10-28 12:57:18 +00:00
|
|
|
return TimeStampText(self.driver, self.locator).text
|
2021-12-29 16:10:22 +00:00
|
|
|
|
2018-07-03 18:50:18 +00:00
|
|
|
@property
|
|
|
|
def member_photo(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
class MemberPhoto(Button):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2022-11-22 16:44:28 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="//*[@content-desc='user-avatar']")
|
2018-07-03 18:50:18 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
return MemberPhoto(self.driver, self.locator)
|
2018-06-21 16:40:27 +00:00
|
|
|
|
2018-06-28 18:46:51 +00:00
|
|
|
@property
|
|
|
|
def username(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
class Username(Text):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2023-02-24 19:05:30 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator,
|
|
|
|
xpath="/android.view.ViewGroup/android.widget.TextView[1]")
|
2018-06-28 18:46:51 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
return Username(self.driver, self.locator)
|
2018-06-28 18:46:51 +00:00
|
|
|
|
2018-07-13 10:56:36 +00:00
|
|
|
def contains_text(self, text, wait_time=5) -> bool:
|
2021-01-25 16:35:40 +00:00
|
|
|
element = Text(self.driver, prefix=self.locator,
|
|
|
|
xpath="//android.view.ViewGroup//android.widget.TextView[contains(@text,'%s')]" % text)
|
2018-07-13 10:56:36 +00:00
|
|
|
return element.is_element_displayed(wait_time)
|
2018-07-03 18:50:18 +00:00
|
|
|
|
2023-04-28 10:15:32 +00:00
|
|
|
def wait_for_sent_state(self, wait_time=30):
|
|
|
|
return BaseElement(self.driver, prefix=self.locator,
|
|
|
|
xpath="//*[@content-desc='message-sent']").is_element_displayed(wait_time)
|
|
|
|
|
2021-04-30 09:31:39 +00:00
|
|
|
@property
|
|
|
|
def uncollapse(self) -> bool:
|
|
|
|
class Collapse(Button):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2021-11-18 15:16:48 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator,
|
|
|
|
xpath="/../../..//android.widget.ImageView[@content-desc='icon']")
|
2021-04-30 09:31:39 +00:00
|
|
|
|
|
|
|
return Collapse(self.driver, self.locator).is_element_displayed()
|
|
|
|
|
2021-02-26 15:27:20 +00:00
|
|
|
@property
|
|
|
|
def status(self) -> str:
|
2023-02-24 19:05:30 +00:00
|
|
|
Text(self.driver, xpath=self.locator).click()
|
|
|
|
status_element = Text(self.driver, prefix=self.locator,
|
|
|
|
xpath="//*[@content-desc='message-status']/android.widget.TextView")
|
|
|
|
status = ''
|
|
|
|
i = 1
|
|
|
|
|
|
|
|
while i < 5:
|
|
|
|
i += 1
|
|
|
|
if Text(self.driver, prefix=self.locator,
|
|
|
|
xpath="//*[@content-desc='message-sending']").is_element_displayed(2):
|
|
|
|
status = "Sending"
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
Text(self.driver, xpath=self.locator).click()
|
|
|
|
if status_element.is_element_displayed(2):
|
|
|
|
status = status_element.text
|
|
|
|
break
|
|
|
|
time.sleep(2)
|
|
|
|
return status
|
|
|
|
|
|
|
|
def wait_for_status_to_be(self, expected_status: str, timeout: int = 30):
|
2023-03-13 13:29:18 +00:00
|
|
|
self.driver.info("Waiting for message to be sent for %s sec" % timeout)
|
2023-02-24 19:05:30 +00:00
|
|
|
start_time = time.time()
|
2023-06-28 12:27:57 +00:00
|
|
|
current_status = 'not set'
|
2023-02-24 19:05:30 +00:00
|
|
|
while time.time() - start_time <= timeout:
|
2023-06-28 12:27:57 +00:00
|
|
|
current_status = self.status
|
2023-06-08 02:57:38 +00:00
|
|
|
if current_status == expected_status:
|
2023-02-24 19:05:30 +00:00
|
|
|
return
|
|
|
|
time.sleep(1)
|
2023-06-08 02:57:38 +00:00
|
|
|
raise TimeoutException("Message status was not changed to %s, it's %s" % (expected_status, current_status))
|
2021-02-26 15:27:20 +00:00
|
|
|
|
2021-12-21 13:57:13 +00:00
|
|
|
@property
|
|
|
|
def sent_status_checkmark(self) -> object:
|
|
|
|
return Text(self.driver, prefix=self.locator, xpath="//*[@content-desc='sent']")
|
|
|
|
|
2019-08-02 21:22:23 +00:00
|
|
|
@property
|
|
|
|
def replied_message_text(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
class RepliedMessageText(Text):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2021-11-18 15:16:48 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator,
|
2022-12-13 18:07:34 +00:00
|
|
|
xpath="/preceding::android.widget.TextView[@content-desc='quoted-message']")
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2019-08-02 21:22:23 +00:00
|
|
|
try:
|
|
|
|
return RepliedMessageText(self.driver, self.message_locator).text
|
|
|
|
except NoSuchElementException:
|
|
|
|
return ''
|
|
|
|
|
2019-12-27 15:26:34 +00:00
|
|
|
@property
|
|
|
|
def replied_to_username_text(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
class RepliedToUsernameText(Text):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator,
|
2021-02-23 14:38:17 +00:00
|
|
|
xpath="/preceding-sibling::*[1]/android.widget.TextView[1]")
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2019-12-27 15:26:34 +00:00
|
|
|
try:
|
|
|
|
return RepliedToUsernameText(self.driver, self.message_locator).text
|
|
|
|
except NoSuchElementException:
|
|
|
|
return ''
|
2022-11-21 04:49:53 +00:00
|
|
|
|
2022-10-26 15:14:25 +00:00
|
|
|
def emojis_below_message(self, emoji: str = 'thumbs-up'):
|
2021-01-25 16:35:40 +00:00
|
|
|
class EmojisNumber(Text):
|
2020-08-14 16:05:41 +00:00
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
self.emoji = emoji
|
2022-10-26 15:14:25 +00:00
|
|
|
self.emojis_id = 'emoji-reaction-%s' % str(emojis[self.emoji])
|
2022-11-21 04:49:53 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator,
|
|
|
|
xpath="/../..//*[@content-desc='%s']/android.widget.TextView" % self.emojis_id)
|
2020-08-14 16:05:41 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def text(self):
|
|
|
|
try:
|
|
|
|
text = self.find_element().text
|
2022-10-26 15:14:25 +00:00
|
|
|
self.driver.info("%s is '%s' for '%s'" % (self.name, text, self.emoji))
|
|
|
|
return int(text.strip())
|
2020-08-14 16:05:41 +00:00
|
|
|
except NoSuchElementException:
|
|
|
|
return 0
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2023-01-05 17:00:58 +00:00
|
|
|
return EmojisNumber(self.driver, self.locator)
|
2022-10-28 12:57:18 +00:00
|
|
|
|
2023-05-15 16:00:28 +00:00
|
|
|
@property
|
|
|
|
def image_in_message(self):
|
|
|
|
try:
|
|
|
|
self.driver.info("Trying to access image inside message with text '%s'" % self.message_text)
|
|
|
|
ChatElementByText(self.driver, self.message_text).wait_for_sent_state(60)
|
2023-06-02 15:42:06 +00:00
|
|
|
return Button(self.driver, xpath="%s//*[@content-desc='image-message']" % self.locator)
|
2023-05-15 16:00:28 +00:00
|
|
|
except NoSuchElementException:
|
|
|
|
self.driver.fail("No image is found in message!")
|
|
|
|
|
2023-07-14 15:08:04 +00:00
|
|
|
class ImageContainer(Button):
|
|
|
|
def __init__(self, driver, parent_locator):
|
|
|
|
super().__init__(driver, xpath='%s//*[@content-desc="image-container"]' % parent_locator)
|
|
|
|
|
|
|
|
def image_by_index(self, index: int):
|
|
|
|
return BaseElement(self.driver, xpath="(%s//android.widget.ImageView)[%s]" % (self.locator, index))
|
|
|
|
|
2023-05-19 16:03:48 +00:00
|
|
|
@property
|
|
|
|
def image_container_in_message(self):
|
|
|
|
try:
|
2023-06-08 02:57:38 +00:00
|
|
|
self.driver.info(
|
|
|
|
"Trying to access images (image container) inside message with text '%s'" % self.message_text)
|
2023-05-19 16:03:48 +00:00
|
|
|
ChatElementByText(self.driver, self.message_text).wait_for_sent_state(60)
|
2023-07-14 15:08:04 +00:00
|
|
|
return self.ImageContainer(self.driver, self.locator)
|
2023-05-19 16:03:48 +00:00
|
|
|
except NoSuchElementException:
|
|
|
|
self.driver.fail("No image container is found in message!")
|
|
|
|
|
2021-07-20 08:34:10 +00:00
|
|
|
@property
|
|
|
|
def pinned_by_label(self):
|
|
|
|
class PinnedByLabelText(Text):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator,
|
|
|
|
xpath="/../..//android.view.ViewGroup[@content-desc='pinned-by']")
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2021-07-20 08:34:10 +00:00
|
|
|
return PinnedByLabelText(self.driver, self.locator)
|
2018-06-21 16:40:27 +00:00
|
|
|
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class UsernameOptions(Button):
|
2019-03-26 09:23:01 +00:00
|
|
|
def __init__(self, driver, username):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver, xpath="//*[@text='%s']/..//*[@content-desc='menu-option']" % username)
|
2020-04-10 10:25:46 +00:00
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
return ChatView(self.driver)
|
|
|
|
|
|
|
|
def click(self):
|
2020-09-09 15:06:07 +00:00
|
|
|
self.scroll_to_element()
|
2020-04-10 10:25:46 +00:00
|
|
|
self.wait_for_element().click()
|
|
|
|
return self.navigate()
|
|
|
|
|
2021-02-04 12:51:01 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class UsernameCheckbox(Button):
|
2020-04-10 10:25:46 +00:00
|
|
|
def __init__(self, driver, username):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.username = username
|
2023-03-31 14:13:27 +00:00
|
|
|
super().__init__(driver, xpath="//*[@text='%s']/..//*[@content-desc='checkbox-off']" % username)
|
2020-04-10 10:25:46 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
def click(self):
|
|
|
|
try:
|
2021-11-18 15:16:48 +00:00
|
|
|
self.scroll_to_element(20).click()
|
2021-01-25 16:35:40 +00:00
|
|
|
except NoSuchElementException:
|
2021-11-18 15:16:48 +00:00
|
|
|
self.scroll_to_element(direction='up', depth=20).click()
|
2020-10-20 15:34:52 +00:00
|
|
|
|
2021-02-04 12:51:01 +00:00
|
|
|
|
2018-12-05 14:11:50 +00:00
|
|
|
class GroupChatInfoView(BaseView):
|
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver)
|
|
|
|
self.add_members = Button(self.driver, translation_id="add-members")
|
2018-12-05 14:11:50 +00:00
|
|
|
|
2019-03-26 09:23:01 +00:00
|
|
|
def get_username_options(self, username: str):
|
|
|
|
return UsernameOptions(self.driver, username)
|
|
|
|
|
2020-04-10 10:25:46 +00:00
|
|
|
def user_admin(self, username: str):
|
2021-07-12 14:44:51 +00:00
|
|
|
admin = Button(self.driver,
|
2022-11-21 04:49:53 +00:00
|
|
|
xpath="//*[@text='%s']/..//*[@text='%s']" % (
|
|
|
|
username, self.get_translation_by_key("group-chat-admin")))
|
2021-07-12 14:44:51 +00:00
|
|
|
admin.scroll_to_element()
|
|
|
|
return admin
|
2020-04-10 10:25:46 +00:00
|
|
|
|
|
|
|
def get_user_from_group_info(self, username: str):
|
2021-07-12 14:44:51 +00:00
|
|
|
user = Text(self.driver, xpath="//*[@text='%s']" % username)
|
|
|
|
user.scroll_to_element()
|
|
|
|
return user
|
2020-09-04 13:26:14 +00:00
|
|
|
|
2021-02-04 12:51:01 +00:00
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
class CommunityView(HomeView):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super().__init__(driver)
|
|
|
|
|
2023-02-24 19:05:30 +00:00
|
|
|
#### OLD UI
|
2021-07-08 08:32:08 +00:00
|
|
|
# Main community page (list with channels)
|
|
|
|
self.add_channel_button = HomeView(self.driver).plus_button
|
|
|
|
self.community_create_a_channel_button = Button(self.driver, accessibility_id="community-create-channel")
|
|
|
|
self.channel_name_edit_box = EditBox(self.driver, translation_id="name-your-channel-placeholder")
|
|
|
|
self.channel_descripton = ChatView(self.driver).community_description_edit_box
|
|
|
|
self.community_options_button = Button(self.driver, accessibility_id="community-menu-button")
|
2023-03-24 10:06:20 +00:00
|
|
|
self.view_members_button = Button(self.driver, accessibility_id="view-members")
|
2021-07-08 08:32:08 +00:00
|
|
|
self.community_info_button = Button(self.driver, translation_id="community-info")
|
2023-03-24 10:06:20 +00:00
|
|
|
self.invite_button = Button(self.driver, accessibility_id="community-invite-people")
|
2021-07-08 08:32:08 +00:00
|
|
|
|
|
|
|
# Community info page
|
2023-06-08 02:57:38 +00:00
|
|
|
self.community_membership_request_value = Text(
|
|
|
|
self.driver, translation_id="members-label",
|
|
|
|
suffix='/following-sibling::android.view.ViewGroup/android.widget.TextView')
|
2021-07-08 08:32:08 +00:00
|
|
|
self.members_button = Button(self.driver, translation_id="members-label")
|
|
|
|
self.community_info_picture = Button(self.driver, accessibility_id="chat-icon")
|
2021-11-26 14:15:26 +00:00
|
|
|
self.leave_community_button = Button(self.driver, translation_id="leave-community")
|
|
|
|
self.edit_community_button = Button(self.driver, translation_id="edit-community")
|
2023-03-20 12:58:09 +00:00
|
|
|
self.share_community_button = Button(self.driver, accessibility_id="share-community")
|
|
|
|
self.share_community_link_button = Button(self.driver, accessibility_id="share-community-link")
|
2021-07-08 08:32:08 +00:00
|
|
|
|
|
|
|
# Members
|
|
|
|
self.invite_people_button = Button(self.driver, accessibility_id="community-invite-people")
|
|
|
|
self.membership_requests_button = Button(self.driver, translation_id="membership-requests")
|
2022-12-13 18:07:34 +00:00
|
|
|
self.share_invite_button = Button(self.driver, accessibility_id="share-community-link")
|
2021-07-08 08:32:08 +00:00
|
|
|
|
2021-11-26 14:15:26 +00:00
|
|
|
# Requesting access to community / joining community
|
2021-07-08 08:32:08 +00:00
|
|
|
self.request_access_button = Button(self.driver, translation_id="request-access")
|
|
|
|
self.membership_request_pending_text = Text(self.driver, translation_id="membership-request-pending")
|
2023-03-24 10:06:20 +00:00
|
|
|
self.join_button = Button(self.driver, accessibility_id="show-request-to-join-screen-button")
|
|
|
|
self.join_community_button = Button(self.driver, accessibility_id="join-community-button")
|
2021-11-26 14:15:26 +00:00
|
|
|
self.follow_button = Button(self.driver, translation_id="follow")
|
2021-07-08 08:32:08 +00:00
|
|
|
|
2023-02-24 19:05:30 +00:00
|
|
|
#### NEW UI
|
|
|
|
# Communities initial page
|
|
|
|
self.community_description_text = Text(self.driver, accessibility_id="community-description-text")
|
|
|
|
|
2023-03-24 10:06:20 +00:00
|
|
|
def join_community(self):
|
2023-06-29 12:05:13 +00:00
|
|
|
self.driver.info("Joining community")
|
2023-03-24 10:06:20 +00:00
|
|
|
self.join_button.click()
|
2023-06-29 12:05:13 +00:00
|
|
|
self.checkbox_button.scroll_to_element()
|
|
|
|
self.checkbox_button.enable()
|
2023-03-24 10:06:20 +00:00
|
|
|
self.join_community_button.scroll_and_click()
|
|
|
|
|
2023-02-24 19:05:30 +00:00
|
|
|
def get_channel(self, channel_name: str):
|
|
|
|
self.driver.info("Getting %s channel element in community" % channel_name)
|
|
|
|
chat_element = self.get_chat(username=channel_name, community_channel=True, wait_time=30)
|
|
|
|
return chat_element
|
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
def add_channel(self, name: str, description="Some new channel"):
|
2021-11-26 14:15:26 +00:00
|
|
|
self.driver.info("Adding channel in community")
|
2021-07-08 08:32:08 +00:00
|
|
|
self.plus_button.click()
|
|
|
|
self.community_create_a_channel_button.wait_and_click()
|
|
|
|
self.channel_name_edit_box.set_value(name)
|
|
|
|
self.channel_descripton.set_value(description)
|
|
|
|
chat_view = ChatView(self.driver)
|
|
|
|
chat_view.confirm_create_in_community_button.click()
|
|
|
|
self.get_chat(name).click()
|
|
|
|
return chat_view
|
|
|
|
|
2021-11-26 14:15:26 +00:00
|
|
|
def leave_community(self):
|
|
|
|
self.driver.info("Leaving community")
|
|
|
|
self.community_options_button.wait_and_click()
|
|
|
|
self.community_info_button.wait_and_click()
|
|
|
|
self.leave_community_button.scroll_and_click()
|
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
def copy_community_link(self):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Copy community link")
|
2021-07-08 08:32:08 +00:00
|
|
|
self.community_options_button.click()
|
|
|
|
self.community_info_button.click()
|
|
|
|
self.element_starts_with_text('join.status.im/c/').click()
|
|
|
|
community_link_text = self.element_starts_with_text('join.status.im/c/').text
|
|
|
|
self.home_button.double_click()
|
2021-11-18 15:16:48 +00:00
|
|
|
return 'https://%s' % community_link_text
|
2021-07-08 08:32:08 +00:00
|
|
|
|
|
|
|
def handle_membership_request(self, username: str, approve=True):
|
2021-11-18 15:16:48 +00:00
|
|
|
self.driver.info("Handling membership request of user '%s', approve='%s'" % (username, str(approve)))
|
2021-07-08 08:32:08 +00:00
|
|
|
self.members_button.click()
|
|
|
|
self.membership_requests_button.click()
|
|
|
|
approve_suffix, decline_suffix = '/following-sibling::android.view.ViewGroup[1]', '/following-sibling::android.view.ViewGroup[2]'
|
|
|
|
if approve:
|
|
|
|
Button(self.driver, xpath="//*[starts-with(@text,'%s')]%s" % (username, approve_suffix)).click()
|
|
|
|
else:
|
|
|
|
Button(self.driver, xpath="//*[starts-with(@text,'%s')]%s" % (username, decline_suffix)).click()
|
|
|
|
self.close_button.click()
|
|
|
|
|
2023-03-24 10:06:20 +00:00
|
|
|
def send_invite_to_community(self, community_name, user_names_to_invite):
|
2023-03-09 05:35:08 +00:00
|
|
|
if isinstance(user_names_to_invite, str):
|
|
|
|
user_names_to_invite = [user_names_to_invite]
|
2022-12-13 18:07:34 +00:00
|
|
|
self.driver.info("Send %s invite to community" % ', '.join(map(str, user_names_to_invite)))
|
2023-03-24 10:06:20 +00:00
|
|
|
self.jump_to_communities_home()
|
|
|
|
home = self.get_home_view()
|
|
|
|
community_element = home.get_chat(community_name, community=True)
|
|
|
|
community_element.long_press_until_element_is_shown(self.view_members_button)
|
|
|
|
self.view_members_button.click_until_presence_of_element(self.invite_button)
|
2022-12-13 18:07:34 +00:00
|
|
|
self.invite_button.click()
|
2023-03-09 05:35:08 +00:00
|
|
|
for user_name in user_names_to_invite:
|
|
|
|
user_contact = self.element_by_text_part(user_name)
|
|
|
|
user_contact.scroll_and_click()
|
2022-12-13 18:07:34 +00:00
|
|
|
self.share_invite_button.click_until_presence_of_element(self.invite_button)
|
|
|
|
self.back_button.click_until_presence_of_element(self.plus_button)
|
2021-07-08 08:32:08 +00:00
|
|
|
|
2023-03-20 12:58:09 +00:00
|
|
|
def share_community(self, coummunity_element, user_names_to_share):
|
|
|
|
if isinstance(user_names_to_share, str):
|
|
|
|
user_names_to_share = [user_names_to_share]
|
|
|
|
self.driver.info("Share to %s community" % ', '.join(map(str, user_names_to_share)))
|
|
|
|
coummunity_element.long_press_until_element_is_shown(self.share_community_button)
|
|
|
|
self.share_community_button.click()
|
|
|
|
for user_name in user_names_to_share:
|
|
|
|
user_contact = self.element_by_text_part(user_name)
|
|
|
|
user_contact.scroll_and_click()
|
|
|
|
self.share_community_link_button.click()
|
|
|
|
|
2023-02-24 19:05:30 +00:00
|
|
|
|
2021-02-23 14:38:17 +00:00
|
|
|
class PreviewMessage(ChatElementByText):
|
2021-11-18 15:16:48 +00:00
|
|
|
def __init__(self, driver, text: str):
|
2021-02-23 14:38:17 +00:00
|
|
|
super().__init__(driver, text=text)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def return_element_or_empty(obj):
|
|
|
|
try:
|
2021-04-30 09:31:39 +00:00
|
|
|
return obj.scroll_to_element()
|
2021-02-23 14:38:17 +00:00
|
|
|
except NoSuchElementException:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
@property
|
|
|
|
def preview_image(self):
|
|
|
|
class PreviewImage(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2023-01-24 18:26:00 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="//*[@content-desc='member-photo']")
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2021-02-23 14:38:17 +00:00
|
|
|
return PreviewMessage.return_element_or_empty(PreviewImage(self.driver, self.locator))
|
|
|
|
|
|
|
|
@property
|
|
|
|
def preview_title(self):
|
|
|
|
class PreviewTitle(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2023-05-19 16:03:48 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="//*[@content-desc='title']")
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2021-02-23 14:38:17 +00:00
|
|
|
return PreviewMessage.return_element_or_empty(PreviewTitle(self.driver, self.locator))
|
|
|
|
|
|
|
|
@property
|
|
|
|
def preview_subtitle(self):
|
|
|
|
class PreviewSubTitle(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2023-05-19 16:03:48 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="//*[@content-desc='description']")
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2021-02-23 14:38:17 +00:00
|
|
|
return PreviewMessage.return_element_or_empty(PreviewSubTitle(self.driver, self.locator))
|
|
|
|
|
2023-05-19 16:03:48 +00:00
|
|
|
@property
|
|
|
|
def preview_link(self):
|
|
|
|
class PreviewLink(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="//*[@content-desc='link']")
|
|
|
|
|
|
|
|
return PreviewMessage.return_element_or_empty(PreviewLink(self.driver, self.locator))
|
|
|
|
|
2021-02-23 14:38:17 +00:00
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
class CommunityLinkPreviewMessage(ChatElementByText):
|
2021-11-18 15:16:48 +00:00
|
|
|
def __init__(self, driver, text: str):
|
2021-07-08 08:32:08 +00:00
|
|
|
super().__init__(driver, text=text)
|
2021-11-18 15:16:48 +00:00
|
|
|
self.locator += "//*[@text='%s']" % self.get_translation_by_key('community')
|
2021-07-08 08:32:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def community_name(self) -> str:
|
|
|
|
class CommunityName(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="/following-sibling::android.widget.TextView[1]")
|
|
|
|
|
|
|
|
return CommunityName(self.driver, self.locator).text
|
|
|
|
|
|
|
|
@property
|
|
|
|
def community_description(self) -> str:
|
|
|
|
class CommunityDescription(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="/following-sibling::android.widget.TextView[2]")
|
|
|
|
|
|
|
|
return CommunityDescription(self.driver, self.locator).text
|
|
|
|
|
|
|
|
@property
|
|
|
|
def community_members_amount(self) -> int:
|
|
|
|
class CommunityMembers(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="/following-sibling::android.widget.TextView[3]")
|
2021-11-18 15:16:48 +00:00
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
members_string = CommunityMembers(self.driver, self.locator).text
|
|
|
|
|
|
|
|
return int(re.search(r'\d+', members_string).group())
|
|
|
|
|
|
|
|
def view(self) -> object:
|
|
|
|
class CommunityViewButton(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2021-11-18 15:16:48 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator,
|
|
|
|
xpath="/..//*[@text='%s']" % self.get_translation_by_key("view"))
|
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
CommunityViewButton(self.driver, self.locator).click()
|
|
|
|
CommunityView(self.driver).request_access_button.wait_for_element(20)
|
|
|
|
return CommunityView(self.driver)
|
|
|
|
|
|
|
|
|
2021-02-04 12:51:01 +00:00
|
|
|
class TransactionMessage(ChatElementByText):
|
2021-11-18 15:16:48 +00:00
|
|
|
def __init__(self, driver, text: str, transaction_value):
|
2021-02-04 12:51:01 +00:00
|
|
|
super().__init__(driver, text=text)
|
2021-05-03 14:08:29 +00:00
|
|
|
if transaction_value:
|
2021-11-18 15:16:48 +00:00
|
|
|
self.xpath = "//*[starts-with(@text,'%s')]/../*[@text='%s']/ancestor::android.view.ViewGroup[@content-desc='chat-item']" % (
|
2022-11-21 04:49:53 +00:00
|
|
|
text, transaction_value)
|
2021-02-04 12:51:01 +00:00
|
|
|
# Common statuses for incoming and outgoing transactions
|
|
|
|
self.address_requested = self.get_translation_by_key("address-requested")
|
|
|
|
self.confirmed = self.get_translation_by_key("status-confirmed")
|
|
|
|
self.pending = self.get_translation_by_key("pending")
|
|
|
|
self.declined = self.get_translation_by_key("transaction-declined")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def transaction_status(self):
|
|
|
|
class TransactionStatus(SilentButton):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="/*[1]/*[1]/*[5]/android.widget.TextView")
|
|
|
|
|
|
|
|
return TransactionStatus(self.driver, self.locator)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def decline_transaction(self):
|
|
|
|
class DeclineTransaction(Button):
|
|
|
|
def __init__(self, driver, parent_locator):
|
|
|
|
super().__init__(driver, prefix=parent_locator, translation_id="decline")
|
|
|
|
|
|
|
|
def click(self):
|
|
|
|
self.wait_for_element().click()
|
|
|
|
return self.navigate()
|
|
|
|
|
|
|
|
return DeclineTransaction(self.driver, self.locator)
|
|
|
|
|
|
|
|
|
|
|
|
class OutgoingTransaction(TransactionMessage):
|
2021-05-03 14:08:29 +00:00
|
|
|
def __init__(self, driver, account_name: str, transaction_value):
|
|
|
|
super().__init__(driver, text="↑ Outgoing transaction", transaction_value=transaction_value)
|
2021-02-04 12:51:01 +00:00
|
|
|
self.account_name = account_name
|
|
|
|
self.address_request_accepted = self.get_translation_by_key("address-request-accepted")
|
|
|
|
self.address_received = self.get_translation_by_key("address-received")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sign_and_send(self):
|
|
|
|
class SignAndSend(Button):
|
|
|
|
def __init__(self, driver, parent_locator):
|
|
|
|
super().__init__(driver, prefix=parent_locator, translation_id="sign-and-send")
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.send_transaction_view import SendTransactionView
|
|
|
|
return SendTransactionView(self.driver)
|
|
|
|
|
|
|
|
def click(self):
|
|
|
|
self.wait_for_element().click()
|
|
|
|
return self.navigate()
|
|
|
|
|
|
|
|
return SignAndSend(self.driver, self.locator)
|
|
|
|
|
|
|
|
|
|
|
|
class IncomingTransaction(TransactionMessage):
|
2021-05-03 14:08:29 +00:00
|
|
|
def __init__(self, driver, account_name: str, transaction_value):
|
|
|
|
super().__init__(driver, text="↓ Incoming transaction", transaction_value=transaction_value)
|
2021-02-04 12:51:01 +00:00
|
|
|
self.account_name = account_name
|
|
|
|
self.shared_account = "Shared '%s'" % account_name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def accept_and_share_address(self):
|
|
|
|
class AcceptAndShareAddress(Button):
|
|
|
|
def __init__(self, driver, parent_locator):
|
|
|
|
super().__init__(driver, prefix=parent_locator, translation_id="accept-and-share-address")
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from views.send_transaction_view import SendTransactionView
|
|
|
|
return SendTransactionView(self.driver)
|
|
|
|
|
|
|
|
def click(self):
|
|
|
|
self.wait_for_element().click()
|
|
|
|
return self.navigate()
|
|
|
|
|
|
|
|
return AcceptAndShareAddress(self.driver, self.locator)
|
|
|
|
|
|
|
|
|
2021-07-20 08:34:10 +00:00
|
|
|
class PinnedMessagesOnProfileButton(Button):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super().__init__(driver, xpath="//*[@content-desc='pinned-messages-item']")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def count(self):
|
|
|
|
class PinnedMessageCounter(Text):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
|
|
|
super().__init__(driver, prefix=parent_locator, xpath="/android.widget.TextView[2]")
|
|
|
|
|
|
|
|
return PinnedMessageCounter(self.driver, self.locator).text
|
|
|
|
|
|
|
|
|
|
|
|
class UnpinMessagePopUp(BaseElement):
|
|
|
|
def __init__(self, driver):
|
2021-11-18 15:16:48 +00:00
|
|
|
# self.message_text = message_text
|
2021-07-20 08:34:10 +00:00
|
|
|
super().__init__(driver, translation_id="pin-limit-reached", suffix='/..')
|
|
|
|
|
|
|
|
def click_unpin_message_button(self):
|
|
|
|
class UnpinMessageButton(Button):
|
|
|
|
def __init__(self, driver, parent_locator: str):
|
2021-11-18 15:16:48 +00:00
|
|
|
super().__init__(driver, prefix=parent_locator,
|
|
|
|
xpath="//android.widget.TextView[starts-with(@text,'Unpin')]")
|
|
|
|
|
2021-07-20 08:34:10 +00:00
|
|
|
return UnpinMessageButton(self.driver, self.locator).click()
|
|
|
|
|
|
|
|
def message_text(self, text):
|
|
|
|
element = Text(self.driver, prefix=self.locator,
|
|
|
|
xpath="//android.widget.TextView[contains(@text,'%s')]" % text)
|
|
|
|
return element
|
|
|
|
|
|
|
|
|
2022-11-21 04:49:53 +00:00
|
|
|
class PinnedMessagesList(BaseElement):
|
|
|
|
def __init__(self, driver):
|
2023-03-28 18:23:30 +00:00
|
|
|
super().__init__(driver, xpath="//*[@content-desc='pinned-messages-menu']")
|
2022-11-21 04:49:53 +00:00
|
|
|
|
2023-02-24 19:05:30 +00:00
|
|
|
def get_pinned_messages_number(self):
|
|
|
|
self.driver.info("Getting number of pinned messages inside pinned messages list element")
|
|
|
|
element = BaseElement(self.driver, prefix=self.locator, xpath="//*[@content-desc='message-sent']")
|
|
|
|
return len(element.find_elements())
|
|
|
|
|
2022-11-21 04:49:53 +00:00
|
|
|
def message_element_by_text(self, text):
|
2023-02-27 15:38:50 +00:00
|
|
|
message_element = Button(self.driver, prefix=self.locator, xpath="//*[starts-with(@text,'%s')]" % text)
|
2022-11-21 04:49:53 +00:00
|
|
|
self.driver.info("Looking for a pinned message by text: %s" % message_element.exclude_emoji(text))
|
|
|
|
return message_element
|
|
|
|
|
|
|
|
def get_message_pinned_by_text(self, text):
|
2023-03-01 11:33:58 +00:00
|
|
|
xpath = "//*[starts-with(@text,'%s')]/../../*[@content-desc='pinned-by']/android.widget.TextView" % text
|
2022-11-21 04:49:53 +00:00
|
|
|
pinned_by_element = Text(self.driver, prefix=self.locator, xpath=xpath)
|
|
|
|
self.driver.info("Looking for a pinned by message with text: %s" % text)
|
|
|
|
return pinned_by_element
|
|
|
|
|
|
|
|
|
2023-02-28 12:44:13 +00:00
|
|
|
class ChatMessageInput(EditBox):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super().__init__(driver, accessibility_id="chat-message-input")
|
|
|
|
|
|
|
|
def paste_text_from_clipboard(self):
|
|
|
|
action = TouchAction(self.driver)
|
|
|
|
location = self.find_element().location
|
|
|
|
x, y = location['x'], location['y']
|
|
|
|
action.long_press(x=x + 250, y=y).release().perform() # long press
|
|
|
|
action.tap(x=x + 50, y=y - 50).release().perform() # tap Paste
|
|
|
|
|
2023-03-09 05:35:08 +00:00
|
|
|
def click_inside(self):
|
|
|
|
action = TouchAction(self.driver)
|
|
|
|
location = self.find_element().location
|
|
|
|
x, y = location['x'], location['y']
|
|
|
|
action.tap(x=x + 250, y=y).release().perform()
|
|
|
|
|
2023-02-28 12:44:13 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
class ChatView(BaseView):
|
2020-11-12 17:28:34 +00:00
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver)
|
2020-12-02 13:18:36 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
# Start new chat
|
2021-02-01 16:09:04 +00:00
|
|
|
self.public_key_edit_box = EditBox(self.driver, accessibility_id="enter-contact-code-input")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.scan_contact_code_button = Button(self.driver, accessibility_id="scan-contact-code-button")
|
2023-01-30 17:18:00 +00:00
|
|
|
self.view_profile_new_contact_button = Button(self.driver, accessibility_id="new-contact-button")
|
2021-01-25 16:35:40 +00:00
|
|
|
|
|
|
|
# Chat header
|
|
|
|
self.user_name_text = Text(self.driver, accessibility_id="chat-name-text")
|
2023-06-26 09:59:29 +00:00
|
|
|
self.user_name_text_new_UI = Text(
|
|
|
|
self.driver,
|
|
|
|
xpath="//*[@content-desc='user-avatar']/../following-sibling::android.widget.TextView")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.add_to_contacts = Button(self.driver, accessibility_id="add-to-contacts-button")
|
|
|
|
## Options
|
2021-02-08 12:52:20 +00:00
|
|
|
self.chat_options = ChatOptionsButton(self.driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.delete_chat_button = Button(self.driver, translation_id="delete-chat")
|
|
|
|
self.clear_history_button = Button(self.driver, translation_id="clear-history")
|
|
|
|
self.reply_message_button = Button(self.driver, translation_id="message-reply")
|
|
|
|
self.share_chat_button = Button(self.driver, accessibility_id="share-chat-button")
|
2023-03-20 12:58:09 +00:00
|
|
|
self.clear_button = Button(self.driver, translation_id="clear-history")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.view_profile_button = ViewProfileButton(self.driver)
|
|
|
|
self.view_profile_by_avatar_button = Button(self.driver, accessibility_id="member-photo")
|
|
|
|
self.user_options = Button(self.driver, accessibility_id="options")
|
|
|
|
self.open_in_status_button = OpenInStatusButton(self.driver)
|
2021-11-18 15:16:48 +00:00
|
|
|
self.close_modal_view_from_chat_button = Button(self.driver,
|
|
|
|
xpath="//androidx.appcompat.widget.LinearLayoutCompat")
|
2020-12-02 13:18:36 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
# Chat input
|
2023-02-28 12:44:13 +00:00
|
|
|
self.chat_message_input = ChatMessageInput(self.driver)
|
2023-01-09 13:46:24 +00:00
|
|
|
self.cancel_reply_button = Button(self.driver, accessibility_id="reply-cancel-button")
|
2023-05-19 16:03:48 +00:00
|
|
|
self.url_preview_composer = Button(self.driver, accessibility_id="url-preview")
|
2023-06-08 02:57:38 +00:00
|
|
|
self.url_preview_composer_text = Text(self.driver,
|
|
|
|
xpath='//*[@content-desc="url-preview"]//*[@content-desc="title"]')
|
|
|
|
self.quote_username_in_message_input = EditBox(
|
|
|
|
self.driver,
|
|
|
|
xpath="//*[@content-desc='reply-cancel-button']/preceding::android.widget.TextView[3]")
|
2022-07-20 14:03:42 +00:00
|
|
|
self.chat_item = Button(self.driver, xpath="(//*[@content-desc='chat-item'])[1]")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.chat_name_editbox = EditBox(self.driver, accessibility_id="chat-name-input")
|
2021-02-19 13:46:29 +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-05-16 07:22:02 +00:00
|
|
|
|
2021-04-30 09:31:39 +00:00
|
|
|
# General chat view
|
|
|
|
self.history_start_icon = Button(self.driver, accessibility_id="history-chat")
|
2021-07-20 08:34:10 +00:00
|
|
|
self.unpin_message_popup = UnpinMessagePopUp(self.driver)
|
2022-07-02 07:50:03 +00:00
|
|
|
self.contact_request_button = Button(self.driver, accessibility_id="contact-request--button")
|
2021-04-30 09:31:39 +00:00
|
|
|
|
2021-11-18 15:16:48 +00:00
|
|
|
# Stickers
|
2021-01-25 16:35:40 +00:00
|
|
|
self.show_stickers_button = Button(self.driver, accessibility_id="show-stickers-icon")
|
|
|
|
self.get_stickers = Button(self.driver, translation_id="get-stickers")
|
|
|
|
self.sticker_icon = Button(self.driver, accessibility_id="sticker-icon")
|
|
|
|
self.sticker_message = Button(self.driver, accessibility_id="sticker-message")
|
2019-03-12 12:18:03 +00:00
|
|
|
|
2020-06-12 15:32:06 +00:00
|
|
|
# Images
|
2023-05-15 16:00:28 +00:00
|
|
|
self.show_images_button = Button(self.driver, accessibility_id="open-images-button")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.take_photo_button = Button(self.driver, accessibility_id="take-picture")
|
|
|
|
self.image_from_gallery_button = Button(self.driver, accessibility_id="open-gallery")
|
2023-05-15 16:00:28 +00:00
|
|
|
self.images_confirm_selection_button = Button(self.driver, accessibility_id="confirm-selection")
|
2021-10-22 17:23:27 +00:00
|
|
|
self.images_area_in_gallery = Button(self.driver,
|
2021-11-18 15:16:48 +00:00
|
|
|
xpath="//*[@content-desc='open-gallery']/following-sibling::android.view.ViewGroup[1]")
|
2021-07-26 16:13:53 +00:00
|
|
|
self.image_message_in_chat = Button(self.driver, accessibility_id="image-message")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.save_image_button = Button(self.driver, translation_id="save")
|
|
|
|
self.recent_image_in_gallery = Button(self.driver,
|
|
|
|
xpath="//*[contains(@resource-id,'thumbnail')]")
|
|
|
|
self.cancel_send_image_button = Button(self.driver, accessibility_id="cancel-send-image")
|
2023-07-14 15:08:04 +00:00
|
|
|
self.share_image_icon_button = Button(self.driver, accessibility_id="share-image")
|
|
|
|
self.view_image_options_button = Button(self.driver, accessibility_id="image-options")
|
|
|
|
self.save_image_icon_button = Button(self.driver, accessibility_id="save-image")
|
2021-10-22 17:23:27 +00:00
|
|
|
self.image_in_android_messenger = Button(self.driver, accessibility_id="Image")
|
2021-01-25 16:35:40 +00:00
|
|
|
|
2021-11-18 15:16:48 +00:00
|
|
|
# Audio
|
2021-07-23 08:02:42 +00:00
|
|
|
self.audio_message_in_chat = Button(self.driver, accessibility_id="audio-message")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.audio_message_button = Button(self.driver, accessibility_id="show-audio-message-icon")
|
|
|
|
self.record_audio_button = Button(self.driver, accessibility_id="start-stop-audio-recording-button")
|
|
|
|
self.cancel_audio_message_button = Button(self.driver, accessibility_id="cancel-message-button")
|
|
|
|
self.send_audio_message_button = Button(self.driver, accessibility_id="send-message-button")
|
|
|
|
self.play_pause_audio_message_button = Button(self.driver, accessibility_id="play-pause-audio-message-button")
|
|
|
|
self.audio_message_in_chat_timer = Text(self.driver,
|
2021-04-19 15:55:25 +00:00
|
|
|
xpath="//*[@content-desc='play-pause-audio-message-button']/../..//android.widget.TextView[1]")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.audio_message_recorded_time = Text(self.driver, accessibility_id="audio-message-recorded-time")
|
2019-04-10 09:48:14 +00:00
|
|
|
|
|
|
|
# Group chats
|
|
|
|
self.group_info = GroupInfoButton(self.driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.leave_chat_button = Button(self.driver, accessibility_id="leave-chat-button")
|
|
|
|
self.leave_button = Button(self.driver, translation_id="leave", uppercase=True)
|
|
|
|
self.join_chat_button = Button(self.driver, accessibility_id="join-chat-button")
|
|
|
|
self.decline_invitation_button = Button(self.driver, translation_id="group-chat-decline-invitation")
|
|
|
|
self.remove_user_button = Button(self.driver, accessibility_id="remove-from-chat")
|
|
|
|
self.make_admin_button = Button(self.driver, accessibility_id="make-admin")
|
|
|
|
self.edit_group_chat_name_button = Button(self.driver, accessibility_id="edit-button")
|
|
|
|
self.edit_group_chat_name_edit_box = EditBox(self.driver, accessibility_id="new-chat-name")
|
|
|
|
self.done_button = Button(self.driver, accessibility_id="done")
|
|
|
|
self.create_button = Button(self.driver, accessibility_id="create-group-chat-button")
|
|
|
|
## Group invites
|
|
|
|
self.group_invite_button = Button(self.driver, accessibility_id="invite-chat-button")
|
|
|
|
self.group_invite_link_text = Text(self.driver,
|
|
|
|
xpath="//*[@content-desc='invitation-link']/android.widget.TextView")
|
|
|
|
self.introduce_yourself_edit_box = EditBox(self.driver, accessibility_id="introduce-yourself-input")
|
|
|
|
self.request_membership_button = Button(self.driver, translation_id="request-membership")
|
|
|
|
self.group_membership_request_button = Button(self.driver, accessibility_id="invitation-requests-button")
|
|
|
|
self.accept_group_invitation_button = Button(self.driver, accessibility_id="accept-invitation-button")
|
|
|
|
self.decline_group_invitation_button = Button(self.driver, accessibility_id="decline-invitation-button")
|
|
|
|
self.retry_group_invite_button = Button(self.driver, accessibility_id="retry-button")
|
|
|
|
self.remove_group_invite_button = Button(self.driver, accessibility_id="remove-group-button")
|
2018-02-13 17:22:41 +00:00
|
|
|
|
2018-05-02 16:01:17 +00:00
|
|
|
# Contact's profile
|
2021-01-27 10:19:03 +00:00
|
|
|
self.contact_profile_picture = ProfilePictureElement(self.driver)
|
2023-03-08 10:31:42 +00:00
|
|
|
self.profile_send_message_button = ProfileSendMessageButton(self.driver)
|
|
|
|
self.profile_block_contact_button = ProfileBlockContactButton(self.driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.confirm_block_contact_button = Button(self.driver, accessibility_id="block-contact-confirm")
|
|
|
|
self.unblock_contact_button = UnblockContactButton(self.driver)
|
2022-06-27 13:34:07 +00:00
|
|
|
self.profile_mute_contact = Button(self.driver, accessibility_id="Mute-item-button")
|
|
|
|
self.profile_unmute_contact = Button(self.driver, accessibility_id="Unmute-item-button")
|
2023-03-08 10:31:42 +00:00
|
|
|
self.profile_add_to_contacts_button = Button(self.driver, accessibility_id="Add to contacts-item-button")
|
2023-02-24 19:05:30 +00:00
|
|
|
self.profile_remove_from_contacts = Button(self.driver, accessibility_id="Remove from contacts-item-button")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.profile_details = Button(self.driver, accessibility_id="share-button")
|
|
|
|
self.profile_nickname = Text(self.driver,
|
|
|
|
xpath="//*[@content-desc='profile-nickname-item']/android.widget.TextView[2]")
|
|
|
|
self.profile_nickname_button = Button(self.driver, accessibility_id="profile-nickname-item")
|
2021-07-20 08:34:10 +00:00
|
|
|
self.pinned_messages_button = PinnedMessagesOnProfileButton(self.driver)
|
2021-01-25 16:35:40 +00:00
|
|
|
self.nickname_input_field = EditBox(self.driver, accessibility_id="nickname-input")
|
|
|
|
self.remove_from_contacts = Button(self.driver, accessibility_id="Remove from contacts-item-button")
|
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
# Communities
|
|
|
|
self.create_community_button = Button(self.driver, translation_id="create-community")
|
|
|
|
self.community_name_edit_box = EditBox(self.driver, translation_id="name-your-community-placeholder")
|
|
|
|
self.community_description_edit_box = EditBox(self.driver, xpath='//android.widget.EditText[@text="%s"]' %
|
2021-11-18 15:16:48 +00:00
|
|
|
self.get_translation_by_key(
|
|
|
|
"give-a-short-description-community"))
|
|
|
|
self.set_community_image_button = Button(self.driver, translation_id='community-thumbnail-image',
|
|
|
|
suffix='/following-sibling::android.view.ViewGroup')
|
2021-07-08 08:32:08 +00:00
|
|
|
self.confirm_create_in_community_button = Button(self.driver, translation_id="create")
|
2023-03-09 05:35:08 +00:00
|
|
|
self.mentions_list = BaseElement(self.driver, accessibility_id="mentions-list")
|
2021-07-08 08:32:08 +00:00
|
|
|
|
2022-11-21 04:49:53 +00:00
|
|
|
# New UI
|
|
|
|
self.pinned_messages_count = Button(self.driver,
|
2023-01-18 13:06:05 +00:00
|
|
|
xpath="//*[@content-desc='pins-count']//android.widget.TextView")
|
2022-11-21 04:49:53 +00:00
|
|
|
self.pinned_messages_list = PinnedMessagesList(self.driver)
|
2023-01-24 18:26:00 +00:00
|
|
|
self.pin_limit_popover = BaseElement(self.driver, translation_id="pin-limit-reached")
|
|
|
|
self.view_pinned_messages_button = Button(self.driver, accessibility_id="pinned-banner")
|
2022-11-21 04:49:53 +00:00
|
|
|
|
2021-05-03 14:08:29 +00:00
|
|
|
def get_outgoing_transaction(self, account=None, transaction_value=None) -> object:
|
2021-02-04 12:51:01 +00:00
|
|
|
if account is None:
|
|
|
|
account = self.status_account_name
|
2021-05-03 14:08:29 +00:00
|
|
|
return OutgoingTransaction(self.driver, account, transaction_value)
|
2021-02-04 12:51:01 +00:00
|
|
|
|
2021-05-03 14:08:29 +00:00
|
|
|
def get_incoming_transaction(self, account=None, transaction_value=None) -> object:
|
2021-02-04 12:51:01 +00:00
|
|
|
if account is None:
|
|
|
|
account = self.status_account_name
|
2021-05-03 14:08:29 +00:00
|
|
|
return IncomingTransaction(self.driver, account, transaction_value)
|
2021-02-04 12:51:01 +00:00
|
|
|
|
2021-05-03 14:08:29 +00:00
|
|
|
def get_preview_message_by_text(self, text=None) -> object:
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info('Getting preview message for link: %s' % text)
|
2021-02-23 14:38:17 +00:00
|
|
|
return PreviewMessage(self.driver, text)
|
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
def get_community_link_preview_by_text(self, text=None) -> object:
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info('Getting community preview message for link: %s' % text)
|
2021-07-08 08:32:08 +00:00
|
|
|
return CommunityLinkPreviewMessage(self.driver, text)
|
2021-02-04 12:51:01 +00:00
|
|
|
|
2018-07-03 12:40:44 +00:00
|
|
|
def delete_chat(self):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Delete chat via options")
|
2018-03-15 16:07:25 +00:00
|
|
|
self.chat_options.click()
|
|
|
|
self.delete_chat_button.click()
|
|
|
|
self.delete_button.click()
|
2018-04-26 06:22:11 +00:00
|
|
|
|
2020-04-10 10:25:46 +00:00
|
|
|
def leave_chat(self):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Leave chat via options")
|
2020-04-10 10:25:46 +00:00
|
|
|
self.chat_options.click()
|
|
|
|
self.leave_chat_button.click()
|
|
|
|
self.leave_button.click()
|
|
|
|
|
2018-06-30 12:17:38 +00:00
|
|
|
def clear_history(self):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Clear chat history via options")
|
2018-06-30 12:17:38 +00:00
|
|
|
self.chat_options.click()
|
|
|
|
self.clear_history_button.click()
|
|
|
|
self.clear_button.click()
|
|
|
|
|
2020-04-10 10:25:46 +00:00
|
|
|
def leave_chat_via_group_info(self):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Leave group chat via group info")
|
2019-04-10 09:48:14 +00:00
|
|
|
self.chat_options.click()
|
|
|
|
self.group_info.click()
|
2020-04-10 10:25:46 +00:00
|
|
|
self.leave_chat_button.click()
|
|
|
|
self.leave_button.click()
|
|
|
|
|
|
|
|
def rename_chat_via_group_info(self, new_chat_name):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Rename group chat to: %s" % new_chat_name)
|
2020-04-10 10:25:46 +00:00
|
|
|
self.chat_options.click()
|
|
|
|
self.group_info.click()
|
|
|
|
self.edit_group_chat_name_button.click()
|
|
|
|
self.edit_group_chat_name_edit_box.set_value(new_chat_name)
|
|
|
|
self.done_button.click()
|
2019-04-10 09:48:14 +00:00
|
|
|
|
2020-09-09 15:06:07 +00:00
|
|
|
def get_group_invite_via_group_info(self):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Copy group invite link")
|
2020-09-09 15:06:07 +00:00
|
|
|
self.chat_options.click()
|
|
|
|
self.group_info.click()
|
|
|
|
self.group_invite_button.click()
|
|
|
|
return self.group_invite_link_text.text
|
|
|
|
|
|
|
|
def request_membership_for_group_chat(self, intro_message):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Requesting membership to group chat")
|
2020-09-09 15:06:07 +00:00
|
|
|
self.introduce_yourself_edit_box.set_value(intro_message)
|
|
|
|
self.request_membership_button.click_until_presence_of_element(self.element_by_text('Request pending…'))
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
def get_username_checkbox(self, username: str):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Getting %s checkbox" % username)
|
2021-01-25 16:35:40 +00:00
|
|
|
return UsernameCheckbox(self.driver, username)
|
|
|
|
|
2020-09-09 15:06:07 +00:00
|
|
|
def accept_membership_for_group_chat_via_chat_view(self, username, accept=True):
|
2021-01-25 16:35:40 +00:00
|
|
|
info = "%s membership to group chat" % username
|
2021-11-18 15:16:48 +00:00
|
|
|
self.driver.info("Accept %s" % info) if accept else self.driver.info("Decline %s" % info)
|
2020-09-09 15:06:07 +00:00
|
|
|
self.group_membership_request_button.click()
|
|
|
|
self.element_by_text(username).click()
|
|
|
|
self.accept_group_invitation_button.click() if accept else self.decline_group_invitation_button.click()
|
|
|
|
|
2018-12-05 14:11:50 +00:00
|
|
|
def add_members_to_group_chat(self, user_names_to_add: list):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Add %s to group chat" % ', '.join(map(str, user_names_to_add)))
|
2018-12-05 14:11:50 +00:00
|
|
|
self.chat_options.click()
|
|
|
|
group_info_view = self.group_info.click()
|
2021-01-25 16:35:40 +00:00
|
|
|
group_info_view.add_members.click()
|
2018-12-05 14:11:50 +00:00
|
|
|
for user_name in user_names_to_add:
|
2021-01-25 16:35:40 +00:00
|
|
|
user_contact = self.get_username_checkbox(user_name)
|
2018-12-05 14:11:50 +00:00
|
|
|
user_contact.scroll_to_element()
|
|
|
|
user_contact.click()
|
2021-01-25 16:35:40 +00:00
|
|
|
self.add_button.click()
|
2018-12-05 14:11:50 +00:00
|
|
|
|
2019-03-26 09:23:01 +00:00
|
|
|
def get_user_options(self, username: str):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Get user options for: '%s'" % username)
|
2019-03-26 09:23:01 +00:00
|
|
|
self.chat_options.click()
|
|
|
|
group_info_view = self.group_info.click()
|
|
|
|
group_info_view.get_username_options(username).click()
|
|
|
|
return self
|
|
|
|
|
2018-05-16 19:59:36 +00:00
|
|
|
def chat_element_by_text(self, text):
|
2021-10-29 09:11:39 +00:00
|
|
|
chat_element = ChatElementByText(self.driver, text)
|
|
|
|
self.driver.info("Looking for a message by text: %s" % chat_element.exclude_emoji(text))
|
|
|
|
return chat_element
|
2018-06-21 16:40:27 +00:00
|
|
|
|
2023-06-08 02:57:38 +00:00
|
|
|
def verify_message_is_under_today_text(self, text, errors, timeout=10):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Verifying that '%s' is under today" % text)
|
2018-06-21 16:40:27 +00:00
|
|
|
message_element = self.chat_element_by_text(text)
|
2023-06-08 02:57:38 +00:00
|
|
|
message_element.wait_for_visibility_of_element(timeout)
|
2018-06-21 16:40:27 +00:00
|
|
|
message_location = message_element.find_element().location['y']
|
|
|
|
today_text_element = self.element_by_text('Today').find_element()
|
|
|
|
today_location = today_text_element.location['y']
|
|
|
|
today_height = today_text_element.size['height']
|
|
|
|
if message_location < today_location + today_height:
|
2018-07-03 18:50:18 +00:00
|
|
|
errors.append("Message '%s' is not under 'Today' text" % text)
|
2018-11-21 10:44:30 +00:00
|
|
|
|
2022-02-23 14:19:18 +00:00
|
|
|
def send_message(self, message: str = 'test message', wait_chat_input_sec=5):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Sending message '%s'" % BaseElement(self.driver).exclude_emoji(message))
|
2022-02-23 14:19:18 +00:00
|
|
|
self.chat_message_input.wait_for_element(wait_chat_input_sec)
|
2018-11-21 10:44:30 +00:00
|
|
|
self.chat_message_input.send_keys(message)
|
|
|
|
self.send_message_button.click()
|
|
|
|
|
2022-11-21 04:49:53 +00:00
|
|
|
def send_contact_request(self, message: str = 'Contact request message', wait_chat_input_sec=5):
|
2022-07-02 07:50:03 +00:00
|
|
|
self.driver.info("Sending contact request message '%s'" % BaseElement(self.driver).exclude_emoji(message))
|
|
|
|
self.contact_request_button.wait_and_click()
|
|
|
|
self.chat_message_input.wait_for_element(wait_chat_input_sec)
|
|
|
|
self.chat_message_input.send_keys(message)
|
|
|
|
self.send_contact_request_button.click()
|
|
|
|
|
2021-07-20 08:34:10 +00:00
|
|
|
def pin_message(self, message, action="pin"):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Looking for message '%s' pin" % message)
|
2023-02-24 19:05:30 +00:00
|
|
|
element = self.element_by_translation_id(action)
|
|
|
|
self.chat_element_by_text(message).long_press_until_element_is_shown(element)
|
|
|
|
element.click_until_absense_of_element(element)
|
2021-07-20 08:34:10 +00:00
|
|
|
|
2021-07-07 08:02:54 +00:00
|
|
|
def edit_message_in_chat(self, message_to_edit, message_to_update):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Looking for message '%s' to edit it" % message_to_edit)
|
2023-02-24 19:05:30 +00:00
|
|
|
element = self.element_by_translation_id("edit-message")
|
2023-07-12 09:21:39 +00:00
|
|
|
self.chat_view_element_starts_with_text(message_to_edit).long_press_until_element_is_shown(element)
|
2023-02-24 19:05:30 +00:00
|
|
|
element.click()
|
2021-07-07 08:02:54 +00:00
|
|
|
self.chat_message_input.clear()
|
|
|
|
self.chat_message_input.send_keys(message_to_update)
|
|
|
|
self.send_message_button.click()
|
|
|
|
|
2022-11-03 11:26:53 +00:00
|
|
|
def delete_message_in_chat(self, message, everyone=True):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Looking for message '%s' to delete it" % message)
|
2023-07-12 09:21:39 +00:00
|
|
|
self.chat_view_element_starts_with_text(message).long_press_element()
|
2022-11-21 04:49:53 +00:00
|
|
|
for_everyone, for_me = self.element_by_translation_id("delete-for-everyone"), self.element_by_translation_id(
|
|
|
|
"delete-for-me")
|
2022-11-03 11:26:53 +00:00
|
|
|
for_everyone.click() if everyone else for_me.click()
|
2021-09-02 16:00:55 +00:00
|
|
|
|
2020-09-16 14:34:55 +00:00
|
|
|
def copy_message_text(self, message_text):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Copying '%s' message via long press" % message_text)
|
2020-09-16 14:34:55 +00:00
|
|
|
self.element_by_text_part(message_text).long_press_element()
|
2022-12-13 18:07:34 +00:00
|
|
|
self.element_by_translation_id("copy-text").click()
|
2020-09-16 14:34:55 +00:00
|
|
|
|
2023-07-12 09:21:39 +00:00
|
|
|
def quote_message(self, message: str):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Quoting '%s' message" % message)
|
2023-07-12 09:21:39 +00:00
|
|
|
self.chat_view_element_starts_with_text(message).long_press_until_element_is_shown(self.reply_message_button)
|
2019-11-08 18:24:55 +00:00
|
|
|
self.reply_message_button.click()
|
|
|
|
|
2021-11-18 15:16:48 +00:00
|
|
|
def set_reaction(self, message: str, emoji: str = 'thumbs-up', emoji_message=False):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Setting '%s' reaction" % emoji)
|
2021-07-23 08:02:42 +00:00
|
|
|
# Audio message is obvious should be tapped not on audio-scroll-line
|
|
|
|
# so we tap on its below element as exception here (not the case for link/tag message!)
|
2023-06-02 15:42:06 +00:00
|
|
|
element = Button(self.driver, accessibility_id='reaction-%s' % emoji)
|
2021-07-23 08:02:42 +00:00
|
|
|
if message == 'audio':
|
|
|
|
self.audio_message_in_chat_timer.long_press_element()
|
|
|
|
else:
|
|
|
|
if not emoji_message:
|
2023-02-24 19:05:30 +00:00
|
|
|
self.chat_element_by_text(message).long_press_until_element_is_shown(element)
|
2021-07-23 08:02:42 +00:00
|
|
|
else:
|
2023-02-24 19:05:30 +00:00
|
|
|
self.element_by_text_part(message).long_press_until_element_is_shown(element)
|
2022-10-26 15:14:25 +00:00
|
|
|
# old UI
|
|
|
|
# element = Button(self.driver, accessibility_id='pick-emoji-%s' % key)
|
2020-08-14 16:05:41 +00:00
|
|
|
element.click()
|
|
|
|
element.wait_for_invisibility_of_element()
|
|
|
|
|
2023-01-09 13:46:24 +00:00
|
|
|
def add_remove_same_reaction(self, message: str, emoji: str = 'thumbs-up'):
|
|
|
|
self.driver.info("Adding one more '%s' reaction or removing an added one" % emoji)
|
|
|
|
key = emojis[emoji]
|
|
|
|
element = Button(self.driver, accessibility_id='emoji-reaction-%s' % key)
|
|
|
|
element.click()
|
|
|
|
|
2021-11-18 15:16:48 +00:00
|
|
|
def view_profile_long_press(self, message=str):
|
2020-05-08 13:36:05 +00:00
|
|
|
self.chat_element_by_text(message).long_press_element()
|
2022-02-23 14:19:18 +00:00
|
|
|
self.view_profile_by_avatar_button.wait_and_click()
|
2023-03-08 10:31:42 +00:00
|
|
|
self.profile_block_contact_button.wait_for_visibility_of_element(5)
|
2020-05-08 13:36:05 +00:00
|
|
|
|
2021-11-18 15:16:48 +00:00
|
|
|
def wait_ens_name_resolved_in_chat(self, message=str, username_value=str):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Waiting ENS name '%s' is resolved in chat" % username_value)
|
2020-12-02 13:18:36 +00:00
|
|
|
counter = 0
|
|
|
|
while True:
|
|
|
|
if counter >= 120:
|
|
|
|
self.driver.fail('Username not updated to %s %s' % (60, username_value))
|
|
|
|
elif not (self.chat_element_by_text(message).username.text == username_value):
|
|
|
|
counter += 5
|
|
|
|
time.sleep(5)
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
2018-11-21 10:44:30 +00:00
|
|
|
def move_to_messages_by_time_marker(self, marker='Today'):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Moving to messages by time marker: '%s'" % marker)
|
2021-11-18 15:16:48 +00:00
|
|
|
Button(self.driver, xpath="//*[@text='%s'']" % marker).scroll_to_element(depth=50, direction='up')
|
2019-09-05 02:32:33 +00:00
|
|
|
|
2022-07-20 14:03:42 +00:00
|
|
|
def install_sticker_pack_by_name(self, pack_name='HCPP20'):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("## Installing '%s' stickerpack" % pack_name, device=False)
|
2022-04-05 15:22:23 +00:00
|
|
|
self.chat_message_input.click()
|
2021-09-17 16:20:12 +00:00
|
|
|
self.show_stickers_button.click()
|
|
|
|
self.get_stickers.click()
|
2023-06-08 02:57:38 +00:00
|
|
|
element = Button(
|
|
|
|
self.driver,
|
|
|
|
xpath="//*[@content-desc='sticker-pack-name'][@text='%s']/..//*[@content-desc='sticker-pack-price']"
|
|
|
|
% pack_name)
|
2022-05-10 10:01:50 +00:00
|
|
|
element.scroll_to_element(depth=21)
|
2019-09-05 02:32:33 +00:00
|
|
|
element.click()
|
|
|
|
element.wait_for_invisibility_of_element()
|
2022-05-30 11:49:30 +00:00
|
|
|
self.navigate_up_button.click()
|
2021-09-17 16:20:12 +00:00
|
|
|
time.sleep(2)
|
|
|
|
self.swipe_left()
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("## Stickerpack is installed successfully!", device=False)
|
2019-10-23 17:17:54 +00:00
|
|
|
|
2021-04-30 09:31:39 +00:00
|
|
|
def scroll_to_start_of_history(self, depth=20):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info('Scrolling th the start of chat history')
|
2021-04-30 09:31:39 +00:00
|
|
|
for _ in range(depth):
|
|
|
|
try:
|
|
|
|
return self.history_start_icon.find_element()
|
|
|
|
except NoSuchElementException:
|
|
|
|
size = self.driver.get_window_size()
|
2021-04-30 14:11:52 +00:00
|
|
|
self.driver.swipe(500, size["height"] * 0.25, 500, size["height"] * 0.8)
|
2021-04-30 09:31:39 +00:00
|
|
|
else:
|
|
|
|
raise Exception('Start of chat history is not reached!')
|
|
|
|
|
2021-03-04 09:35:48 +00:00
|
|
|
def user_profile_image_in_mentions_list(self, username):
|
|
|
|
return Button(self.driver, xpath="//*[@content-desc='suggestions-list']//*[@text='%s']/"
|
|
|
|
"..//*[@content-desc='member-photo']" % username)
|
|
|
|
|
2020-10-20 15:34:52 +00:00
|
|
|
def search_user_in_mention_suggestion_list(self, username):
|
2021-01-25 16:35:40 +00:00
|
|
|
return Button(self.driver, xpath="//*[@content-desc='suggestions-list']//*[@text='%s']" % username)
|
2020-10-20 15:34:52 +00:00
|
|
|
|
2021-11-18 15:16:48 +00:00
|
|
|
def select_mention_from_suggestion_list(self, username_in_list, typed_search_pattern=''):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Selecting '%s' from suggestion list by '%s'" % (username_in_list, typed_search_pattern))
|
2020-10-20 15:34:52 +00:00
|
|
|
self.chat_message_input.set_value('@' + typed_search_pattern)
|
|
|
|
self.chat_message_input.click()
|
2020-12-02 13:18:36 +00:00
|
|
|
self.search_user_in_mention_suggestion_list(username_in_list).wait_for_visibility_of_element(10).click()
|
2020-10-20 15:34:52 +00:00
|
|
|
|
2020-09-04 13:26:14 +00:00
|
|
|
def record_audio_message(self, message_length_in_seconds=5):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Recording audiomessage %ss" % message_length_in_seconds)
|
2020-09-04 13:26:14 +00:00
|
|
|
self.audio_message_button.click()
|
|
|
|
self.allow_button.click()
|
|
|
|
self.record_audio_button.click()
|
|
|
|
sleep(message_length_in_seconds)
|
|
|
|
|
|
|
|
def play_audio_message(self, listen_time=5):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Playing audiomessage during %ss" % listen_time)
|
2020-09-04 13:26:14 +00:00
|
|
|
self.play_pause_audio_message_button.click()
|
|
|
|
sleep(listen_time)
|
|
|
|
self.play_pause_audio_message_button.click()
|
|
|
|
|
2019-10-23 17:17:54 +00:00
|
|
|
def block_contact(self):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Block contact from other user profile")
|
2023-03-08 10:31:42 +00:00
|
|
|
self.profile_block_contact_button.click()
|
2021-01-25 16:35:40 +00:00
|
|
|
self.confirm_block_contact_button.click()
|
2020-01-03 15:24:05 +00:00
|
|
|
|
2021-09-24 10:35:19 +00:00
|
|
|
def open_user_profile_from_public_chat(self, message):
|
|
|
|
chat_element = self.chat_element_by_text(message)
|
|
|
|
chat_element.find_element()
|
|
|
|
chat_element.member_photo.click()
|
|
|
|
|
2022-04-12 09:22:26 +00:00
|
|
|
def open_user_profile_from_1_1_chat(self):
|
|
|
|
self.chat_options.click()
|
|
|
|
self.view_profile_button.click()
|
|
|
|
|
2021-09-24 10:35:19 +00:00
|
|
|
def set_nickname(self, nickname, close_profile=True):
|
2021-10-25 16:05:22 +00:00
|
|
|
self.driver.info("Setting nickname:%s" % nickname)
|
2020-10-28 08:46:17 +00:00
|
|
|
self.profile_nickname_button.click()
|
2020-09-15 13:40:39 +00:00
|
|
|
self.nickname_input_field.send_keys(nickname)
|
|
|
|
self.element_by_text('Done').click()
|
2021-09-24 10:35:19 +00:00
|
|
|
if close_profile:
|
|
|
|
self.close_button.click()
|
2020-09-15 13:40:39 +00:00
|
|
|
|
2021-02-19 13:46:29 +00:00
|
|
|
def convert_device_time_to_chat_timestamp(self) -> list:
|
2020-01-03 15:24:05 +00:00
|
|
|
sent_time_object = dateutil.parser.parse(self.driver.device_time)
|
2021-11-18 15:16:48 +00:00
|
|
|
timestamp = datetime.strptime("%s:%s" % (sent_time_object.hour, sent_time_object.minute), '%H:%M').strftime(
|
|
|
|
"%I:%M %p")
|
2021-02-19 13:46:29 +00:00
|
|
|
timestamp_obj = datetime.strptime(timestamp, '%I:%M %p')
|
2021-11-18 15:16:48 +00:00
|
|
|
possible_timestamps_obj = [timestamp_obj + timedelta(0, 0, 0, 0, 1), timestamp_obj,
|
2023-06-08 02:57:38 +00:00
|
|
|
timestamp_obj - timedelta(0, 0, 0, 0, 1), timestamp_obj - timedelta(0, 0, 0, 0, 2)]
|
2021-11-18 15:16:48 +00:00
|
|
|
timestamps = list(map(lambda x: x.strftime("%I:%M %p"), possible_timestamps_obj))
|
2021-02-19 13:46:29 +00:00
|
|
|
final_timestamps = [t[1:] if t[0] == '0' else t for t in timestamps]
|
|
|
|
return final_timestamps
|
|
|
|
|
2021-05-03 14:08:29 +00:00
|
|
|
def get_transaction_message_by_asset(self, transaction_value, incoming=True) -> object:
|
|
|
|
if incoming:
|
|
|
|
transaction_message = self.get_incoming_transaction(account=None, transaction_value=transaction_value)
|
|
|
|
else:
|
|
|
|
transaction_message = self.get_outgoing_transaction(account=None, transaction_value=transaction_value)
|
|
|
|
return transaction_message
|
|
|
|
|
2021-07-08 08:32:08 +00:00
|
|
|
def get_community_by_name(self, community_name: str):
|
2023-03-09 05:35:08 +00:00
|
|
|
community_button = Button(
|
|
|
|
self.driver,
|
|
|
|
xpath="//*[@content-desc='community-name-text'][starts-with(@text,'%s')]/.." % community_name
|
|
|
|
)
|
2021-07-08 08:32:08 +00:00
|
|
|
community_button.click()
|
|
|
|
return CommunityView(self.driver)
|
|
|
|
|
2023-06-29 12:12:33 +00:00
|
|
|
def user_list_element_by_name(self, user_name: str):
|
|
|
|
return BaseElement(self.driver, xpath="//*[@content-desc='user-list']//*[@text='%s']" % user_name)
|
|
|
|
|
2023-03-09 05:35:08 +00:00
|
|
|
def mention_user(self, user_name: str):
|
|
|
|
self.driver.info("Mention user %s in the chat" % user_name)
|
|
|
|
gboard = self.driver.available_ime_engines[0]
|
|
|
|
self.driver.activate_ime_engine(gboard) # workaround to get mentions list expanded
|
|
|
|
self.chat_message_input.click_inside()
|
|
|
|
self.chat_message_input.send_keys("@")
|
|
|
|
try:
|
2023-04-28 10:15:32 +00:00
|
|
|
self.mentions_list.wait_for_element()
|
2023-06-29 12:12:33 +00:00
|
|
|
self.user_list_element_by_name(user_name).click()
|
2023-03-09 05:35:08 +00:00
|
|
|
except TimeoutException:
|
|
|
|
self.driver.fail("Mentions list is not shown")
|
|
|
|
|
2023-05-19 16:03:48 +00:00
|
|
|
def get_image_by_index(self, index=0):
|
|
|
|
return Button(self.driver, accessibility_id="image-%s" % index)
|
|
|
|
|
|
|
|
def send_images_with_description(self, description, indexes=None):
|
|
|
|
if indexes is None:
|
|
|
|
indexes = [0]
|
|
|
|
self.show_images_button.click()
|
|
|
|
self.allow_button.click_if_shown()
|
|
|
|
[self.get_image_by_index(i).click() for i in indexes]
|
|
|
|
self.images_confirm_selection_button.click()
|
2023-06-13 03:24:21 +00:00
|
|
|
self.chat_message_input.send_keys(description)
|
2023-05-19 16:03:48 +00:00
|
|
|
self.send_message_button.click()
|
|
|
|
|
2021-02-01 16:09:04 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_resolved_chat_key(username, chat_key):
|
|
|
|
return '%s • %s…%s' % (username, chat_key[:6], chat_key[-4:])
|
|
|
|
|
2020-04-10 10:25:46 +00:00
|
|
|
# Group chat system messages
|
|
|
|
@staticmethod
|
|
|
|
def leave_system_message(username):
|
|
|
|
return "%s left the group" % username
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def has_been_made_admin_system_message(admin, new_admin):
|
|
|
|
return "%s has made %s admin" % (admin, new_admin)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_system_message(admin, chat_name):
|
|
|
|
return '%s created the group %s' % (admin, chat_name)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def invite_system_message(admin, invited_user):
|
|
|
|
return '%s has invited %s' % (admin, invited_user)
|
|
|
|
|
2022-06-09 13:54:45 +00:00
|
|
|
@staticmethod
|
|
|
|
def has_added_system_message(admin, invited_user):
|
|
|
|
return '%s has added %s' % (admin, invited_user)
|
|
|
|
|
2021-02-04 12:51:01 +00:00
|
|
|
@staticmethod
|
|
|
|
def invited_to_join_system_message(username, chat_name):
|
|
|
|
return '%s invited you to join the group %s' % (username, chat_name)
|
|
|
|
|
2020-04-10 10:25:46 +00:00
|
|
|
@staticmethod
|
|
|
|
def join_system_message(username):
|
|
|
|
return '%s joined the group' % username
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def changed_group_name_system_message(admin, chat_name):
|
2021-10-15 10:26:36 +00:00
|
|
|
return "%s changed the group's name to %s" % (admin, chat_name)
|
|
|
|
|
|
|
|
### Push notifications
|
|
|
|
@staticmethod
|
|
|
|
def pn_invited_to_group_chat(admin, chat_name):
|
|
|
|
return '%s invited you to %s' % (admin, chat_name)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def pn_wants_you_to_join_to_group_chat(admin, chat_name):
|
2021-11-18 15:16:48 +00:00
|
|
|
return '%s wants you to join group %s' % (admin, chat_name)
|
2023-06-29 12:12:33 +00:00
|
|
|
|
|
|
|
def authors_for_reaction(self, emoji: str):
|
|
|
|
return Button(self.driver, accessibility_id='authors-for-reaction-%s' % emojis[emoji])
|
2023-07-12 09:21:39 +00:00
|
|
|
|
|
|
|
def chat_view_element_starts_with_text(self, text: str):
|
|
|
|
return BaseElement(self.driver,
|
|
|
|
xpath="//*[@content-desc=':chat-floating-screen']//*[starts-with(@text,'%s')]" % text)
|