def open_file(self, path: str) -> Application: """Open a file with the default application. :param path: Path to file Example: .. code-block:: robotframework Open file orders.xlsx """ path: Path = Path(path) if not path.exists(): raise FileNotFoundError(f"File does not exist: {path}") # TODO: Move implementations to platform-specific adapters if utils.is_windows(): return self._open_default_windows(path) elif utils.is_linux(): return self._open_default_linux(path) elif utils.is_macos(): return self._open_default_macos(path) else: raise NotImplementedError("Not supported for current system")
def open_file(self, path: str) -> Application: """Open a file with the default application. :param path: Path to file Example: .. code-block:: robotframework Open file orders.xlsx """ name = Path(path).name if not Path(path).exists(): raise FileNotFoundError(f"File does not exist: {path}") if utils.is_windows(): # TODO: Find out way to get actual default application return self._create_app(name, ["start", "/WAIT"], shell=True) elif utils.is_macos(): # TODO: Find out way to get actual default application return self._create_app(name, ["open", "-W", path]) else: mimetype = output("xdg-mime", "query", "filetype", path) applications = output("xdg-mime", "query", "default", mimetype) default = output("xdg-mime", "query", "default", "text/plain") def executable(app): with open(Path("/usr/share/applications/") / app) as fd: matches = re.search(r"\bExec=(\S+)", fd.read(), re.MULTILINE) return matches.group(1) if matches else None for app in applications.split(";") + default.split(";"): exe = executable(app) if not exe: continue try: return self._create_app(name, [exe, path]) except FileNotFoundError: pass raise RuntimeError(f"No default application found for {path}")
def copy_to_clipboard(self, locator: LocatorType) -> str: """Read value to system clipboard from given input element. :param locator: Locator for element :returns: Current clipboard value Example: .. code-block:: robotframework ${value}= Copy to clipboard ResultPage.Counter Log Copied text: ${value} """ if utils.is_macos(): self.ctx.click(locator, "triple click") self.ctx.press_keys("cmd", "c") else: self.ctx.click(locator, "triple click") self.ctx.press_keys("ctrl", "c") return self.get_clipboard_value()