def __multi_confs_file(cls, *, file_path, creation_context): yaml = Yaml.from_file(file_path, allow_any=True) conf_map = dict() if yaml is not None: for section_name in yaml.section_names: conf_map[section_name] = cls.from_yaml(yaml_obj=yaml.get_section(section_name), creation_context=f"Section {section_name} in {creation_context}", conf_stage=ConfigStage.REFERENCE) return conf_map
def __load_sessions_file(cls): from arjuna import C if cls.__SESSIONS_YAML is None: cls.SESSIONS_YAML_FILE = C(ArjunaOption.CONF_SESSIONS_FILE) try: cls.__SESSIONS_YAML = Yaml.from_file(cls.SESSIONS_YAML_FILE) except FileNotFoundError as e: raise TestSessionsFileNotFoundError(cls.SESSIONS_YAML_FILE)
def load_desc(cls): if cls.ARJUNA_OPTIONS_DESC_MAP is not None: return my_dir = os.path.dirname(os.path.realpath(__file__)) desc_file = os.path.abspath(os.path.join(my_dir, "..", "res", "arjuna_conf_desc.yaml")) creation_context=f"This Yaml represents arjuna_conf_desc.yaml configuration file at {desc_file} that describes rules for Arjuna's built-in options." desc_yaml = Yaml.from_file(desc_file) cls.ARJUNA_OPTIONS_DESC_MAP = {cls.process_arjuna_option_name(k): v for k, v in desc_yaml.as_map().items()}
def __load_groups_file(cls): from arjuna import C if cls.__GROUPS_YAML is None: cls.GROUPS_YAML_FILE = C(ArjunaOption.CONF_GROUPS_FILE) try: cls.__GROUPS_YAML = Yaml.from_file(cls.GROUPS_YAML_FILE) except FileNotFoundError: raise TestGroupsFileNotFoundError(cls.GROUPS_YAML_FILE)
def __load_stages_file(cls): from arjuna import C if cls.__STAGES_YAML is None: cls.STAGES_YAML_FILE = C(ArjunaOption.CONF_STAGES_FILE) try: cls.__STAGES_YAML = Yaml.from_file(cls.STAGES_YAML_FILE) except FileNotFoundError: raise TestStagesFileNotFoundError(cls.STAGES_YAML_FILE)
def __load_sessions_file(cls): from arjuna import C if cls.__SESSIONS_YAML is None: cls.SESSIONS_YAML_FILE = C(ArjunaOption.CONF_SESSIONS_LOCAL_FILE) if not os.path.isfile(cls.SESSIONS_YAML_FILE): cls.SESSIONS_YAML_FILE = C(ArjunaOption.CONF_SESSIONS_FILE) try: cls.__SESSIONS_YAML = Yaml.from_file(cls.SESSIONS_YAML_FILE, allow_any=True) except FileNotFoundError as e: raise TestSessionsFileNotFoundError(file_path=cls.SESSIONS_YAML_FILE)
def __load_groups_file(cls): from arjuna import C if cls.__GROUPS_YAML is None: cls.GROUPS_YAML_FILE = C(ArjunaOption.CONF_GROUPS_LOCAL_FILE) if not os.path.isfile(cls.GROUPS_YAML_FILE): cls.GROUPS_YAML_FILE = C(ArjunaOption.CONF_GROUPS_FILE) try: cls.__GROUPS_YAML = Yaml.from_file(cls.GROUPS_YAML_FILE, allow_any=True) except FileNotFoundError: raise TestGroupsFileNotFoundError(file_path=cls.GROUPS_YAML_FILE)
def __get_group_yaml(cls, name): from arjuna import C gfile = C(ArjunaOption.CONF_GROUPS_LOCAL_FILE) if not os.path.isfile(gfile): gfile = C(ArjunaOption.CONF_GROUPS_FILE) try: gyaml = Yaml.from_file(gfile, allow_any=True) except FileNotFoundError: raise TestGroupsFileNotFoundError(file_path=gfile) try: return gyaml.get_section(name) except YamlUndefinedSectionError as e: raise UndefinedTestGroupError(name=name, file_path=gfile)
def __init__(self, path): self.path = path self.__name = get_file_name(path) if (path.lower().endswith("yaml")): self.__node = Yaml.from_file(path) else: raise Exception("Unsupported file format for Excel reading.") map = dict() for index, record in enumerate(self.__node): map[index] = DataRecord(context="Ref-{}[{}]".format( self.__name, index), **dict(record.items())) super().__init__(map)
def init(self, project_root_dir, cli_config, run_id, *, static_rid): from arjuna.configure.options import ArjunaOptions ArjunaOptions.load_desc() self.__project_root_dir = project_root_dir from arjuna.engine.controller import TestSessionController self.__test_session = TestSessionController() run_id = run_id and run_id or "mrun" prefix = "" if not static_rid: prefix = "{}-".format( datetime.datetime.now().strftime("%Y.%m.%d-%H.%M.%S.%f")[:-3]) run_id = "{}{}".format(prefix, run_id) self.__thread_wise_ref_conf_map[ threading.currentThread().name] = self.__test_session.init( project_root_dir, cli_config, run_id) from arjuna.tpi.constant import ArjunaOption self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.REPORT_DIR)) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.REPORT_XML_DIR)) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.REPORT_HTML_DIR)) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.LOG_DIR)) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.SCREENSHOTS_DIR)) from arjuna.engine.logger import Logger self.__logger = Logger(self.ref_config) from arjuna import ArjunaOption self.__allowed_log_contexts = self.ref_config.value( ArjunaOption.LOG_ALLOWED_CONTEXTS) from arjuna.tpi.hook.config import Configurator configurator = Configurator() # Load configs from config hooks hooks_dir = self.ref_config.value(ArjunaOption.HOOKS_DIR) if os.path.isdir(hooks_dir): sys.path.append(hooks_dir) try: from arjuna_config import register_ref_confs except ModuleNotFoundError as e: # Module not defined. pass except ImportError as f: # Hook not defined pass else: register_ref_confs(configurator) deps_dir = self.ref_config.value(ArjunaOption.DEPS_DIR) if os.path.isdir(deps_dir): sys.path.append(deps_dir) # Load data references from arjuna.engine.data.factory import DataReference self.__contextual_data_references, self.__indexed_data_references = DataReference.load_all( self.ref_config) # Load localization data from arjuna.engine.data.localizer import Localizer self.__localizer = Localizer.load_all(self.ref_config) from arjuna.tpi.parser.yaml import Yaml from arjuna.interact.gui.auto.finder.withx import WithX fpath = self.ref_config.value(ArjunaOption.CONF_WITHX_FILE) creation_context = f"WithX.yaml file at {fpath}" if os.path.isfile(fpath): wyaml = Yaml.from_file(fpath, allow_any=True) if wyaml is not None: self.__common_withx_ref = WithX(wyaml.as_map()) self.__start_bmproxy(self.ref_config) return self.ref_config
def __init__(self, path): if (path.lower().endswith("yaml")): self.__node = Yaml.from_file(path) else: raise Exception("Unsupported file format for Excel reading.") super().__init__(path)
def load(self): from arjuna import Arjuna, log_debug from arjuna.configure.validator import Validator from arjuna.interact.gui.auto.finder._with import WithType from arjuna.tpi.parser.yaml import Yaml creation_context="Gui Namespace file at {}".format(self.__ns_path) yaml = Yaml.from_file(self.__ns_path, allow_any=True) if yaml is None: return if not yaml.has_section("labels"): # print("No labels configured. Skipping...") return from arjuna.interact.gui.auto.finder.withx import WithX if yaml.has_section("withx"): self.__withx = WithX(yaml.get_section("withx").as_map()) else: self.__withx = WithX() common_withx = Arjuna.get_withx_ref() for label, label_map in yaml.get_section("labels").as_map().items(): Validator.name(label) self.__ns[label.lower()] = {"locators" : {self.__context: []}, "meta": dict()} for loc, loc_obj in label_map.items(): loc = loc.lower() wtype, wvalue = None, None if not self.__withx.has_locator(loc) and not common_withx.has_locator(loc): wtype, wvalue = loc.upper(), loc_obj if wtype in dir(WithType): iloc = ImplWith(wtype=wtype, wvalue=wvalue, has_content_locator=False) self.__ns[label.lower()]["locators"][self.__context].append(iloc) else: self.__ns[label.lower()]["meta"][wtype.lower()] = wvalue else: if self.__withx.has_locator(loc): wx = self.__withx elif common_withx.has_locator(loc): wx = common_withx else: raise Exception("No WithX locator with name {} found. Check GNS file at {}.".format(name, self.__ns_path)) wtype, wvalue = wx.format(loc, loc_obj) iloc = ImplWith(wtype=wtype, wvalue=wvalue, has_content_locator=False) self.__ns[label.lower()]["locators"][self.__context].append(iloc) if not self.__ns[label.lower()]["locators"][self.__context]: raise Exception("No locators defined for label: {}".format(label)) if yaml.has_section("load"): self.__load_targets = yaml.get_section("load").as_map() if "root" in self.__load_targets: self.__ns["__root__"] = self.__load_targets["root"].lower() else: self.__ns["__root__"] = None if "anchor" in self.__load_targets: self.__ns["__anchor__"] = self.__load_targets["anchor"].lower() else: self.__ns["__anchor__"] = None else: self.__ns["__root__"] = None self.__ns["__anchor__"] = None for ename, wmd in self.__ns.items(): if ename not in {'__root__', '__anchor__'}: context_data = wmd["locators"] for context, locators in context_data.items(): self.add_element_meta_data(ename, context, locators, wmd["meta"]) log_debug("Loading {} label for {} context with locators: {} and meta {}.".format(ename, context, [str(l) for l in locators], wmd["meta"])) self.add_reference("__root__", self.__ns["__root__"]) self.add_reference("__anchor__", self.__ns["__anchor__"])
def init(self, project_root_dir, cli_config, run_id, *, static_rid, linked_projects): from arjuna.configure.options import ArjunaOptions ArjunaOptions.load_desc() self.__project_root_dir = project_root_dir from arjuna.engine.controller import TestSessionController self.__test_session = TestSessionController() run_id = run_id and run_id or "mrun" prefix = "" if not static_rid: prefix = "{}-".format( datetime.datetime.now().strftime("%Y.%m.%d-%H.%M.%S.%f")[:-3]) run_id = "{}{}".format(prefix, run_id) # Process linked Arjuna projects def get_arjuna_project_path_and_name(fpath): from arjuna.core.utils import file_utils if not file_utils.is_absolute_path(fpath): fpath = os.path.abspath(os.path.join(project_root_dir, fpath)) if not file_utils.is_dir(fpath): if file_utils.is_file(fpath): raise Exception( "The Linked Arjuna Project path is a file. It should be a directory: {}" .format(fpath)) else: raise Exception( "The Linked Arjuna Project path does not exist: {}". format(fpath)) else: if not os.path.exists( os.path.join(fpath, "script", "arjuna_launcher.py")): raise Exception( "The Linked Arjuna Project path exists but is not an Arjuna test project: {}" .format(fpath)) return os.path.basename(fpath), fpath, os.path.abspath(fpath + "/..") self.__linked_projects = list() linked_project_dict = dict() from arjuna.tpi.constant import ArjunaOption unique_paths = list() for arjuna_proj_dir in linked_projects: proj_name, proj_path, proj_import_path = get_arjuna_project_path_and_name( arjuna_proj_dir) from arjuna.configure.configurator import TestConfigurator l_proj_configurator = TestConfigurator(proj_path, cli_config, run_id) ref_conf_editable = l_proj_configurator.ref_config ref_conf = self.__test_session._create_config(ref_conf_editable) data_env_conf_map = l_proj_configurator.file_confs #for run_env_conf in [self.__test_session._create_config(econf, name=name) for name, econf in l_proj_configurator.file_confs.items()]: # data_env_conf_map[run_env_conf.name] = run_env_conf self.__linked_projects.append( LinkedArjunaProject(name=proj_name, location=proj_path, ref_conf=ref_conf, ref_conf_editable=ref_conf_editable, data_env_conf_map=data_env_conf_map)) unique_paths.append(proj_import_path) unique_paths = set(unique_paths) for p in unique_paths: sys.path.append(p) self.__thread_wise_ref_conf_map[ threading.currentThread().name] = self.__test_session.init( project_root_dir, cli_config, run_id, self.__linked_projects) def get_src_file_path(src): return os.path.abspath( os.path.join(os.path.dirname(os.path.realpath(__file__)), src)) def get_proj_target_path(dest): return os.path.join( self.ref_config.value(ArjunaOption.PROJECT_ROOT_DIR), dest) def copy_file(src, dest): shutil.copyfile(get_src_file_path(src), get_proj_target_path(dest)) res_import_block = ''' try: from {project}.lib.resource import * except ModuleNotFoundError as e: if e.name not in {{"{project}.lib", "{project}.lib.resource"}}: raise Exception(e.name) ''' from arjuna import Arjuna f = open(get_src_file_path("../../res/conftest.txt"), "r") contents = f.read() f.close() res_import_blocks = list() for proj in self.__linked_projects: res_import_blocks.append( res_import_block.format(project=proj.name)) res_import_blocks.append( res_import_block.format( project=self.ref_config.value(ArjunaOption.PROJECT_NAME))) contents = contents.format(res_import_block="".join(res_import_blocks)) if os.path.exists(get_proj_target_path("test")): f = open(get_proj_target_path("test/conftest.py"), "w") f.write(contents) f.close() else: raise Exception( "No test directory found in project: {}. Check current directory or --project switch value." .format(self.ref_config.value(ArjunaOption.PROJECT_ROOT_DIR))) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.REPORT_DIR)) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.REPORT_XML_DIR)) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.REPORT_HTML_DIR)) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.LOG_DIR)) self.__create_dir_if_doesnot_exist( self.ref_config.value(ArjunaOption.SCREENSHOTS_DIR)) from arjuna.engine.logger import Logger self.__logger = Logger(self.ref_config) from arjuna import ArjunaOption self.__allowed_log_contexts = self.ref_config.value( ArjunaOption.LOG_ALLOWED_CONTEXTS) from arjuna.tpi.hook.config import Configurator configurator = Configurator() # Load configs from config hooks hooks_dir = self.ref_config.value(ArjunaOption.HOOKS_DIR) if os.path.isdir(hooks_dir): sys.path.append(hooks_dir) try: from arjuna_config import register_ref_confs except ModuleNotFoundError as e: # Module not defined. pass except ImportError as f: # Hook not defined pass else: register_ref_confs(configurator) def get_deps_dir_path(fpath): from arjuna.core.utils import file_utils if file_utils.is_absolute_path(fpath): if not file_utils.is_dir(fpath): if file_utils.is_file(fpath): raise Exception("Not a directory: {}".format(fpath)) return fpath else: fpath = os.path.abspath( os.path.join( self.ref_config.value(ArjunaOption.PROJECT_ROOT_DIR), fpath)) if not file_utils.is_dir(fpath): if file_utils.is_file(fpath): raise Exception("Not a directory: {}".format(fpath)) return fpath deps_dir = get_deps_dir_path( self.ref_config.value(ArjunaOption.DEPS_DIR)) if os.path.isdir(deps_dir): sys.path.append(deps_dir) # Load data references from arjuna.engine.data.factory import DataReference, DataReferences self.__contextual_data_references = DataReferences() self.__indexed_data_references = DataReferences() for linked_project in self.__linked_projects: cdrs, idrs = DataReference.load_all(linked_project.ref_conf) self.__contextual_data_references.update(cdrs) self.__indexed_data_references.update(idrs) cdrs, idrs = DataReference.load_all(self.ref_config) self.__contextual_data_references.update(cdrs) self.__indexed_data_references.update(idrs) # Load localization data from arjuna.engine.data.localizer import Localizer self.__localizer = Localizer.load_all(self.ref_config) from arjuna.tpi.parser.yaml import Yaml from arjuna.interact.gui.auto.finder.withx import WithX fpath = self.ref_config.value(ArjunaOption.CONF_WITHX_LOCAL_FILE) if not os.path.isfile(fpath): fpath = self.ref_config.value(ArjunaOption.CONF_WITHX_FILE) creation_context = f"WithX.yaml file at {fpath}" if os.path.isfile(fpath): wyaml = Yaml.from_file(fpath, allow_any=True) if wyaml is not None: self.__common_withx_ref = WithX(wyaml.as_map()) self.__start_bmproxy(self.ref_config) return self.ref_config
def load(self): from arjuna import Arjuna, log_debug from arjuna.configure.validator import Validator from arjuna.interact.gui.auto.finder._with import WithType from arjuna.tpi.parser.yaml import Yaml creation_context = "Gui Namespace file at {}".format(self.__ns_path) yaml = Yaml.from_file(self.__ns_path, allow_any=True) if yaml is None: return if not yaml.has_section("labels"): # print("No labels configured. Skipping...") return from arjuna.interact.gui.auto.finder.withx import WithX if yaml.has_section("withx"): self.__withx = WithX(yaml.get_section("withx").as_map()) else: self.__withx = WithX() common_withx = Arjuna.get_withx_ref() from arjuna.tpi.error import GuiWidgetDefinitionError for label, label_map in yaml.get_section("labels").as_map().items(): log_debug("Loading label: " + label) Validator.name(label) self.__ns[label.lower()] = { "locators": { self.__context: [] }, "meta": dict() } for entry in label_map: if type(label_map) is dict: loc, loc_obj = entry, label_map[entry] elif type(label_map) is list: if type(entry) is not dict or len(entry) != 1: raise GuiWidgetDefinitionError( "The GNS entry for label {} is not correctly formatted. For list content type, each list item should be a single item dictionary. Found: {}" .format(label, label_map)) loc, loc_obj = list(entry.keys())[0], list( entry.values())[0] else: raise GuiWidgetDefinitionError( "The GNS entry for label {} is not correctly formatted. The content should either be a YAML mapping or YAML list. Found: {}" .format(label, label_map)) log_debug("Loading locator: " + loc) loc = loc.lower() wtype, wvalue = None, None if not self.__withx.has_locator( loc) and not common_withx.has_locator(loc): wtype, wvalue = loc.upper(), loc_obj if wtype in dir(WithType): log_debug("Loading Arjuna defined Locator: " + loc) if wtype in {'ATTR', 'FATTR', 'BATTR', 'EATTR'}: if len(wvalue) > 1: raise Exception( "attr/fattr/battr/eattr entries in GNS should have a single key value pair mapping. Found: {} for locator type: {} for label: {}" .format(wvalue, loc, label)) final_value = dict() for k, v in wvalue.items(): final_value['name'] = k final_value['value'] = v wvalue = final_value iloc = ImplWith(wtype=wtype, wvalue=wvalue, has_content_locator=False) self.__ns[label.lower()]["locators"][ self.__context].append(iloc) else: log_debug("Loading meta data for key: " + loc) self.__ns[label.lower()]["meta"][ wtype.lower()] = wvalue else: if self.__withx.has_locator(loc): wx = self.__withx elif common_withx.has_locator(loc): wx = common_withx else: raise Exception( "No WithX locator with name {} found. Check GNS file at {}." .format(name, self.__ns_path)) try: wtype, wvalue = wx.format(loc, loc_obj) except Exception as e: raise Exception( "Error in implementation of withx locator extension: {} for label {}. Implementation: {}. Error: {}." .format(loc, label, wvalue, str(e))) iloc = ImplWith(wtype=wtype, wvalue=wvalue, has_content_locator=False) self.__ns[label.lower()]["locators"][ self.__context].append(iloc) if not self.__ns[label.lower()]["locators"][self.__context]: raise Exception( "No locators defined for label: {}".format(label)) if yaml.has_section("load"): self.__load_targets = yaml.get_section("load").as_map() if "root" in self.__load_targets: self.__ns["__root__"] = self.__load_targets["root"].lower() else: self.__ns["__root__"] = None if "anchor" in self.__load_targets: self.__ns["__anchor__"] = self.__load_targets["anchor"].lower() else: self.__ns["__anchor__"] = None else: self.__ns["__root__"] = None self.__ns["__anchor__"] = None for ename, wmd in self.__ns.items(): if ename not in {'__root__', '__anchor__'}: context_data = wmd["locators"] for context, locators in context_data.items(): self.add_element_meta_data(ename, context, locators, wmd["meta"]) log_debug( "Loading {} label for {} context with locators: {} and meta {}." .format(ename, context, [str(l) for l in locators], wmd["meta"])) self.add_reference("__root__", self.__ns["__root__"]) self.add_reference("__anchor__", self.__ns["__anchor__"])