|
| 1 | +import random |
| 2 | +import string |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from tests import marks, get_current_time |
| 7 | +from tests.base_test_case import MultipleDeviceTestCase |
| 8 | +from views.sign_in_view import SignInView |
| 9 | + |
| 10 | + |
| 11 | +@marks.all |
| 12 | +@marks.chat |
| 13 | +class TestMessagesOneToOneChat(MultipleDeviceTestCase): |
| 14 | + |
| 15 | + @marks.skip |
| 16 | + @marks.testrail_case_id(764) |
| 17 | + def test_text_message_1_1_chat(self): |
| 18 | + self.create_drivers(2) |
| 19 | + device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) |
| 20 | + for sign_in in device_1, device_2: |
| 21 | + sign_in.create_user() |
| 22 | + device_1_home, device_2_home = device_1.get_home_view(), device_2.get_home_view() |
| 23 | + device_2_public_key = device_2_home.get_public_key() |
| 24 | + device_2_home.home_button.click() |
| 25 | + |
| 26 | + device_1_chat = device_1_home.add_contact(device_2_public_key) |
| 27 | + |
| 28 | + message = 'hello' |
| 29 | + device_1_chat.chat_message_input.send_keys(message) |
| 30 | + device_1_chat.send_message_button.click() |
| 31 | + |
| 32 | + device_2_home.element_by_text(message, 'button').click() |
| 33 | + |
| 34 | + if device_1_chat.chat_element_by_text(message).status.text != 'Seen': |
| 35 | + pytest.fail("'Seen' status is shown under the sent text message") |
| 36 | + |
| 37 | + @marks.skip |
| 38 | + @marks.testrail_case_id(772) |
| 39 | + def test_offline_messaging_1_1_chat(self): |
| 40 | + self.create_drivers(2, offline_mode=True) |
| 41 | + device_1, device_2 = self.drivers[0], self.drivers[1] |
| 42 | + sign_in_1, sign_in_2 = SignInView(device_1), SignInView(device_2) |
| 43 | + sign_in_1.create_user() |
| 44 | + username_2 = sign_in_2.create_user() |
| 45 | + home_1, home_2 = sign_in_1.get_home_view(), sign_in_2.get_home_view() |
| 46 | + public_key_1 = home_1.get_public_key() |
| 47 | + home_1.home_button.click() |
| 48 | + |
| 49 | + device_1.set_network_connection(1) # airplane mode on primary device |
| 50 | + |
| 51 | + chat_2 = home_2.add_contact(public_key_1) |
| 52 | + message_1 = 'test message' |
| 53 | + chat_2.chat_message_input.send_keys(message_1) |
| 54 | + chat_2.send_message_button.click() |
| 55 | + device_2.set_network_connection(1) # airplane mode on secondary device |
| 56 | + |
| 57 | + device_1.set_network_connection(2) # turning on WiFi connection on primary device |
| 58 | + |
| 59 | + chat_element = home_1.get_chat_with_user(username_2) |
| 60 | + chat_element.wait_for_visibility_of_element(20) |
| 61 | + chat_1 = chat_element.click() |
| 62 | + chat_1.chat_element_by_text(message_1).wait_for_visibility_of_element(2) |
| 63 | + |
| 64 | + device_2.set_network_connection(2) # turning on WiFi connection on secondary device |
| 65 | + device_1.set_network_connection(1) # airplane mode on primary device |
| 66 | + |
| 67 | + chat_2.element_by_text('Connecting to peers...').wait_for_invisibility_of_element(60) |
| 68 | + message_2 = 'one more message' |
| 69 | + chat_2.chat_message_input.send_keys(message_2) |
| 70 | + chat_2.send_message_button.click() |
| 71 | + |
| 72 | + device_1.set_network_connection(2) # turning on WiFi connection on primary device |
| 73 | + |
| 74 | + chat_1 = chat_element.click() |
| 75 | + chat_1.chat_element_by_text(message_2).wait_for_visibility_of_element(180) |
| 76 | + |
| 77 | + @marks.testrail_case_id(3701) |
| 78 | + def test_resend_message_offline(self): |
| 79 | + self.create_drivers(2, offline_mode=True) |
| 80 | + device_1, device_2 = self.drivers[0], self.drivers[1] |
| 81 | + sign_in_1, sign_in_2 = SignInView(device_1), SignInView(device_2) |
| 82 | + username_1 = 'user_%s' % get_current_time() |
| 83 | + sign_in_1.create_user(username_1) |
| 84 | + sign_in_2.create_user() |
| 85 | + home_1, home_2 = sign_in_1.get_home_view(), sign_in_2.get_home_view() |
| 86 | + public_key_2 = home_2.get_public_key() |
| 87 | + home_2.home_button.click() |
| 88 | + |
| 89 | + device_1.set_network_connection(1) # airplane mode on primary device |
| 90 | + |
| 91 | + chat_1 = home_1.add_contact(public_key_2) |
| 92 | + message = 'test message' |
| 93 | + chat_1.chat_message_input.send_keys(message) |
| 94 | + chat_1.send_message_button.click() |
| 95 | + progress_time = chat_1.chat_element_by_text(message).progress_bar.measure_time_while_element_is_shown() |
| 96 | + if not 9 < progress_time < 11: |
| 97 | + self.errors.append('Progress indicator is shown during %s seconds' % progress_time) |
| 98 | + |
| 99 | + device_1.set_network_connection(2) # turning on WiFi connection |
| 100 | + |
| 101 | + chat_1.element_by_text('Not sent. Tap for options').click() |
| 102 | + if not chat_1.element_by_text('Delete message').is_element_displayed(): |
| 103 | + self.errors.append("'Delete message' button is not shown for not sent message") |
| 104 | + |
| 105 | + chat_1.connection_status.wait_for_invisibility_of_element(60) |
| 106 | + chat_1.element_by_text('Resend').click() |
| 107 | + if chat_1.chat_element_by_text(message).status.text != 'Sent': |
| 108 | + self.errors.append("Message status is not 'Sent' after resending the message") |
| 109 | + |
| 110 | + chat_2 = home_2.get_chat_with_user(username_1).click() |
| 111 | + if not chat_2.chat_element_by_text(message).is_element_displayed(10): |
| 112 | + self.errors.append("Message with text '%s' is not received" % message) |
| 113 | + |
| 114 | + self.verify_no_errors() |
| 115 | + |
| 116 | + @marks.testrail_case_id(3710) |
| 117 | + def test_messaging_in_different_networks(self): |
| 118 | + self.create_drivers(2, offline_mode=True) |
| 119 | + device_1, device_2 = self.drivers[0], self.drivers[1] |
| 120 | + sign_in_1, sign_in_2 = SignInView(device_1), SignInView(device_2) |
| 121 | + username_1 = 'user_%s' % get_current_time() |
| 122 | + sign_in_1.create_user(username_1) |
| 123 | + sign_in_2.create_user() |
| 124 | + home_1, home_2 = sign_in_1.get_home_view(), sign_in_2.get_home_view() |
| 125 | + public_key_2 = home_2.get_public_key() |
| 126 | + profile_2 = home_2.get_profile_view() |
| 127 | + profile_2.switch_network('Mainnet with upstream RPC') |
| 128 | + sign_in_2.click_account_by_position(0) |
| 129 | + sign_in_2.sign_in() |
| 130 | + |
| 131 | + chat_1 = home_1.add_contact(public_key_2) |
| 132 | + message = 'test message' |
| 133 | + chat_1.chat_message_input.send_keys(message) |
| 134 | + chat_1.send_message_button.click() |
| 135 | + |
| 136 | + chat_2 = home_2.get_chat_with_user(username_1).click() |
| 137 | + chat_2.chat_element_by_text(message).wait_for_visibility_of_element() |
| 138 | + |
| 139 | + public_chat_name = ''.join(random.choice(string.ascii_lowercase) for _ in range(7)) |
| 140 | + chat_1.get_back_to_home_view() |
| 141 | + home_1.join_public_chat(public_chat_name) |
| 142 | + chat_2.get_back_to_home_view() |
| 143 | + home_2.join_public_chat(public_chat_name) |
| 144 | + |
| 145 | + chat_1.chat_message_input.send_keys(message) |
| 146 | + chat_1.send_message_button.click() |
| 147 | + chat_2.chat_element_by_text(message).wait_for_visibility_of_element() |
0 commit comments