def register(self, strategy_name, strategy_keyword, persist=False): strategy = CustomLocator(self.ctx, strategy_name, strategy_keyword) if strategy.name in self._strategies: raise RuntimeError("The custom locator '%s' cannot be registered. " "A locator of that name already exists." % strategy.name) self._strategies[strategy.name] = strategy.find if is_falsy(persist): # Unregister after current scope ends events.on("scope_end", "current", self.unregister, strategy.name)
def register(self, strategy_name, strategy_keyword, persist=False): strategy = CustomLocator(self.ctx, strategy_name, strategy_keyword) if strategy.name in self._strategies: raise RuntimeError("The custom locator '%s' cannot be registered. " "A locator of that name already exists." % strategy.name) self._strategies[strategy.name] = strategy.find if is_falsy(persist): # Unregister after current scope ends events.on('scope_end', 'current', self.unregister, strategy.name)
def set_screenshot_directory(self, path, persist=False): """Sets the root output directory for captured screenshots. ``path`` argument specifies the absolute path where the screenshots should be written to. If the specified ``path`` does not exist, it will be created. Setting ``persist`` specifies that the given ``path`` should be used for the rest of the test execution, otherwise the path will be restored at the end of the currently executing scope. """ path = os.path.abspath(path) self._create_directory(path) if is_falsy(persist): self._screenshot_path_stack.append(self.screenshot_root_directory) # Restore after current scope ends events.on('scope_end', 'current', self._restore_screenshot_directory) self.screenshot_root_directory = path