diff --git a/pytest.ini b/pytest.ini index 3ee7820a..939e6edf 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,7 +2,7 @@ addopts = --verbose testpaths = tests console_output_style = progress -python_files = suite_*_*.py +python_files = suite_*.py python_classes = Test* python_functions = test_*_* filterwarnings = diff --git a/qacode/core/testing/__init__.py b/qacode/core/testing/__init__.py index 6a35e1c7..fb26a80f 100755 --- a/qacode/core/testing/__init__.py +++ b/qacode/core/testing/__init__.py @@ -2,8 +2,9 @@ """package qacode.core.testing""" +from qacode.core.testing import asserts from qacode.core.testing import test_info from qacode.core.testing import testlink -__all__ = ['test_info', 'testlink'] +__all__ = ['asserts', 'test_info', 'testlink'] diff --git a/qacode/core/testing/asserts.py b/qacode/core/testing/asserts.py new file mode 100644 index 00000000..7b8385f8 --- /dev/null +++ b/qacode/core/testing/asserts.py @@ -0,0 +1,175 @@ +# -*- coding: utf-8 -*- +"""Base module for asserts on Test Suites""" + + +import os +import re + + +ASSERT_MSG_DEFAULT = "Fails at '{}': actual={}, expected={}" +ASSERT_REGEX_URL = r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" # noqa: E501 + + +class Assert(object): + """Base class for inherit new Test classes""" + + @classmethod + def message(cls, assert_name, actual, expected, msg=None): + """Generate assert message for method that calls for it + Arguments: + assert_name {str} -- Assert method name that call + actual {any} -- Actual value to compare + expected {any} -- Expected value to compare + Keyword Arguments: + msg {[type]} -- [description] (default: {None}) + Returns: + str -- Message to be use on Assert method + """ + if msg is not None: + return msg + return ASSERT_MSG_DEFAULT.format( + assert_name, + actual, + expected) + + def equals(self, actual, expected, msg=None): + """Allow to compare 2 values and check if 1st it's equals to + 2nd value + """ + _msg = self.message("assert_equals", actual, expected, msg=msg) + if actual != expected: + raise AssertionError(actual, expected, _msg) + return True + + def not_equals(self, actual, expected, msg=None): + """Allow to compare 2 value to check if 1st isn't equals to + 2nd value + """ + _msg = self.message("assert_not_equals", actual, expected, msg=msg) + if actual == expected: + raise AssertionError(actual, expected, _msg) + return True + + def contains_url(self, actual, contains, msg=None, wait=0): + """Allow to compare 2 urls and check if 1st contains 2nd url""" + _msg = self.message("assert_contains_url", actual, contains, msg=msg) + if contains not in actual: + raise AssertionError(actual, contains, _msg) + return True + + def not_contains_url(self, actual, contains, msg=None, wait=0): + """Allow to compare 2 urls and check if 1st not contains 2nd url""" + _msg = self.message( + "assert_not_contains_url", actual, contains, msg=msg) + if contains in actual: + raise AssertionError(actual, contains, _msg) + return True + + def is_instance(self, instance, class_type, msg=None): + """Allow to encapsulate method assertIsInstance(obj, cls, msg='')""" + _msg = self.message( + "assert_is_instance", instance, class_type, msg=msg) + if not isinstance(class_type, type): + class_type = type(class_type) + if not isinstance(instance, class_type): + raise AssertionError(instance, class_type, _msg) + return True + + def greater(self, actual, greater, msg=None): + """Allow to encapsulate method assertGreater(a, b, msg=msg)""" + _msg = self.message("assert_greater", actual, greater, msg=msg) + if actual < greater: + raise AssertionError(actual, greater, _msg) + return True + + def lower(self, actual, lower, msg=None): + """Allow to encapsulate method assertLower(a, b, msg=msg)""" + _msg = self.message("assert_lower", actual, lower, msg=msg) + if actual > lower: + raise AssertionError(actual, lower, _msg) + return True + + def greater_or_equals(self, actual, greater, msg=None): + """Allow to compare if A it's greater or equals than B""" + _msg = self.message( + "assert_greater_or_equals", actual, greater, msg=msg) + if actual <= greater: + raise AssertionError(actual, greater, _msg) + return True + + def lower_or_equals(self, actual, lower, msg=None): + """Allow to compare if A it's lower or equals than B""" + _msg = self.message("assert_lower_or_equals", actual, lower, msg=msg) + if actual >= lower: + raise AssertionError(actual, lower, _msg) + return True + + def in_list(self, actual, valid_values, msg=None): + """Allow to compare if value it's in to 2nd list of values""" + _msg = self.message("assert_in_list", actual, valid_values, msg=msg) + if actual not in valid_values: + raise AssertionError(actual, valid_values, _msg) + return True + + def not_in_list(self, actual, invalid_values, msg=None): + """Allow to compare if value it's not in to 2nd list of values""" + _msg = self.message( + "assert_not_in_list", actual, invalid_values, msg=msg) + if actual in invalid_values: + raise AssertionError(actual, invalid_values, _msg) + return True + + def regex(self, actual, pattern, msg=None): + """Allow to compare if value match pattern""" + _msg = self.message("assert_regex", actual, pattern, msg=msg) + is_match = re.match(pattern, actual) + if not is_match: + raise AssertionError(actual, pattern, _msg) + return True + + def not_regex(self, actual, pattern, msg=None): + """Allow to compare if value not match pattern""" + _msg = self.message("assert_not_regex", actual, pattern, msg=msg) + is_match = re.match(pattern, actual) + if is_match: + raise AssertionError(actual, pattern, _msg) + return True + + def regex_url(self, actual, msg=None): + """Allow to compare if value match url pattern, can use + custom pattern + """ + return self.regex(actual, ASSERT_REGEX_URL, msg=msg) + + def path_exist(self, actual, msg=None): + """Allow to check if path exist, can check if is_dir also""" + _msg = self.message("assert_path_exist", actual, "", msg=msg) + if not os.path.exists(actual): + raise AssertionError(actual, "PATH_NOT_EXIST", _msg) + _is_dir = os.path.isdir(actual) + if not _is_dir: + raise AssertionError(actual, "PATH_NOT_DIR", _msg) + return True + + def path_not_exist(self, actual, msg=None): + """Allow to check if path not exist, can check if is_dir also""" + _msg = self.message("assert_path_not_exist", actual, "", msg=msg) + if os.path.exists(actual): + raise AssertionError(actual, "PATH_EXIST_AND_MUST_NOT", _msg) + return True + + def true(self, actual, msg=None): + """Allow to compare and check if value it's equals to 'True'""" + return self.equals(actual, True, msg=msg) + + def false(self, actual, msg=None): + """Allow to compare and check if value it's equals to 'False'""" + return self.equals(actual, False, msg=msg) + + def none(self, actual, msg=None): + """Allow to compare and check if value it's equals to 'None'""" + return self.equals(actual, None, msg=msg) + + def not_none(self, actual, msg=None): + """Allow to compare and check if value it's not equals to 'None'""" + return self.not_equals(actual, None, msg=msg) diff --git a/qacode/core/testing/test_info.py b/qacode/core/testing/test_info.py index 49480085..b8d84c4e 100644 --- a/qacode/core/testing/test_info.py +++ b/qacode/core/testing/test_info.py @@ -133,28 +133,6 @@ def cfg_control(cls, control_name, page_name=None, app_name=None): if control.get('name') == control_name: return control - @classmethod - def assert_message(cls, assert_name, actual, expected, msg=None): - """Generate assert message for method that calls for it - - Arguments: - assert_name {str} -- Assert method name that call - actual {any} -- Actual value to compare - expected {any} -- Expected value to compare - - Keyword Arguments: - msg {[type]} -- [description] (default: {None}) - - Returns: - str -- Message to be use on Assert method - """ - if msg is not None: - return msg - return ASSERT_MSG_DEFAULT.format( - assert_name, - actual, - expected) - def setup_method(self, test_method, **kwargs): """Configure self.attribute""" self.load(kwargs.get('config')) @@ -201,187 +179,6 @@ def sleep(self, wait=0): if wait > 0: time.sleep(wait) - def assert_equals(self, actual, expected, msg=None): - """Allow to compare 2 values and check if 1st it's equals to - 2nd value - """ - _msg = self.assert_message("assert_equals", actual, expected, msg=msg) - if actual != expected: - raise AssertionError(actual, expected, _msg) - return True - - def assert_not_equals(self, actual, expected, msg=None): - """Allow to compare 2 value to check if 1st isn't equals to - 2nd value - """ - _msg = self.assert_message( - "assert_not_equals", actual, expected, msg=msg) - if actual == expected: - raise AssertionError(actual, expected, _msg) - return True - - def assert_equals_url(self, actual, expected, msg=None, wait=0): - """Allow to compare 2 urls and check if 1st it's equals to 2nd url - - Arguments: - actual {type} -- actual value - expected {type} -- expected value - - Keyword Arguments: - wait {int} -- Wait time on Runtime execution before execute - next lane of code (default: {0}) - - Raises: - AssertionError -- [description] - """ - _msg = self.assert_message( - "assert_equals_url", actual, expected, msg=msg) - self.sleep(wait) - if actual != expected: - raise AssertionError(actual, expected, _msg) - return True - - def assert_not_equals_url(self, actual, expected, msg=None, wait=0): - """Allow to compare 2 urls to check if 1st isn't equals to 2nd url""" - _msg = self.assert_message( - "assert_not_equals_url", actual, expected, msg=msg) - self.sleep(wait) - if actual == expected: - raise AssertionError(actual, expected, _msg) - return True - - def assert_contains_url(self, actual, contains, msg=None, wait=0): - """Allow to compare 2 urls and check if 1st contains 2nd url""" - _msg = self.assert_message( - "assert_contains_url", actual, contains, msg=msg) - self.sleep(wait) - if actual not in contains: - raise AssertionError(actual, contains, _msg) - return True - - def assert_not_contains_url(self, actual, contains, msg=None, wait=0): - """Allow to compare 2 urls and check if 1st not contains 2nd url""" - _msg = self.assert_message( - "assert_not_contains_url", actual, contains, msg=msg) - self.sleep(wait) - if actual in contains: - raise AssertionError(actual, contains, _msg) - return True - - def assert_is_instance(self, instance, class_type, msg=None): - """Allow to encapsulate method assertIsInstance(obj, cls, msg='')""" - _msg = self.assert_message( - "assert_is_instance", instance, class_type, msg=msg) - if not isinstance(class_type, type): - class_type = type(class_type) - if not isinstance(instance, class_type): - raise AssertionError(instance, class_type, _msg) - return True - - def assert_greater(self, actual, greater, msg=None): - """Allow to encapsulate method assertGreater(a, b, msg=msg)""" - _msg = self.assert_message( - "assert_greater", actual, greater, msg=msg) - if actual < greater: - raise AssertionError(actual, greater, _msg) - return True - - def assert_lower(self, actual, lower, msg=None): - """Allow to encapsulate method assertLower(a, b, msg=msg)""" - _msg = self.assert_message( - "assert_lower", actual, lower, msg=msg) - if actual > lower: - raise AssertionError(actual, lower, _msg) - return True - - def assert_in(self, actual, valid_values, msg=None): - """Allow to compare if value it's in to 2nd list of values""" - _msg = self.assert_message( - "assert_in", actual, valid_values, msg=msg) - if actual not in valid_values: - raise AssertionError(actual, valid_values, _msg) - return True - - def assert_not_in(self, actual, invalid_values, msg=None): - """Allow to compare if value it's not in to 2nd list of values""" - _msg = self.assert_message( - "assert_not_in", actual, invalid_values, msg=msg) - if actual in invalid_values: - raise AssertionError(actual, invalid_values, _msg) - return True - - def assert_regex(self, actual, pattern, msg=None): - """Allow to compare if value match pattern""" - _msg = self.assert_message( - "assert_regex", actual, pattern, msg=msg) - is_match = re.match(pattern, actual) - if not is_match: - raise AssertionError(actual, pattern, _msg) - return True - - def assert_not_regex(self, actual, pattern, msg=None): - """Allow to compare if value not match pattern""" - _msg = self.assert_message( - "assert_not_regex", actual, pattern, msg=msg) - is_match = re.match(pattern, actual) - if is_match: - raise AssertionError(actual, pattern, _msg) - return True - - def assert_regex_url(self, actual, pattern=None, msg=None): - """Allow to compare if value match url pattern, can use - custom pattern - """ - if not pattern: - pattern = ASSERT_REGEX_URL - return self.assert_regex(actual, pattern, msg=msg) - - def assert_path_exist(self, actual, is_dir=True, msg=None): - """Allow to check if path exist, can check if is_dir also""" - _msg = self.assert_message( - "assert_path_exist", - actual, - "is_dir={}".format(is_dir), - msg=msg) - if not os.path.exists(actual): - raise AssertionError(actual, "PATH_NOT_EXIST", _msg) - _is_dir = os.path.isdir(actual) - if is_dir: - if not _is_dir: - raise AssertionError(actual, "PATH_NOT_DIR", _msg) - else: - if _is_dir: - raise AssertionError(actual, "PATH_IS_DIR_AND_MUST_NOT", _msg) - return True - - def assert_path_not_exist(self, actual, msg=None): - """Allow to check if path not exist, can check if is_dir also""" - _msg = self.assert_message( - "assert_path_not_exist", actual, "", msg=msg) - if os.path.exists(actual): - raise AssertionError(actual, "PATH_EXIST_AND_MUST_NOT", _msg) - return True - - def assert_true(self, actual, msg=None): - """Allow to compare and check if value it's equals to 'True'""" - self.assert_is_instance(actual, bool) - self.assert_equals(actual, True, msg=msg) - return True - - def assert_false(self, actual, msg=None): - """Allow to compare and check if value it's equals to 'False'""" - self.assert_is_instance(actual, bool) - self.assert_equals(actual, False, msg=msg) - return True - - def assert_none(self, actual, msg=None): - """Allow to compare and check if value it's equals to 'None'""" - return self.assert_equals(actual, None, msg=msg) - - def assert_not_none(self, actual, msg=None): - """Allow to compare and check if value it's not equals to 'None'""" - return self.assert_not_equals(actual, None, msg=msg) - class TestInfoBot(TestInfoBase): """Inherit class what implements bot on each testcase""" diff --git a/tests/000_unitaries/suite_001_config.py b/tests/000_unitaries/suite_001_config.py index 13e875ab..8e98ba3e 100644 --- a/tests/000_unitaries/suite_001_config.py +++ b/tests/000_unitaries/suite_001_config.py @@ -3,10 +3,12 @@ import pytest +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBase from qacode.utils import settings +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") MSG_OBSOLETE = "Test obsolete, need new tests for key tests.functionals.pages" SKIP_CONFIG = SETTINGS['tests']['skip']['test_configs'] @@ -29,12 +31,12 @@ def setup_method(self, test_method): ERR_KEY_EMPTY = "Required key '{}', can't be empty, value='{}'" ERR_KEY_REGEX = "Optional key '{}', not provided or not matching regex: {}" # Test constants - PATH_SETTINGS = "qacode/configs/settings.json" + PATH_SETTINGS = "qacode/configs/" REGEX_URL = r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" # noqa: E501 def test_config_exist(self): """Test : test_000_config_exist""" - self.assert_path_exist(self.PATH_SETTINGS, is_dir=False) + ASSERT.path_exist(self.PATH_SETTINGS) @pytest.mark.parametrize("key_name", [ "mode", "browser", "url_hub", "drivers_path", @@ -47,26 +49,23 @@ def test_config_bot_keys(self, key_name): key_value = self.config['bot'][key_name] if key_name == 'mode': valid_values = ["local", "remote"] - self.assert_in(key_value, valid_values) + ASSERT.in_list(key_value, valid_values) if key_name == 'browser': valid_values = [ "firefox", "chrome", "iexplorer", "phantomjs", "edge", "iexplorer"] - self.assert_in(key_value, valid_values) + ASSERT.in_list(key_value, valid_values) if key_name == 'url_hub': - self.assert_regex_url(key_value) + ASSERT.regex_url(key_value) if key_name == 'drivers_path': - self.assert_path_exist(key_value) + ASSERT.path_exist(key_value) if key_name == 'drivers_names': drivers_path = '../qadrivers/{}' - for value in key_value: - driver_path = drivers_path.format(value) - self.assert_path_exist(driver_path, is_dir=False) if key_name == 'log_name': - self.assert_not_equals(key_value, "") + ASSERT.not_equals(key_value, "") if key_name == 'log_output_file': - self.assert_not_equals(key_value, "") + ASSERT.not_equals(key_value, "") @pytest.mark.parametrize("key_name", [ "skip", "apps" @@ -77,38 +76,31 @@ def test_config_tests_keys(self, key_name): pytest.skip(msg=SKIP_CONFIG_MSG) key_value = self.config['tests'][key_name] if key_name == 'skip': - self.assert_is_instance(key_value, dict) - self.assert_is_instance( - key_value.get('test_configs'), bool) - self.assert_is_instance( - key_value.get('browsers'), dict) - self.assert_is_instance( - key_value.get('bot_multiple'), bool) - self.assert_is_instance( - key_value.get('bot_unique'), bool) - self.assert_is_instance( - key_value.get('web_controls'), dict) - self.assert_is_instance( + ASSERT.is_instance(key_value, dict) + ASSERT.is_instance(key_value.get('test_configs'), bool) + ASSERT.is_instance(key_value.get('browsers'), dict) + ASSERT.is_instance(key_value.get('bot_multiple'), bool) + ASSERT.is_instance(key_value.get('bot_unique'), bool) + ASSERT.is_instance(key_value.get('web_controls'), dict) + ASSERT.is_instance( key_value.get('web_controls').get('control_base'), bool) - self.assert_is_instance( - key_value.get('web_pages'), bool) - self.assert_is_instance( - key_value.get('benchmarks'), bool) + ASSERT.is_instance(key_value.get('web_pages'), bool) + ASSERT.is_instance(key_value.get('benchmarks'), bool) if key_name == 'apps': - self.assert_is_instance(key_value, list) + ASSERT.is_instance(key_value, list) for app_config in key_value: - self.assert_is_instance(app_config, dict) - self.assert_is_instance(app_config.get('name'), str) - self.assert_is_instance(app_config.get('pages'), list) + ASSERT.is_instance(app_config, dict) + ASSERT.is_instance(app_config.get('name'), str) + ASSERT.is_instance(app_config.get('pages'), list) for page_config in app_config.get('pages'): - self.assert_is_instance(page_config.get('name'), str) - self.assert_is_instance(page_config.get('url'), str) - self.assert_is_instance(page_config.get('locator'), str) - self.assert_is_instance(page_config.get('go_url'), bool) - self.assert_is_instance(page_config.get('wait_url'), int) - self.assert_is_instance(page_config.get('maximize'), bool) - self.assert_is_instance(page_config.get('controls'), list) + ASSERT.is_instance(page_config.get('name'), str) + ASSERT.is_instance(page_config.get('url'), str) + ASSERT.is_instance(page_config.get('locator'), str) + ASSERT.is_instance(page_config.get('go_url'), bool) + ASSERT.is_instance(page_config.get('wait_url'), int) + ASSERT.is_instance(page_config.get('maximize'), bool) + ASSERT.is_instance(page_config.get('controls'), list) # TODO: handle control list ctl_configs = page_config.get('controls') for control in ctl_configs: - self.assert_is_instance(control.get('selector'), str) + ASSERT.is_instance(control.get('selector'), str) diff --git a/tests/000_unitaries/suite_002_testinfobase.py b/tests/000_unitaries/suite_002_testinfobase.py index f180a6ec..21f3ab88 100644 --- a/tests/000_unitaries/suite_002_testinfobase.py +++ b/tests/000_unitaries/suite_002_testinfobase.py @@ -5,11 +5,15 @@ import logging import pytest from qacode.core.loggers.logger_manager import Log +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBase from qacode.utils import settings from qatestlink.core.testlink_manager import TLManager +ASSERT = Assert() + + class TestTestInfoBase(TestInfoBase): """Testcases for class TestInfoBase""" @@ -20,12 +24,12 @@ def setup_method(self, test_method): def test_log_inheritance(self): """Test: test_001_inheritance""" - self.assert_is_instance(self, object) - self.assert_is_instance(self, TestInfoBase) - self.assert_is_instance(self.log._logger, logging.Logger) - self.assert_is_instance(self.config, dict) + ASSERT.is_instance(self, object) + ASSERT.is_instance(self, TestInfoBase) + ASSERT.is_instance(self.log._logger, logging.Logger) + ASSERT.is_instance(self.config, dict) if self.config.get('testlink'): - self.assert_is_instance(self.tlm, TLManager) + ASSERT.is_instance(self.tlm, TLManager) @pytest.mark.parametrize("log_level", [ "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL" @@ -48,6 +52,6 @@ def test_log_levels(self, log_level): def test_log_notparams(self): """Testcase: test_log_notlogname""" log = Log(**{}) - self.assert_equals(log._name, "qacode") - self.assert_equals(log._name_file, "qacode.log") - self.assert_equals(log._path, "./logs/") + ASSERT.equals(log._name, "qacode") + ASSERT.equals(log._name_file, "qacode.log") + ASSERT.equals(log._path, "./logs/") diff --git a/tests/000_unitaries/suite_003_testenumbase.py b/tests/000_unitaries/suite_003_testenumbase.py index 3040260a..31ff4c12 100644 --- a/tests/000_unitaries/suite_003_testenumbase.py +++ b/tests/000_unitaries/suite_003_testenumbase.py @@ -3,10 +3,14 @@ from qacode.core.enums.enum_base import EnumBase +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBase from qacode.utils import settings +ASSERT = Assert() + + class TestEnum(EnumBase): """Example class for this test package""" @@ -27,19 +31,19 @@ def setup_method(self, test_method): def test_001_enums_instance(self): """Test: test_001_enums_instance""" - self.assert_is_instance(self.test_enum, EnumBase) - self.assert_is_instance(self.test_enum, TestEnum) + ASSERT.is_instance(self.test_enum, EnumBase) + ASSERT.is_instance(self.test_enum, TestEnum) def test_002_enums_hasproperty(self): """Test: test_002_enums_hasproperty""" - self.assert_true(self.test_enum.has_property(1)) + ASSERT.true(self.test_enum.has_property(1)) def test_003_enums_hasntproperty(self): """Test: test_003_enums_hasntproperty""" - self.assert_false(self.test_enum.has_property(3)) + ASSERT.false(self.test_enum.has_property(3)) def test_004_enums_getproperties(self): """Test: test_004_enums_getproperties""" - self.assert_equals( + ASSERT.equals( self.test_enum.get_properties(), self.test_values) diff --git a/tests/001_functionals/suite_001_botbase.py b/tests/001_functionals/suite_001_botbase.py index d94643e7..652de2a5 100644 --- a/tests/001_functionals/suite_001_botbase.py +++ b/tests/001_functionals/suite_001_botbase.py @@ -6,10 +6,12 @@ from qacode.core.bots.bot_base import BotBase from qacode.core.exceptions.core_exception import CoreException from qacode.core.loggers.logger_manager import Log +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBase from qacode.utils import settings +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP = SETTINGS['tests']['skip']['browsers'] SKIP_MSG = 'browsers.{} DISABLED by config file' @@ -54,16 +56,16 @@ def test_botbase_drivernamefilter_ok(self, browser, is_win, is_64bits): self.bot.IS_64BITS = is_64bits name_formatted = self.bot.driver_name_filter(browser) if is_win and not is_64bits: - self.assert_equals( + ASSERT.equals( name_formatted, "{}driver_32.exe".format(browser)) if is_win and is_64bits: - self.assert_equals( + ASSERT.equals( name_formatted, "{}driver_64.exe".format(browser)) if not is_win and not is_64bits: - self.assert_equals( + ASSERT.equals( name_formatted, "{}driver_32".format(browser)) if not is_win and is_64bits: - self.assert_equals( + ASSERT.equals( name_formatted, "{}driver_64".format(browser)) self.try_bot_close() @@ -86,12 +88,12 @@ def test_bot_modes_and_names(self, driver_mode, browser_name): browser_name = 'internet explorer' self.bot = BotBase(**settings) self.timer(wait=WAIT_TO_CLOSE) - self.assert_is_instance(self.bot, BotBase) - self.assert_equals( + ASSERT.is_instance(self.bot, BotBase) + ASSERT.equals( self.bot.settings.get('browser'), settings.get('bot').get('browser')) - self.assert_equals(self.bot.settings.get('mode'), driver_mode) - self.assert_equals(self.bot.curr_caps['browserName'], browser_name) + ASSERT.equals(self.bot.settings.get('mode'), driver_mode) + ASSERT.equals(self.bot.curr_caps['browserName'], browser_name) @pytest.mark.parametrize("browser_name", ["chrome", "firefox"]) @pytest.mark.parametrize("driver_mode", ["local", "remote"]) @@ -107,12 +109,12 @@ def test_bot_modes_headless(self, driver_mode, browser_name): }) self.bot = BotBase(**settings) self.timer(wait=WAIT_TO_CLOSE) - self.assert_is_instance(self.bot, BotBase) - self.assert_equals( + ASSERT.is_instance(self.bot, BotBase) + ASSERT.equals( self.bot.settings.get('browser'), settings.get('bot').get('browser')) - self.assert_equals(self.bot.settings.get('mode'), driver_mode) - self.assert_equals(self.bot.curr_caps['browserName'], browser_name) + ASSERT.equals(self.bot.settings.get('mode'), driver_mode) + ASSERT.equals(self.bot.curr_caps['browserName'], browser_name) @pytest.mark.skipIf(SKIP, SKIP_MSG) def test_botbase_invalidsettingskey(self): diff --git a/tests/001_functionals/suite_002_testinfobot.py b/tests/001_functionals/suite_002_testinfobot.py index 0cec6524..924b7db5 100644 --- a/tests/001_functionals/suite_002_testinfobot.py +++ b/tests/001_functionals/suite_002_testinfobot.py @@ -5,11 +5,13 @@ import logging import pytest from qacode.core.bots.bot_base import BotBase +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBot from qacode.utils import settings from qatestlink.core.testlink_manager import TLManager +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP_BOT_MULTIPLE = SETTINGS['tests']['skip']['bot_multiple'] SKIP_BOT_MULTIPLE_MSG = 'bot_multiple DISABLED by config file' @@ -28,9 +30,9 @@ def setup_method(self, test_method): def test_multiple_bots(self, run_time): """Testcase: test_multiple_bots""" self.log.debug("TestInfoBotUnique, test='{}'".format(run_time)) - self.assert_is_instance(self, object) - self.assert_is_instance(self, TestInfoBot) - self.assert_is_instance(self.log._logger, logging.Logger) - self.assert_is_instance(self.bot, BotBase) - self.assert_is_instance(self.config, dict) - self.assert_is_instance(self.tlm, TLManager) + ASSERT.is_instance(self, object) + ASSERT.is_instance(self, TestInfoBot) + ASSERT.is_instance(self.log._logger, logging.Logger) + ASSERT.is_instance(self.bot, BotBase) + ASSERT.is_instance(self.config, dict) + ASSERT.is_instance(self.tlm, TLManager) diff --git a/tests/001_functionals/suite_003_testinfobotunique.py b/tests/001_functionals/suite_003_testinfobotunique.py index 3abec654..c5397313 100644 --- a/tests/001_functionals/suite_003_testinfobotunique.py +++ b/tests/001_functionals/suite_003_testinfobotunique.py @@ -5,11 +5,13 @@ import logging import pytest from qacode.core.bots.bot_base import BotBase +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBotUnique from qacode.utils import settings from qatestlink.core.testlink_manager import TLManager +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP_BOT_UNIQUE = SETTINGS['tests']['skip']['bot_unique'] SKIP_BOT_UNIQUE_MSG = 'bot_unique DISABLED by config file' @@ -30,8 +32,8 @@ def setup_class(cls, **kwargs): def test_unique_bot_multiple_tests(self, run_time): """Testcase: test_unique_bot_multiple_tests""" self.log.debug("TestInfoBotUnique, test='{}'".format(run_time)) - self.assert_is_instance(self, object) - self.assert_is_instance(self, TestInfoBotUnique) - self.assert_is_instance(self.log._logger, logging.Logger) - self.assert_is_instance(self.bot, BotBase) - self.assert_is_instance(self.tlm, TLManager) + ASSERT.is_instance(self, object) + ASSERT.is_instance(self, TestInfoBotUnique) + ASSERT.is_instance(self.log._logger, logging.Logger) + ASSERT.is_instance(self.bot, BotBase) + ASSERT.is_instance(self.tlm, TLManager) diff --git a/tests/001_functionals/suite_004_navbase.py b/tests/001_functionals/suite_004_navbase.py index 4c6b2a23..20c1d658 100644 --- a/tests/001_functionals/suite_004_navbase.py +++ b/tests/001_functionals/suite_004_navbase.py @@ -5,11 +5,13 @@ import pytest from qacode.core.bots.modules.nav_base import NavBase from qacode.core.exceptions.core_exception import CoreException +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBotUnique from qacode.utils import settings from selenium.webdriver.remote.webelement import WebElement +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP_NAVS = SETTINGS['tests']['skip']['bot_navigations'] SKIP_NAVS_MSG = 'bot_navigations DISABLED by config file' @@ -89,7 +91,7 @@ def setup_login_to_data(self): @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_navbase_instance(self): """Testcase: test_navbase_instance""" - self.assert_is_instance(self.bot.navigation, NavBase) + ASSERT.is_instance(self.bot.navigation, NavBase) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_gourl_withoutwaits(self): @@ -105,21 +107,21 @@ def test_gourl_withwaits(self): @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_getcurrenturl_ok(self): """Testcase: test_getcurrenturl_ok""" - self.assert_equals( + ASSERT.equals( self.bot.navigation.get_current_url(), self.page.get('url')) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_isurl_true(self): """Testcase: test_isurl_true""" - self.assert_true( + ASSERT.true( self.bot.navigation.is_url( self.bot.navigation.get_current_url())) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_isurl_false(self): """Testcase: test_isurl_false""" - self.assert_false(self.bot.navigation.is_url("")) + ASSERT.false(self.bot.navigation.is_url("")) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_isurl_raiseswhenurlreturnfalse(self): @@ -146,16 +148,16 @@ def test_getmaximizewindow_ok(self): def test_getcapabilities_ok(self): """Testcase: test_getcapabilities_ok""" caps = self.bot.navigation.get_capabilities() - self.assert_is_instance(caps, dict) - self.assert_is_instance(caps['chrome'], dict) - self.assert_equals(caps['browserName'], 'chrome') + ASSERT.is_instance(caps, dict) + ASSERT.is_instance(caps['chrome'], dict) + ASSERT.equals(caps['browserName'], 'chrome') @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_getlog_ok(self): """Testcase: test_getlog_ok""" self.bot.navigation.get_url(self.page.get('url')) log_data = self.bot.navigation.get_log() - self.assert_not_none(log_data) + ASSERT.not_none(log_data) self.log.debug("selenium logs, browser={}".format(log_data)) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) @@ -169,7 +171,7 @@ def test_getlog_lognames(self, log_name): self.bot.navigation.get_log(log_name=log_name) return True log_data = self.bot.navigation.get_log(log_name=log_name) - self.assert_not_none(log_data) + ASSERT.not_none(log_data) msg = "selenium logs, log_name={}, log_data={}".format( log_name, log_data) self.log.debug(msg) @@ -177,7 +179,7 @@ def test_getlog_lognames(self, log_name): @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_findelement_ok(self): """Testcase: test_findelement_ok""" - self.assert_is_instance( + ASSERT.is_instance( self.bot.navigation.find_element("body"), WebElement) @@ -197,7 +199,7 @@ def test_findelement_notlocator(self): @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_findelementwait_ok(self): """Testcase: test_findelementwait_ok""" - self.assert_is_instance( + ASSERT.is_instance( self.bot.navigation.find_element_wait("body"), WebElement) @@ -205,17 +207,17 @@ def test_findelementwait_ok(self): def test_findelementswait_ok(self): """Testcase: test_findelementwait_ok""" elements = self.bot.navigation.find_elements_wait("body>*") - self.assert_is_instance(elements, list) + ASSERT.is_instance(elements, list) for element in elements: - self.assert_is_instance(element, WebElement) + ASSERT.is_instance(element, WebElement) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_findelements_ok(self): """Testcase: test_findelement_ok""" elements = self.bot.navigation.find_elements("body>*") - self.assert_is_instance(elements, list) + ASSERT.is_instance(elements, list) for element in elements: - self.assert_is_instance(element, WebElement) + ASSERT.is_instance(element, WebElement) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_findelements_notfound(self): @@ -233,7 +235,7 @@ def test_findelements_notlocator(self): @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_getwindowhandle_ok(self): """Testcase: test_getwindowhandle_ok""" - self.assert_not_none( + ASSERT.not_none( self.bot.navigation.get_window_handle()) @pytest.mark.skipIf( @@ -258,7 +260,7 @@ def test_addcookie_badcookiekeys(self): @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_getcookies_ok(self): """Testcase: test_getcookies_ok""" - self.assert_is_instance( + ASSERT.is_instance( self.bot.navigation.get_cookies(), list) @@ -281,13 +283,13 @@ def test_setwindowsize_ok(self): @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_gettitle_ok(self): """Testcase: test_gettitle_ok""" - self.assert_not_none( + ASSERT.not_none( self.bot.navigation.get_title()) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_getscreenshotasbase64_ok(self): """Testcase: test_getscreenshotasbase64_ok""" - self.assert_not_none( + ASSERT.not_none( self.bot.navigation.get_screenshot_as_base64()) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) @@ -343,11 +345,11 @@ def test_findelementchild_ok(self): self.setup_login_to_data() ele_parent = self.bot.navigation.find_element_wait( self.lst_ordered.get("selector")) - self.assert_is_instance(ele_parent, WebElement) + ASSERT.is_instance(ele_parent, WebElement) ele_child = self.bot.navigation.find_element_child( ele_parent, self.lst_ordered_child.get("selector")) - self.assert_is_instance(ele_child, WebElement) - self.assert_equals( + ASSERT.is_instance(ele_child, WebElement) + ASSERT.equals( "Item list01", self.bot.navigation.ele_text(ele_child)) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) @@ -356,13 +358,13 @@ def test_findelementchildren_ok(self): self.setup_login_to_data() ele_parent = self.bot.navigation.find_element_wait( self.lst_ordered.get("selector")) - self.assert_is_instance(ele_parent, WebElement) + ASSERT.is_instance(ele_parent, WebElement) ele_children = self.bot.navigation.find_element_children( ele_parent, self.lst_ordered_child.get("selector")) - self.assert_is_instance(ele_children, list) - self.assert_greater(len(ele_children), 1) - self.assert_lower(len(ele_children), 5) - self.assert_equals( + ASSERT.is_instance(ele_children, list) + ASSERT.greater(len(ele_children), 1) + ASSERT.lower(len(ele_children), 5) + ASSERT.equals( "Item list01", self.bot.navigation.ele_text(ele_children[0])) @@ -375,7 +377,7 @@ def test_elewaitinvisible_ok(self): ele.click() # end setup ele = self.bot.navigation.ele_wait_invisible(selector, timeout=7) - self.assert_is_instance(ele, WebElement) + ASSERT.is_instance(ele, WebElement) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_elewaitvisible_ok(self): @@ -388,7 +390,7 @@ def test_elewaitvisible_ok(self): # end setup ele_visible = self.bot.navigation.ele_wait_visible( ele_invisible, timeout=7) - self.assert_is_instance(ele_visible, WebElement) + ASSERT.is_instance(ele_visible, WebElement) @pytest.mark.skipIf(SKIP_NAVS, SKIP_NAVS_MSG) def test_elewaittext_ok(self): @@ -401,8 +403,8 @@ def test_elewaittext_ok(self): # end setup is_changed = self.bot.navigation.ele_wait_text( selector_title, "Buttonss", timeout=12) - self.assert_true(is_changed) - self.assert_is_instance( + ASSERT.true(is_changed) + ASSERT.is_instance( self.bot.navigation.ele_text(ele_text), "Buttonss") @@ -416,7 +418,7 @@ def test_elewaitvalue_ok(self): # end setup is_changed = self.bot.navigation.ele_wait_value( selector, "bad_text", timeout=12) - self.assert_true(is_changed) - self.assert_is_instance( + ASSERT.true(is_changed) + ASSERT.is_instance( self.bot.navigation.ele_attribute(ele_text, "value"), "bad_text") diff --git a/tests/001_functionals/suite_005_controlbase.py b/tests/001_functionals/suite_005_controlbase.py index 0b35800b..ab9ef1fa 100644 --- a/tests/001_functionals/suite_005_controlbase.py +++ b/tests/001_functionals/suite_005_controlbase.py @@ -4,12 +4,14 @@ import pytest from qacode.core.exceptions.core_exception import CoreException +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBotUnique from qacode.core.webs.controls.control_base import ControlBase from qacode.utils import settings from selenium.webdriver.remote.webelement import WebElement +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP_CONTROLS = SETTINGS['tests']['skip']['web_controls']['control_base'] SKIP_CONTROLS_MSG = 'web_controls DISABLED by config file' @@ -112,19 +114,19 @@ def test_controlbase_instance(self, on_instance_search, auto_reload): } # functional testcases ctl = ControlBase(self.bot, **cfg) - self.assert_is_instance(ctl, ControlBase) + ASSERT.is_instance(ctl, ControlBase) # main config - self.assert_equals(ctl.selector, cfg.get('selector')) - self.assert_equals(ctl.name, cfg.get('name')) - self.assert_equals(ctl.locator, cfg.get('locator')) - self.assert_equals( + ASSERT.equals(ctl.selector, cfg.get('selector')) + ASSERT.equals(ctl.name, cfg.get('name')) + ASSERT.equals(ctl.locator, cfg.get('locator')) + ASSERT.equals( ctl.on_instance_search, cfg.get('on_instance_search')) - self.assert_equals(ctl.auto_reload, cfg.get('auto_reload')) + ASSERT.equals(ctl.auto_reload, cfg.get('auto_reload')) if on_instance_search: - self.assert_is_instance(ctl.element, WebElement) - self.assert_equals(ctl.tag, tag_name) + ASSERT.is_instance(ctl.element, WebElement) + ASSERT.equals(ctl.tag, tag_name) else: - self.assert_none(ctl.element) + ASSERT.none(ctl.element) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_controlbase_instance_raises(self): @@ -145,7 +147,7 @@ def test_property_gettext(self): cfg_btn = self.btn_submit.copy() cfg_btn.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_btn) - self.assert_equals(control.text, 'Login') + ASSERT.equals(control.text, 'Login') @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_gettext(self): @@ -153,7 +155,7 @@ def test_method_gettext(self): cfg_btn = self.btn_submit.copy() cfg_btn.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_btn) - self.assert_equals(control.get_text(), 'Login') + ASSERT.equals(control.get_text(), 'Login') @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_property_attr_id(self): @@ -161,7 +163,7 @@ def test_property_attr_id(self): cfg_input = self.txt_username.copy() cfg_input.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_input) - self.assert_not_none(control.attr_id) + ASSERT.not_none(control.attr_id) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_property_attr_class(self): @@ -169,7 +171,7 @@ def test_property_attr_class(self): cfg_form = self.form_login.copy() cfg_form.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_form) - self.assert_in('ember-view', control.attr_class) + ASSERT.in_list('ember-view', control.attr_class) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_getattrvalue(self): @@ -177,7 +179,7 @@ def test_method_getattrvalue(self): cfg_form = self.form_login.copy() cfg_form.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_form) - self.assert_not_none(control.get_attr_value('id')) + ASSERT.not_none(control.get_attr_value('id')) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_get_attrs(self): @@ -186,10 +188,10 @@ def test_method_get_attrs(self): cfg_form.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_form) attrs = control.get_attrs(['id', 'class']) - self.assert_equals(attrs[0]['name'], 'id') - self.assert_equals(attrs[0]['value'], 'frmLogin') - self.assert_equals(attrs[1]['name'], 'class') - self.assert_in('ember-view', attrs[1]['value']) + ASSERT.equals(attrs[0]['name'], 'id') + ASSERT.equals(attrs[0]['value'], 'frmLogin') + ASSERT.equals(attrs[1]['name'], 'class') + ASSERT.in_list('ember-view', attrs[1]['value']) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_property_tag(self): @@ -197,7 +199,7 @@ def test_property_tag(self): cfg_form = self.form_login.copy() cfg_form.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_form) - self.assert_equals(control.tag, 'form') + ASSERT.equals(control.tag, 'form') @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) @pytest.mark.parametrize("retry", [False, True]) @@ -222,8 +224,8 @@ def test_method_typetext(self, control_config, clear): ctl_config.update(control_config) control = ControlBase(self.bot, **ctl_config) control.type_text(text_to_type, clear=clear) - self.assert_equals(control.text, text_to_type) - self.assert_equals(control.get_attr_value('value'), text_to_type) + ASSERT.equals(control.text, text_to_type) + ASSERT.equals(control.get_attr_value('value'), text_to_type) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_getcssvalue(self): @@ -231,7 +233,7 @@ def test_method_getcssvalue(self): cfg_input = self.txt_username.copy() cfg_input.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_input) - self.assert_equals( + ASSERT.equals( control.get_css_value('color'), 'rgba(73, 80, 87, 1)') @@ -243,7 +245,7 @@ def test_method_setcssrule(self): control = ControlBase(self.bot, **cfg_input) control.type_text('test') control.set_css_value('color', 'red') - self.assert_equals( + ASSERT.equals( control.get_css_value('color'), 'rgba(255, 0, 0, 1)') @@ -256,7 +258,7 @@ def test_method_gettext_onscreenfalse(self): control = ControlBase(self.bot, **cfg_btn) control.set_css_value('display', 'none') text = control.get_text(on_screen=False) - self.assert_greater(len(text), 0, msg=msg_err) + ASSERT.greater(len(text), 0, msg=msg_err) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) @pytest.mark.parametrize("selector", ["#txtUsername-field"]) @@ -272,13 +274,13 @@ def test_method_reload_base(self, selector, instance): "on_instance_search": False, } control = ControlBase(self.bot, **cfg_base) - self.assert_equals(control.on_instance_search, False) - self.assert_none(control.element) + ASSERT.equals(control.on_instance_search, False) + ASSERT.none(control.element) # Real test behaviour cfg_base.update({"on_instance_search": True}) control.reload(**cfg_base) - self.assert_equals(control.on_instance_search, True) - self.assert_is_instance(control.element, WebElement) + ASSERT.equals(control.on_instance_search, True) + ASSERT.is_instance(control.element, WebElement) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_findchild(self): @@ -287,8 +289,8 @@ def test_method_findchild(self): control = ControlBase(self.bot, **self.lst_ordered) selector_child = self.lst_ordered_child.get("selector") ctl_child = control.find_child(selector_child) - self.assert_is_instance(ctl_child, ControlBase) - self.assert_is_instance(ctl_child.element, WebElement) + ASSERT.is_instance(ctl_child, ControlBase) + ASSERT.is_instance(ctl_child.element, WebElement) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_findchildren(self): @@ -297,10 +299,10 @@ def test_method_findchildren(self): control = ControlBase(self.bot, **self.lst_ordered) selector_child = self.lst_ordered_child.get("selector") children = control.find_children(selector_child) - self.assert_lower(len(children), 5) + ASSERT.lower(len(children), 5) for ctl_child in children: - self.assert_is_instance(ctl_child, ControlBase) - self.assert_is_instance(ctl_child.element, WebElement) + ASSERT.is_instance(ctl_child, ControlBase) + ASSERT.is_instance(ctl_child.element, WebElement) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_waitinvisible(self): @@ -310,8 +312,8 @@ def test_method_waitinvisible(self): ctl = ControlBase(self.bot, **self.btn_click_invisible) ctl.click() ctl_invisible = ctl.wait_invisible(timeout=7) - self.assert_is_instance(ctl_invisible, ControlBase) - self.assert_is_instance(ctl_invisible.element, WebElement) + ASSERT.is_instance(ctl_invisible, ControlBase) + ASSERT.is_instance(ctl_invisible.element, WebElement) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_waitvisible(self): @@ -321,8 +323,8 @@ def test_method_waitvisible(self): # end setup ctl = ControlBase(self.bot, **self.btn_click_visible) ctl_visible = ctl.wait_visible(timeout=7) - self.assert_is_instance(ctl_visible, ControlBase) - self.assert_is_instance(ctl_visible.element, WebElement) + ASSERT.is_instance(ctl_visible, ControlBase) + ASSERT.is_instance(ctl_visible.element, WebElement) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_method_waitblink(self): @@ -332,8 +334,8 @@ def test_method_waitblink(self): ctl.click() # end setup ctl_blink = ctl.wait_blink(timeout=7) - self.assert_is_instance(ctl_blink, ControlBase) - self.assert_is_instance(ctl_blink.element, WebElement) + ASSERT.is_instance(ctl_blink, ControlBase) + ASSERT.is_instance(ctl_blink.element, WebElement) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) @pytest.mark.parametrize( @@ -351,5 +353,5 @@ def test_method_waittext(self, ctl_cfg): # end setup ctl = ControlBase(self.bot, **getattr(self, ctl_cfg[0])) ctl.reload() - self.assert_true(ctl.wait_text(ctl_cfg[1], timeout=7)) - self.assert_equals(ctl.text, ctl_cfg[1]) + ASSERT.true(ctl.wait_text(ctl_cfg[1], timeout=7)) + ASSERT.equals(ctl.text, ctl_cfg[1]) diff --git a/tests/001_functionals/suite_007_controldropdown.py b/tests/001_functionals/suite_007_controldropdown.py index 511c570f..0d80b1bc 100644 --- a/tests/001_functionals/suite_007_controldropdown.py +++ b/tests/001_functionals/suite_007_controldropdown.py @@ -4,6 +4,7 @@ import pytest from qacode.core.exceptions.control_exception import ControlException +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBotUnique from qacode.core.webs.controls.control_dropdown import ControlDropdown from qacode.utils import settings @@ -11,6 +12,7 @@ from selenium.webdriver.support.ui import Select +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP_CONTROLS = SETTINGS['tests']['skip']['web_controls']['control_dropdown'] SKIP_CONTROLS_MSG = 'web_controls DISABLED by config file' @@ -92,19 +94,19 @@ def test_controldropdown_instance(self, on_instance_search, }) # functional testcases ctl = ControlDropdown(self.bot, **cfg) - self.assert_is_instance(ctl, ControlDropdown) - self.assert_equals(ctl.selector, cfg.get('selector')) - self.assert_equals(ctl.name, cfg.get('name')) - self.assert_equals(ctl.locator, 'css selector') - self.assert_equals( + ASSERT.is_instance(ctl, ControlDropdown) + ASSERT.equals(ctl.selector, cfg.get('selector')) + ASSERT.equals(ctl.name, cfg.get('name')) + ASSERT.equals(ctl.locator, 'css selector') + ASSERT.equals( ctl.on_instance_search, cfg.get('on_instance_search')) - self.assert_equals(ctl.auto_reload, cfg.get('auto_reload')) + ASSERT.equals(ctl.auto_reload, cfg.get('auto_reload')) if on_instance_search: - self.assert_is_instance(ctl.element, WebElement) + ASSERT.is_instance(ctl.element, WebElement) if auto_reload is not None: - self.assert_none(ctl.dropdown) + ASSERT.none(ctl.dropdown) ctl.reload(**ctl.settings) - self.assert_is_instance(ctl.dropdown, Select) + ASSERT.is_instance(ctl.dropdown, Select) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) @pytest.mark.parametrize("auto_reload", [True, False]) @@ -117,15 +119,15 @@ def test_method_reload_form(self, auto_reload): "on_instance_search": False, }) ctl = ControlDropdown(self.bot, **cfg) - self.assert_equals(ctl.on_instance_search, False) - self.assert_none(ctl.element) - self.assert_none(ctl.dropdown) + ASSERT.equals(ctl.on_instance_search, False) + ASSERT.none(ctl.element) + ASSERT.none(ctl.dropdown) # Real test behaviour cfg.update({"on_instance_search": True}) ctl.reload(**cfg) - self.assert_equals(ctl.on_instance_search, True) - self.assert_is_instance(ctl.element, WebElement) - self.assert_is_instance(ctl.dropdown, Select) + ASSERT.equals(ctl.on_instance_search, True) + ASSERT.is_instance(ctl.element, WebElement) + ASSERT.is_instance(ctl.dropdown, Select) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) @pytest.mark.parametrize("text", ["Link 1.1", "Link 1.2"]) @@ -206,7 +208,7 @@ def test_method_deselect_notdropdown(self, text): control.select(text) control.dropdown = None control.deselect(text) - self.assert_is_instance(control.dropdown, Select) + ASSERT.is_instance(control.dropdown, Select) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) @pytest.mark.parametrize("text", ["Link 1.1"]) @@ -270,4 +272,4 @@ def test_method_deselect_all_notdropdown(self): control.select(text) control.dropdown = None control.deselect_all() - self.assert_is_instance(control.dropdown, Select) + ASSERT.is_instance(control.dropdown, Select) diff --git a/tests/001_functionals/suite_008_controltable.py b/tests/001_functionals/suite_008_controltable.py index 9013822b..8966583d 100644 --- a/tests/001_functionals/suite_008_controltable.py +++ b/tests/001_functionals/suite_008_controltable.py @@ -3,6 +3,7 @@ import pytest +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBotUnique from qacode.core.webs.controls.control_base import ControlBase from qacode.core.webs.controls.control_table import ControlTable @@ -10,6 +11,7 @@ from selenium.webdriver.remote.webelement import WebElement +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP_CONTROLS = SETTINGS['tests']['skip']['web_controls']['control_table'] SKIP_CONTROLS_MSG = 'web_controls DISABLED by config file' @@ -112,30 +114,30 @@ def test_controltable_instance(self, on_instance_search, }) # functional testcases ctl = ControlTable(self.bot, **cfg) - self.assert_is_instance(ctl, ControlTable) - self.assert_equals(ctl.selector, cfg.get('selector')) - self.assert_equals(ctl.name, cfg.get('name')) - self.assert_equals(ctl.locator, 'css selector') - self.assert_equals( + ASSERT.is_instance(ctl, ControlTable) + ASSERT.equals(ctl.selector, cfg.get('selector')) + ASSERT.equals(ctl.name, cfg.get('name')) + ASSERT.equals(ctl.locator, 'css selector') + ASSERT.equals( ctl.on_instance_search, cfg.get('on_instance_search')) - self.assert_equals(ctl.auto_reload, cfg.get('auto_reload')) + ASSERT.equals(ctl.auto_reload, cfg.get('auto_reload')) if on_instance_search: - self.assert_is_instance(ctl.element, WebElement) + ASSERT.is_instance(ctl.element, WebElement) if auto_reload is not None: - self.assert_none(ctl.table) + ASSERT.none(ctl.table) ctl.reload(**ctl.settings) - self.assert_is_instance(ctl.table, ControlBase) - self.assert_is_instance(ctl.rows, list) + ASSERT.is_instance(ctl.table, ControlBase) + ASSERT.is_instance(ctl.rows, list) # Use case 1. not html5:: TABLE > (TR > TH)+(TR > TD) # Use case 2. html5:: TABLE > (THEAD > (TR > TH))+(TBODY > (TR > TH)) # Use case 3. html5:: TABLE > # (THEAD > (TR > TH))+[(TBODY > (TR > TH))] - self.assert_lower(len(ctl.rows), rows) + ASSERT.lower(len(ctl.rows), rows) for row in ctl.rows: - self.assert_is_instance(row, list) - self.assert_lower(len(row), cols) + ASSERT.is_instance(row, list) + ASSERT.lower(len(row), cols) for cell in row: - self.assert_is_instance(cell, ControlBase) + ASSERT.is_instance(cell, ControlBase) @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) @pytest.mark.parametrize("ctl_name", ['tbl_ok', 'tbl_html5_ok']) @@ -145,10 +147,10 @@ def test_controltable_instance_raises(self, ctl_name): cfg.update({"selector": "span"}) # functional testcases ctl = ControlTable(self.bot, **cfg) - self.assert_is_instance(ctl, ControlTable) - self.assert_equals(ctl.selector, cfg.get('selector')) - self.assert_equals(ctl.name, cfg.get('name')) - self.assert_equals(ctl.locator, 'css selector') + ASSERT.is_instance(ctl, ControlTable) + ASSERT.equals(ctl.selector, cfg.get('selector')) + ASSERT.equals(ctl.name, cfg.get('name')) + ASSERT.equals(ctl.locator, 'css selector') @pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG) def test_controltable_internals_ok(self): @@ -164,5 +166,5 @@ def test_controltable_properties_ok(self): rows_before = len(ctl.rows) ctl.table = ctl.element rows_after = len(ctl.rows) - self.assert_is_instance(ctl.table, ControlBase) - self.assert_equals(rows_before, rows_after) + ASSERT.is_instance(ctl.table, ControlBase) + ASSERT.equals(rows_before, rows_after) diff --git a/tests/001_functionals/suite_009_pagebase.py b/tests/001_functionals/suite_009_pagebase.py index 487dad55..b8e8a925 100644 --- a/tests/001_functionals/suite_009_pagebase.py +++ b/tests/001_functionals/suite_009_pagebase.py @@ -3,12 +3,14 @@ import pytest +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBotUnique from qacode.core.webs.controls.control_base import ControlBase from qacode.core.webs.pages.page_base import PageBase from qacode.utils import settings +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP_PAGES = SETTINGS['tests']['skip']['web_pages'] SKIP_PAGES_MSG = 'web_pages DISABLED by config file' @@ -58,8 +60,8 @@ def test_instance_url(self): "go_url": True }) page = PageBase(self.bot, **cfg) - self.assert_is_instance(page, PageBase) - self.assert_equals_url( + ASSERT.is_instance(page, PageBase) + ASSERT.equals( self.bot.curr_driver.current_url, self.page.get('url')) @@ -68,29 +70,27 @@ def test_instance_notgourl(self): """Testcase: test_002_instance_notgourl""" cfg = self.page.copy() cfg.update({ - "go_url": False, - "controls": [] + "go_url": False, "controls": [] }) page = PageBase(self.bot, **cfg) - self.assert_is_instance(page, PageBase) - self.assert_not_equals_url( - self.bot.curr_driver.current_url, - cfg.get('url')) + ASSERT.is_instance(page, PageBase) + ASSERT.not_equals( + self.bot.curr_driver.current_url, cfg.get('url')) @pytest.mark.skipIf(SKIP_PAGES, SKIP_PAGES_MSG) def test_instance_element(self): """Testcase: test_003_instance_element""" cfg = self.page.copy() page = PageBase(self.bot, **cfg) - self.assert_is_instance(page, PageBase) - self.assert_equals_url( + ASSERT.is_instance(page, PageBase) + ASSERT.equals( self.bot.curr_driver.current_url, cfg.get('url')) for control in self.page.get('controls'): name = control.get('name') - self.assert_in(name, dir(page)) + ASSERT.in_list(name, dir(page)) element = page.__dict__[name] - self.assert_is_instance(element, ControlBase) + ASSERT.is_instance(element, ControlBase) @pytest.mark.skipIf(SKIP_PAGES, SKIP_PAGES_MSG) def test_instance_maximized(self): @@ -102,8 +102,8 @@ def test_instance_maximized(self): "controls": [] }) page = PageBase(self.bot, **cfg) - self.assert_is_instance(page, PageBase) - self.assert_equals_url( + ASSERT.is_instance(page, PageBase) + ASSERT.equals( self.bot.curr_driver.current_url, cfg.get('url')) @@ -112,14 +112,14 @@ def test_method_getelement(self): """Testcase: test_004_instance_maximized""" cfg = self.page.copy() page = PageBase(self.bot, **cfg) - self.assert_is_instance(page, PageBase) - self.assert_equals_url( + ASSERT.is_instance(page, PageBase) + ASSERT.equals( self.bot.curr_driver.current_url, cfg.get('url')) for config_control in self.page.get('controls'): name = config_control.get('name') instance_name = config_control.get('instance') ctl = page.get_element(config_control) - self.assert_in(name, dir(page)) + ASSERT.in_list(name, dir(page)) if instance_name == 'ControlBase': - self.assert_is_instance(ctl, ControlBase) + ASSERT.is_instance(ctl, ControlBase) diff --git a/tests/002_benchmarks/suite_001_browsers.py b/tests/002_benchmarks/suite_001_browsers.py index e61fb8b1..7327d3b3 100644 --- a/tests/002_benchmarks/suite_001_browsers.py +++ b/tests/002_benchmarks/suite_001_browsers.py @@ -5,10 +5,12 @@ import pytest from qacode.core.bots.bot_base import BotBase from qacode.core.loggers.logger_manager import Log +from qacode.core.testing.asserts import Assert from qacode.core.testing.test_info import TestInfoBase from qacode.utils import settings +ASSERT = Assert() SETTINGS = settings(file_path="qacode/configs/") SKIP = SETTINGS['tests']['skip']['benchmarks'] SKIP_MSG = 'benchmarks DISABLED by config file' @@ -48,12 +50,12 @@ def bot_benchmark(self, browser_name, driver_mode, is_headless): if browser_name == 'iexplorer': browser_name = 'internet explorer' self.bot = BotBase(**settings) - self.assert_is_instance(self.bot, BotBase) - self.assert_equals( + ASSERT.is_instance(self.bot, BotBase) + ASSERT.equals( self.bot.settings.get('browser'), settings.get('bot').get('browser')) - self.assert_equals(self.bot.settings.get('mode'), driver_mode) - self.assert_equals(self.bot.curr_caps['browserName'], browser_name) + ASSERT.equals(self.bot.settings.get('mode'), driver_mode) + ASSERT.equals(self.bot.curr_caps['browserName'], browser_name) try: if self.bot: self.bot.close() diff --git a/tests/testing/__init__.py b/tests/testing/__init__.py new file mode 100644 index 00000000..dbfb5f0b --- /dev/null +++ b/tests/testing/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +"""package tests.testing""" diff --git a/tests/testing/suite_asserts.py b/tests/testing/suite_asserts.py new file mode 100644 index 00000000..059dbe21 --- /dev/null +++ b/tests/testing/suite_asserts.py @@ -0,0 +1,133 @@ +# -*- coding: utf-8 -*- +"""Test Suite module for qacode.core.bots package""" + + +import pytest +from qacode.core.testing.asserts import (ASSERT_REGEX_URL, Assert) + + +@pytest.mark.dependency(name="asserts_create") +def test_asserts_create(): + """TODO: doc method""" + assert type(Assert()) == Assert + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_equals(): + """TODO: doc method""" + Assert().equals("equals", "equals") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notequals(): + """TODO: doc method""" + Assert().not_equals("equals", "notequals") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_containsurl(): + """TODO: doc method""" + Assert().contains_url("http://equals.com", "equals.com") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notcontainsurl(): + """TODO: doc method""" + Assert().not_contains_url("http://equals.com", "notcontains") + + +@pytest.mark.dependency(depends=['asserts_create']) +@pytest.mark.parametrize("class_type", [str, " "]) +def test_asserts_isinstance(class_type): + """TODO: doc method""" + Assert().is_instance("text", class_type) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_greaterorequals(): + """TODO: doc method""" + Assert().greater_or_equals(1, 0) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_lowerorequals(): + """TODO: doc method""" + Assert().lower_or_equals(0, 1) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_greater(): + """TODO: doc method""" + Assert().greater(1, 0) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_lower(): + """TODO: doc method""" + Assert().lower(0, 1) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_inlist(): + """TODO: doc method""" + Assert().in_list(0, [0, 1]) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notinlist(): + """TODO: doc method""" + Assert().not_in_list(0, [1, 2]) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_regex(): + """TODO: doc method""" + Assert().regex("https://netzulo.tk:83", ASSERT_REGEX_URL) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notregex(): + """TODO: doc method""" + Assert().not_regex("htttp://lol", ASSERT_REGEX_URL) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_regexurl(): + """TODO: doc method""" + Assert().regex_url("https://netzulo.tk:83") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_pathexist(): + """TODO: doc method""" + Assert().path_exist("./") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_pathnotexist(): + """TODO: doc method""" + Assert().path_not_exist("doesnotexist/") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_true(): + """TODO: doc method""" + Assert().true(True) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_false(): + """TODO: doc method""" + Assert().false(False) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_none(): + """TODO: doc method""" + Assert().none(None) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notnone(): + """TODO: doc method""" + Assert().not_none(":)") \ No newline at end of file diff --git a/tests/testing/suite_asserts_raises.py b/tests/testing/suite_asserts_raises.py new file mode 100644 index 00000000..82ffc9c4 --- /dev/null +++ b/tests/testing/suite_asserts_raises.py @@ -0,0 +1,154 @@ +# -*- coding: utf-8 -*- +"""Test Suite module for qacode.core.bots package""" + + +import pytest +from qacode.core.testing.asserts import (ASSERT_REGEX_URL, Assert) + + +@pytest.mark.dependency(name="asserts_create") +def test_asserts_create(): + """TODO: doc method""" + asserts = Assert() + assert type(asserts) == Assert + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_equals_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().equals("equals", "notequals") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notequals_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().not_equals("equals", "equals") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_containsurl_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().contains_url("http://equals.com", "notcontains") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notcontainsurl_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().not_contains_url("http://equals.com", "equals.com") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_isinstance_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().is_instance("text", int) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_greater_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().greater(0, 1) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_lower_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().lower(1, 0) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_greaterorequals_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().greater_or_equals(0, 1) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_lowerorequals_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().lower_or_equals(1, 0) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_inlist_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().in_list(0, [1, 2]) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notinlist_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().not_in_list(1, [1, 2]) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_regex_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().regex("doesnotexist", ASSERT_REGEX_URL) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notregex_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().not_regex("http://netzulo.tk:83", ASSERT_REGEX_URL) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_regexurl_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().regex_url("noturl") + + +@pytest.mark.dependency(depends=['asserts_create']) +@pytest.mark.parametrize("path", ["doesnotexist", "logs/qacode.log"]) +def test_asserts_pathexist_raises(path): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().path_exist(path) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_pathnotexist_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().path_not_exist("./") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_true_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().true(False) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_false_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().false(True) + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_none_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().none(":)") + + +@pytest.mark.dependency(depends=['asserts_create']) +def test_asserts_notnone_raises(): + """TODO: doc method""" + with pytest.raises(AssertionError): + Assert().not_none(None) \ No newline at end of file