Skip to content

Commit

Permalink
e2e: fixes navigation, long press and so on
Browse files Browse the repository at this point in the history
  • Loading branch information
yevh-berdnyk committed Sep 1, 2023
1 parent f3f85f9 commit 5647bb4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 24 deletions.
7 changes: 4 additions & 3 deletions test/appium/tests/critical/chats/test_1_1_public_chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,13 +1153,13 @@ def test_1_1_chat_push_emoji(self):
chat_2 = self.device_2.click_upon_push_notification_by_text(message)

self.device_2.just_fyi("Send emoji message to Device 1 while it's on background")
self.device_1.put_app_to_background()
self.device_1.open_notification_bar()
emoji_message = random.choice(list(emoji.EMOJI_UNICODE))
emoji_unicode = emoji.EMOJI_UNICODE[emoji_message]
chat_2.send_message(emoji.emojize(emoji_message))

self.device_1.just_fyi("Device 1 checks PN with emoji")
self.device_1.put_app_to_background()
self.device_1.open_notification_bar()
if not self.device_1.element_by_text_part(emoji_unicode).is_element_displayed(60):
self.device_1.click_system_back_button()
self.device_1.status_in_background_button.click()
Expand Down Expand Up @@ -1312,8 +1312,9 @@ def test_1_1_chat_text_message_delete_push_disappear(self):
self.device_2.just_fyi("Send one more message and check that PN will be deleted with message deletion")
message_to_delete = 'DELETE ME'
self.home_1.put_app_to_background()
self.chat_2.send_message(message_to_delete)
self.home_1.open_notification_bar()
self.chat_2.send_message(message_to_delete)
self.chat_2.chat_element_by_text(message_to_delete).wait_for_sent_state()
if not self.home_1.get_pn(message_to_delete):
self.home_1.click_system_back_button()
self.home_1.status_in_background_button.click()
Expand Down
2 changes: 1 addition & 1 deletion test/appium/tests/critical/chats/test_group_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ def test_group_chat_join_send_text_messages_push(self):
message_to_admin = self.message_to_admin
[self.homes[i].navigate_back_to_home_view() for i in range(3)]
self.homes[1].get_chat(self.chat_name).click()
self.chats[0].open_notification_bar()

self.chats[1].send_message(message_to_admin)

self.chats[0].just_fyi('Check that PN is received and after tap you are redirected to group chat')
self.chats[0].open_notification_bar()
pn = self.homes[0].get_pn(message_to_admin)
if pn:
pn.click()
Expand Down
11 changes: 7 additions & 4 deletions test/appium/tests/critical/test_public_chat_browsing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import random
import time
from datetime import timedelta

import emoji
Expand Down Expand Up @@ -337,7 +338,7 @@ def test_community_discovery(self):
for element, template in element_templates.items():
if element.is_element_differs_from_template(template):
element.save_new_screenshot_of_element('%s_different.png' % element.name)
self.errors.append("%s is different from expected %s!" % (element.name, template))
self.errors.append("Element %s is different from expected template %s!" % (element.locator, template))
self.errors.verify_no_errors()

@marks.testrail_id(702846)
Expand All @@ -348,6 +349,7 @@ def test_community_navigate_to_channel_when_relaunch(self):
self.home.get_to_community_channel_from_home(self.community_name)

self.channel.send_message(text_message)
self.channel.chat_element_by_text(text_message).wait_for_visibility_of_element()
self.channel.reopen_app()
if not self.channel.chat_element_by_text(text_message).is_element_displayed(30):
self.drivers[0].fail("Not navigated to channel view after reopening app")
Expand Down Expand Up @@ -577,6 +579,7 @@ def prepare_devices(self):
self.chat_2.chat_element_by_text(self.community_name).view_community_button.click()
self.community_2.join_community()
self.channel_2 = self.community_2.get_channel(self.channel_name).click()
self.channel_2.chat_message_input.wait_for_visibility_of_element(20)

@marks.testrail_id(702838)
def test_community_message_send_check_timestamps_sender_username(self):
Expand Down Expand Up @@ -1010,6 +1013,7 @@ def test_community_mark_all_messages_as_read(self):
self.errors.append("New messages counter is not shown in community channel element")
self.community_1.click_system_back_button()
mark_as_read_button = self.community_1.mark_all_messages_as_read_button
self.home_1.community_floating_screen.wait_for_invisibility_of_element()
community_1_element.long_press_until_element_is_shown(mark_as_read_button)
mark_as_read_button.click()
if community_1_element.new_messages_grey_dot.is_element_displayed():
Expand Down Expand Up @@ -1065,18 +1069,17 @@ def prepare_devices(self):
self.channel_2 = self.community_2.get_channel(self.channel_name).click()

@marks.testrail_id(702786)
@marks.xfail(
reason="Issue with username in PN, issue #6 in https://github.com/status-im/status-mobile/issues/15500")
@marks.xfail(reason="Issue with username in PN, issue #6 in 15500")
def test_community_mentions_push_notification(self):
self.home_1.navigate_back_to_home_view()
self.device_1.open_notification_bar()

self.device_2.just_fyi("Invited member sends a message with a mention")
self.channel_2.send_message("hi")
self.channel_2.mention_user(self.username_1)
self.channel_2.send_message_button.click()

self.device_1.just_fyi("Admin gets push notification with the mention and tap it")
self.device_1.open_notification_bar()
message_received = False
if self.home_1.get_pn(self.username_1):
self.device_1.click_upon_push_notification_by_text(self.username_1)
Expand Down
4 changes: 2 additions & 2 deletions test/appium/views/base_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ def click_system_back_button(self, times=1):

