def test_from_dict_required(self): data = { "type": "browser", "strategy": "class", } with pytest.raises(ValueError): Locator.from_dict(data)
def test_from_dict_no_type(self): data = { "strategy": "class", "value": "btn-primary", } with pytest.raises(ValueError): Locator.from_dict(data)
def _load(self, data): """Load database content as Locator objects.""" locators = {} invalid = {} # Migrate from old list-based file format if isinstance(data, list): data = { fields["name"]: fields for fields in data if "name" in fields } sanitized = [] for name, fields in data.items(): try: sname = sanitize_name(name) if sname in sanitized: raise ValueError( f"Duplicate sanitized name: {name} / {sname}") sanitized.append(sname) locators[name] = Locator.from_dict(fields) except Exception as exc: # pylint: disable=broad-except self.logger.warning('Failed to parse locator "%s": %s', name, exc) invalid[name] = fields # Migrate base64 screenshots to files for name, locator in locators.items(): self._convert_screenshot(name, locator) return locators, invalid
def test_from_dict_image_template(self): data = { "type": "image", "path": "images/TestTemplate.png", "source": "images/TestSource.png", } locator = Locator.from_dict(data) assert isinstance(locator, ImageLocator) assert locator.path == "images/TestTemplate.png" assert locator.source == "images/TestSource.png" assert locator.confidence == None
def test_from_dict_extras(self): data = { "type": "browser", "strategy": "class", "value": "btn-primary", "source": "https://robotsparebinindustries.com/", "notvalid": "somevalue", } locator = Locator.from_dict(data) assert isinstance(locator, BrowserLocator)
def test_from_dict_optional(self): data = { "type": "browser", "strategy": "class", "value": "btn-primary", } locator = Locator.from_dict(data) assert isinstance(locator, BrowserLocator) assert locator.strategy == "class" assert locator.value == "btn-primary" assert locator.source == None
def test_from_dict(self): data = { "type": "browser", "strategy": "class", "value": "btn-primary", "source": "https://robotsparebinindustries.com/", } locator = Locator.from_dict(data) assert isinstance(locator, BrowserLocator) assert locator.strategy == "class" assert locator.value == "btn-primary" assert locator.source == "https://robotsparebinindustries.com/"
def _load(self, data): """Load database content as Locator objects.""" locators = {} invalid = {} sanitized = [] for name, fields in data.items(): try: sname = sanitize_name(name) if sname in sanitized: raise ValueError( f"Duplicate sanitized name: {name} / {sname}") sanitized.append(sname) locators[name] = Locator.from_dict(fields) except Exception as exc: # pylint: disable=broad-except self.logger.warning('Failed to parse locator "%s": %s', name, exc) invalid[name] = fields return locators, invalid