From c95bc11d52aff596adac0c25b56f34427177020f Mon Sep 17 00:00:00 2001 From: yevh-berdnyk Date: Mon, 30 Apr 2018 12:58:20 +0300 Subject: [PATCH] Removed getting latest nightly apk, fixed messaging tests Signed-off-by: yevh-berdnyk --- test/appium/tests/api_requests.py | 6 +++++- test/appium/tests/conftest.py | 6 +++--- test/appium/tests/test_sanity.py | 9 ++------- test/appium/tests/test_transaction.py | 17 +++++++++++++---- test/appium/views/base_view.py | 12 ++++++++++++ test/appium/views/chat_view.py | 4 ++-- test/appium/views/sign_in_view.py | 6 +++--- 7 files changed, 40 insertions(+), 20 deletions(-) diff --git a/test/appium/tests/api_requests.py b/test/appium/tests/api_requests.py index ddc131545f..00580b90ae 100644 --- a/test/appium/tests/api_requests.py +++ b/test/appium/tests/api_requests.py @@ -46,11 +46,15 @@ def verify_balance_is_updated(initial_balance, recipient_address, wait_time=240) return +def faucet(address): + return requests.request('GET', 'http://51.15.45.169:3001/donate/0x%s' % address).json() + + def get_donate(address, wait_time=300): initial_balance = get_balance(address) counter = 0 if initial_balance < 1000000000000000000: - response = requests.request('GET', 'http://51.15.45.169:3001/donate/0x%s' % address).json() + response = faucet(address) while True: if counter >= wait_time: pytest.fail("Donation was not received during %s seconds!" % wait_time) diff --git a/test/appium/tests/conftest.py b/test/appium/tests/conftest.py index 60995ff9b0..0533c84c17 100644 --- a/test/appium/tests/conftest.py +++ b/test/appium/tests/conftest.py @@ -33,11 +33,11 @@ latest_nightly_apk['url'] = storage + latest_nightly_apk['name'] def pytest_addoption(parser): parser.addoption("--build", action="store", - default='build_' + latest_nightly_apk['name'], + default=datetime.now().strftime('%Y-%m-%d-%H-%M'), # 'build_' + latest_nightly_apk['name'], help="Specify build name") parser.addoption('--apk', action='store', - default=latest_nightly_apk['url'], + default=None, help='Url or local path to apk') parser.addoption('--env', action='store', @@ -117,4 +117,4 @@ def update_sauce_jobs(test_name, job_ids, passed): def pytest_runtest_setup(item): - test_suite_data.add_test(SingleTestData(item.name)) \ No newline at end of file + test_suite_data.add_test(SingleTestData(item.name)) diff --git a/test/appium/tests/test_sanity.py b/test/appium/tests/test_sanity.py index 5c6e565240..36c0126bd9 100644 --- a/test/appium/tests/test_sanity.py +++ b/test/appium/tests/test_sanity.py @@ -117,13 +117,8 @@ class TestSanity(SingleDeviceTestCase): def test_password_logcat(self): password = 'qwerty1234' sign_in_view = SignInView(self.driver) - sign_in_view.create_account_button.click() - sign_in_view.password_input.send_keys(password) - sign_in_view.next_button.click() - sign_in_view.confirm_password_input.send_keys(password) - sign_in_view.next_button.click() - sign_in_view.find_full_text( - "Creating your account on the blockchain. We can't touch it, no one can, except for you!") + sign_in_view.create_user(password=password) + sign_in_view.home_button.wait_for_visibility_of_element() if password in str(sign_in_view.logcat): pytest.fail('Password in logcat!!!', pytrace=False) diff --git a/test/appium/tests/test_transaction.py b/test/appium/tests/test_transaction.py index d8cb9abe38..9c74c194b3 100644 --- a/test/appium/tests/test_transaction.py +++ b/test/appium/tests/test_transaction.py @@ -203,11 +203,15 @@ class TestTransaction(SingleDeviceTestCase): @pytest.mark.all class TestTransactions(MultipleDeviceTestCase): + senders = dict() + senders['c_user'] = transaction_users_wallet['C_USER'] + senders['d_user'] = transaction_users['D_USER'] + senders['f_user'] = transaction_users['F_USER'] @pytest.mark.pr def test_send_eth_to_request_in_group_chat(self): recipient = transaction_users['E_USER'] - sender = transaction_users['F_USER'] + sender = self.senders['f_user'] self.create_drivers(2) device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) for user_details in (recipient, device_1), (sender, device_2): @@ -236,7 +240,7 @@ class TestTransactions(MultipleDeviceTestCase): @pytest.mark.pr def test_send_eth_to_request_in_one_to_one_chat(self): recipient = transaction_users['C_USER'] - sender = transaction_users['D_USER'] + sender = self.senders['d_user'] self.create_drivers(2) device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) for user_details in (recipient, device_1), (sender, device_2): @@ -274,8 +278,8 @@ class TestTransactions(MultipleDeviceTestCase): @pytest.mark.pr def test_send_eth_to_request_from_wallet(self): - recipient = transaction_users['D_USER'] - sender = transaction_users['C_USER'] + recipient = transaction_users_wallet['D_USER'] + sender = self.senders['c_user'] self.create_drivers(2) device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1]) for user_details in (recipient, device_1), (sender, device_2): @@ -306,3 +310,8 @@ class TestTransactions(MultipleDeviceTestCase): request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button') device_2_chat.send_eth_to_request(request_button, sender['password']) api_requests.verify_balance_is_updated(initial_balance_recipient, recipient['address']) + + def teardown_method(self, method): + for user in self.senders: + api_requests.faucet(address=self.senders[user]['address']) + super(TestTransactions, self).teardown_method(method) diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index ef19df00c2..16968ad9d7 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -240,6 +240,18 @@ class BaseView(object): element.locator = element.Locator.xpath_selector('//*[contains(@text, "' + text + '")]') return element + def element_starts_with_text(self, text, element_type='base'): + info("Looking for full text: '%s'" % text) + element = self.element_types[element_type](self.driver) + element.locator = element.Locator.xpath_selector("//*[starts-with(@text,'%s')]" % text) + return element + + def wait_for_element_starts_with_text(self, text, wait_time=60): + info("Looking for full text: '%s'" % text) + element = BaseElement(self.driver) + element.locator = element.Locator.xpath_selector("//*[starts-with(@text,'%s')]" % text) + return element.wait_for_element(wait_time) + def get_home_view(self): from views.home_view import HomeView return HomeView(self.driver) diff --git a/test/appium/views/chat_view.py b/test/appium/views/chat_view.py index 9e36923f51..9dbdccc22f 100644 --- a/test/appium/views/chat_view.py +++ b/test/appium/views/chat_view.py @@ -166,7 +166,7 @@ class ChatView(BaseView): def wait_for_message_in_one_to_one_chat(self, expected_message: str, errors: list): try: - self.find_full_text(expected_message, wait_time=20) + self.wait_for_element_starts_with_text(expected_message, wait_time=20) except TimeoutException: errors.append('Message with text "%s" was not received' % expected_message) @@ -189,7 +189,7 @@ class ChatView(BaseView): received_messages = list() while repeat <= wait_time: for message in expected_messages: - if self.element_by_text(message, 'text').is_element_present(1): + if self.element_starts_with_text(message, 'text').is_element_present(1): received_messages.append(message) if not set(expected_messages) - set(received_messages): break diff --git a/test/appium/views/sign_in_view.py b/test/appium/views/sign_in_view.py index 5a0e51d074..d5ee14e5db 100644 --- a/test/appium/views/sign_in_view.py +++ b/test/appium/views/sign_in_view.py @@ -97,11 +97,11 @@ class SignInView(BaseView): self.name_input = NameInput(self.driver) self.do_not_share = DonNotShare(self.driver) - def create_user(self): + def create_user(self, password: str = 'qwerty1234'): self.create_account_button.click() - self.password_input.set_value('qwerty1234') + self.password_input.set_value(password) self.next_button.click() - self.confirm_password_input.set_value('qwerty1234') + self.confirm_password_input.set_value(password) self.next_button.click() self.name_input.wait_for_element(45) self.name_input.set_value('user_%s' % get_current_time())