def navigate_back_to_home_view(self, attempts=3):
counter = 0
while self.chat_floating_screen.is_element_displayed(2) \
or self.community_floating_screen.is_element_displayed(2):
while not self.chat_floating_screen.is_element_disappeared(2) \
or not self.community_floating_screen.is_element_disappeared(2):
self.driver.press_keycode(4)
element = self.chats_tab
while not element.is_element_displayed(1) and counter <= attempts:
Expand Down
34 changes: 22 additions & 12 deletions test/appium/views/chat_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import dateutil.parser
from appium.webdriver.common.touch_action import TouchAction
from selenium.common.exceptions import NoSuchElementException, TimeoutException, StaleElementReferenceException
from selenium.common.exceptions import NoSuchElementException, TimeoutException, StaleElementReferenceException, \
InvalidElementStateException

from tests import emojis, common_password
from views.base_element import Button, EditBox, Text, BaseElement, SilentButton
Expand Down Expand Up @@ -334,9 +335,10 @@ def click(self):


class UsernameCheckbox(Button):
def __init__(self, driver, username):
def __init__(self, driver, username, state_on):
self.username = username
super().__init__(driver, xpath="//*[@text='%s']/..//*[@content-desc='checkbox-off']" % username)
super().__init__(driver, xpath="//*[@text='%s']/..//*[@content-desc='checkbox-%s']" % (
username, 'on' if state_on else 'off'))

def click(self):
try:
Expand Down Expand Up @@ -488,6 +490,7 @@ def share_community(self, community_name, user_names_to_share):
self.driver.info("Share to %s community" % ', '.join(map(str, user_names_to_share)))
self.jump_to_communities_home()
home = self.get_home_view()
home.communities_tab.click()
community_element = home.get_chat(community_name, community=True)
# community_element.long_press_until_element_is_shown(self.view_members_button)
community_element.long_press_until_element_is_shown(self.share_community_button)
Expand Down Expand Up @@ -941,9 +944,9 @@ def request_membership_for_group_chat(self, intro_message):
self.introduce_yourself_edit_box.set_value(intro_message)
self.request_membership_button.click_until_presence_of_element(self.element_by_text('Request pending…'))

def get_username_checkbox(self, username: str):
def get_username_checkbox(self, username: str, state_on=False):
self.driver.info("Getting %s checkbox" % username)
return UsernameCheckbox(self.driver, username)
return UsernameCheckbox(self.driver, username, state_on)

def accept_membership_for_group_chat_via_chat_view(self, username, accept=True):
info = "%s membership to group chat" % username
Expand Down Expand Up @@ -993,13 +996,18 @@ def send_message(self, message: str = 'test message', wait_chat_input_sec=5):
try:
self.chat_message_input.send_keys(message)
break
except StaleElementReferenceException:
except (StaleElementReferenceException, InvalidElementStateException):
time.sleep(1)
except Exception as e:
raise e
else:
raise StaleElementReferenceException(msg="Can't send keys to chat message input, loading")
self.send_message_button.click()
try:
self.send_message_button.click()
except NoSuchElementException:
self.chat_message_input.clear()
self.chat_message_input.send_keys(message)
self.send_message_button.click()

def send_contact_request(self, message: str = 'Contact request message', wait_chat_input_sec=5):
self.driver.info("Sending contact request message '%s'" % BaseElement(self.driver).exclude_emoji(message))
Expand All @@ -1017,18 +1025,20 @@ def pin_message(self, message, action="pin"):
def edit_message_in_chat(self, message_to_edit, message_to_update):
self.driver.info("Looking for message '%s' to edit it" % message_to_edit)
element = self.element_by_translation_id("edit-message")
self.chat_view_element_starts_with_text(message_to_edit).long_press_until_element_is_shown(element)
self.chat_element_by_text(message_to_edit).message_body.long_press_until_element_is_shown(element)
element.click()
self.chat_message_input.clear()
self.chat_message_input.send_keys(message_to_update)
self.send_message_button.click()

def delete_message_in_chat(self, message, everyone=True):
self.driver.info("Looking for message '%s' to delete it" % message)
self.chat_view_element_starts_with_text(message).long_press_element()
for_everyone, for_me = self.element_by_translation_id("delete-for-everyone"), self.element_by_translation_id(
"delete-for-me")
for_everyone.click() if everyone else for_me.click()
if everyone:
delete_button = self.element_by_translation_id("delete-for-everyone")
else:
delete_button = self.element_by_translation_id("delete-for-me")
self.chat_element_by_text(message).message_body.long_press_until_element_is_shown(delete_button)
delete_button.click()

def copy_message_text(self, message_text):
self.driver.info("Copying '%s' message via long press" % message_text)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions test/appium/views/home_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, driver, username_part, community=False, community_channel=Fal
if self.community_channel:
super().__init__(
driver,
xpath="//*[@content-desc='chat-name-text']//*[starts-with(@text,'# %s')]/.." % username_part)
xpath="//*[@content-desc='chat-name-text']//*[starts-with(@text,'# %s')]/../.." % username_part)
elif community:
super().__init__(
driver,
Expand Down Expand Up @@ -411,7 +411,9 @@ def create_group_chat(self, user_names_to_add: list, group_chat_name: str = 'new
self.new_chat_button.click()
chat = self.get_chat_view()
self.start_a_new_chat_bottom_sheet_button.click()
[chat.get_username_checkbox(user_name).click() for user_name in user_names_to_add]
for user_name in user_names_to_add:
chat.get_username_checkbox(user_name).click_until_presence_of_element(
chat.get_username_checkbox(user_name, state_on=True))
self.setup_chat_button.click()
chat.chat_name_editbox.send_keys(group_chat_name)
chat.create_button.click()
Expand Down

0 comments on commit 5647bb4

Please sign in to comment.