From 64589d526f6410e247f9bf054b1ade755f1bc3cd Mon Sep 17 00:00:00 2001 From: Anton Danchenko Date: Tue, 4 Sep 2018 00:18:18 +0300 Subject: [PATCH] chatbot for one-to-one chats Signed-off-by: Anton Danchenko --- test/appium/tests/base_test_case.py | 13 +++++----- test/appium/tests/conftest.py | 13 ++++++++++ test/appium/tests/test_chatbot.py | 37 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 test/appium/tests/test_chatbot.py diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 56ec3f15b4..7bf6c3c4aa 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -151,14 +151,13 @@ class Driver(webdriver.Remote): class SingleDeviceTestCase(AbstractTestCase): - def setup_method(self, method): - capabilities = {'local': {'executor': self.executor_local, - 'capabilities': self.capabilities_local}, - 'sauce': {'executor': self.executor_sauce_lab, - 'capabilities': self.capabilities_sauce_lab}} + def setup_method(self, method, max_duration=1800): + + (executor, capabilities) = (self.executor_sauce_lab, self.capabilities_sauce_lab) if \ + self.environment == 'sauce' else (self.executor_local, self.capabilities_local) + capabilities['maxDuration'] = max_duration + self.driver = Driver(executor, capabilities) - self.driver = Driver(capabilities[self.environment]['executor'], - capabilities[self.environment]['capabilities']) test_suite_data.current_test.testruns[-1].jobs[self.driver.session_id] = 1 self.driver.implicitly_wait(self.implicitly_wait) diff --git a/test/appium/tests/conftest.py b/test/appium/tests/conftest.py index a31fc94150..9af1c5548c 100644 --- a/test/appium/tests/conftest.py +++ b/test/appium/tests/conftest.py @@ -22,6 +22,7 @@ testrail_report = TestrailReport(sauce_username, sauce_access_key) def pytest_addoption(parser): + parser.addoption("--build", action="store", default=datetime.now().strftime('%Y-%m-%d-%H-%M'), @@ -52,6 +53,7 @@ def pytest_addoption(parser): help='string; ropsten or rinkeby') # message reliability + parser.addoption('--rerun_count', action='store', default=0, @@ -77,6 +79,17 @@ def pytest_addoption(parser): default=None, help='Public key of user for 1-1 chat') + # chat bot + + parser.addoption('--public_keys', + action='store', + default=None, + help='List of public keys for one-to-one chats') + parser.addoption('--running_time', + action='store', + default=None, + help='Running time in seconds') + def get_rerun_count(): return int(pytest.config.getoption('rerun_count')) diff --git a/test/appium/tests/test_chatbot.py b/test/appium/tests/test_chatbot.py new file mode 100644 index 0000000000..c0cdf2fa18 --- /dev/null +++ b/test/appium/tests/test_chatbot.py @@ -0,0 +1,37 @@ +import time +import pytest +import numpy +from tests.base_test_case import SingleDeviceTestCase +from random import randint +from views.sign_in_view import SignInView + +stop = int(time.time()) + int(pytest.config.getoption('running_time')) + + +@pytest.mark.chatbot +class TestChatBot(SingleDeviceTestCase): + + def setup_method(self, method, max_duration=10800): + super(TestChatBot, self).setup_method(method, max_duration=10800) + + public_keys = pytest.config.getoption('public_keys').split() + repeats = 24 / len(public_keys) + + @pytest.mark.chatbot + @pytest.mark.parametrize('key', numpy.repeat(public_keys, repeats)) + def test_one_to_one_chatbot(self, key): + sign_in = SignInView(self.driver) + home = sign_in.create_user() + chat = home.add_contact(key) + + message_text = 'test' + chat.chat_message_input.send_keys(message_text) + chat.send_message_button.click() + + message = 'Message # %s, sent by e2e test, to %s ' + counter = 0 + while int(time.time()) < stop: + counter += 1 + time.sleep(randint(60, 120)) + chat.chat_message_input.send_keys(message % (counter, key)) + chat.send_message_button.click()