Example #1
0
    def register(self, *, config_name=None):
        '''
            Register the new configuration.

            Keyword Arguments:
                config_name: (Optional) Name that you want to assign to the configuration.

            Note:
                - Name needs to be unique in a test run. No configuration should exist with the same name.
                - A dynamic, unique name is generated if name is not provided.

        '''
        from arjuna import Arjuna, ConfigCreationError
        if config_name is None and not self._auto_gen_name:
            raise ConfigCreationError("This ConfigBuilder has been created with auto_gen_name setting as False. You must provide a config_name to the build call.")
        config_name = config_name and config_name or 'c{}'.format(str(uuid.uuid4()).replace("-","_"))

        try:
            from arjuna.configure.validator import Validator
            Validator.name(config_name)
        except:
            raise ConfigCreationError("Unsupported name >>{}<< provided for a Configuration object. {}".format(config_name, Validator.VNREGEX_TEXT))

        if Arjuna.has_config(config_name):
            raise ConfigCreationError("You can not re-register a configuration for a name. Config with name {} already exists.".format(config_name))

        config = self._test_session.register_config(config_name.lower(), 
                                        self._config_container.arjuna_options, #.items(),
                                        self._config_container.user_options, #.items(),
                                        self._base_config
                                    )

        return config
Example #2
0
 def __init__(self, xdict={}):
     self.__xdict = CIStringDict()
     for k,v in xdict.items():
         try:
             self.__xdict[Validator.name(k)] = {"wtype" : xdict[k]["wtype"].strip().upper(), "wvalue" : xdict[k]["wvalue"]}
         except Exception as e:
             raise Exception(f"Invalid WithX entry for name >>{k}<<.")
Example #3
0
    def __init__(self, xdict={}):
        def process_value(wtype, wvalue):
            if wtype in {'ATTR', 'FATTR', 'BATTR',
                         'EATTR'}:  #:, 'NODE', 'BNODE', 'FNODE'}:
                if len(wvalue) > 1:
                    raise Exception(
                        "attr/fattr/battr/eattr specification should contain only a single key value pair for attribute name and value. Wrong withx definition found wtype: {} with value {}"
                        .format(wtype, wvalue))
                name = list(wvalue.keys())[0]
                value = list(wvalue.values())[0]
                return {'name': name, 'value': value}
            else:
                return wvalue

        self.__xdict = CIStringDict()
        for k, v in xdict.items():
            try:
                wname = Validator.name(k)
                wtype = xdict[k]["wtype"].strip().upper()
                wvalue = xdict[k]["wvalue"]
                self.__xdict[wname] = {
                    "wtype": wtype,
                    "wvalue": process_value(wtype, wvalue)
                }
            except Exception as e:
                raise Exception(f"Invalid WithX entry for name >>{k}<<. {e}")
Example #4
0
    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__"])
Example #5
0
    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__"])