import logging import random import string import time import traceback from .logger import Logger class AssertUtils(object): log = Logger(logging.DEBUG) def sleep(self, sec, info=""): if info is not None: self.log.info("Wait :: " + str(sec) + " seconds for " + info) try: time.sleep(sec) except Exception: traceback.print_stack() def get_alpha_numeric(self, length, _type="letters"): """ Get random string of characters :param length: Length of string, number of characters string should have :param type: Type of character string should have. Default is letters Provide lower/upper/digits for different types """ if _type == "lower": case = string.ascii_lowercase elif _type == "upper": case = string.ascii_uppercase elif _type == "digits": case = string.digits elif _type == "mix": case = string.ascii_letters + string.digits else: case = string.ascii_letters return "".join(random.choice(case) for _ in range(length)) def get_unique_name(self, charCount=10): return self.get_alpha_numeric(charCount, "lower") def get_unique_name_list(self, listSize=5, itemLength=None): nameList = [] for i in range(0, listSize): nameList.append(self.get_unique_name(itemLength[i])) return nameList def verify_list_match(self, expectedList, actualList): return set(expectedList) == set(actualList) def verify_list_contains(self, expectedList, actualList): length = len(expectedList) for i in range(0, length): if expectedList[i] not in actualList: return False return True def verify_text_contains(self, actualText, expectedText): self.log.info("Actual Text From Application Web UI --> :: " + actualText) self.log.info("Expected Text From Application Web UI --> :: " + expectedText) if expectedText.lower() in actualText.lower(): self.log.info("### VERIFICATIONS CONTAINS !!!") return True self.log.error("### VERIFICATIONS DO NOT CONTAINS !!!") def verify_text_match(self, actualText, expectedText): self.log.info("Actual Text From Application Web UI --> :: " + actualText) self.log.info("Expected Text From Application Web UI --> :: " + expectedText) if expectedText.lower() == actualText.lower(): self.log.info("### VERIFICATIONS MATCHED !!!") return True self.log.error("### VERIFICATIONS DO NOT MATCHED !!!") def are_lists_equal(self, db_values, ui_values): for i in range(len(db_values)): self.log.info("DB value: " + str(db_values[i]) + " UI Value: " + str(ui_values[i])) if int(ui_values[i]) != int(db_values[i]): return False return True def are_same_values_in_lists(self, list_1, list_2): for value_1 in list_1: for value_2 in list_2: if value_1 == value_2: self.log.info("value 1: " + value_1 + " value_2: " + value_2) return False return True