def url(self):
     wait_condition(lambda: self.get_attribute_value("AXURL") is not None,
                    timeout=60)
     wait_condition(
         lambda: self.get_attribute_value("AXURL").startswith("http"),
         timeout=30)
     return wait_condition(lambda: self.get_attribute_value("AXURL"),
                           timeout=30)
Beispiel #2
0
 def close_tabs(self):
     if not self.is_running:
         return
     try:
         as_wrapper.tell_app(self.name,
                             "close tabs of every window",
                             ignoring_responses=True)
         wait_condition(lambda: as_wrapper.tell_app(
             self.name, "return the number of tabs in windows") == 0)
     except AssertionError:
         as_wrapper.tell_app(self.name,
                             "close every window",
                             ignoring_responses=True)
Beispiel #3
0
 def download_file(self,
                   url: str,
                   file_name: str = "*pattern*",
                   timeout: int = MINUTE):
     _before_ = self.downloads
     self.request_webpage(url)
     self.confirm_download()
     wait_condition(lambda: self.downloads > _before_, timeout=MINUTE)
     wait_condition(
         lambda: glob.glob(os.path.join(env.downloads, "*.download")) == [],
         timeout=timeout)
     return wait_condition(
         lambda: glob.glob(os.path.join(env.downloads, file_name)),
         timeout=30)
Beispiel #4
0
 def did_webpage_load(self,
                      expected_address: str,
                      timeout: float = 15) -> bool:
     if not self.did_launch:
         raise EnvironmentError(f'{self.name} did not launch')
     wait_condition(lambda: self.native_window is not None,
                    exceptions=EXCEPTIONS)
     wait_condition(lambda: self.execute_js_command("document.readyState")
                    == "complete",
                    timeout=timeout)
     if not self.did_reload_button_appear:
         logging.warning("Reload button has not shown")
     return wait_condition(lambda: expected_address in self.document_url,
                           timeout=3,
                           exceptions=EXCEPTIONS)
 def get_process_cpu_usage(self, process_name: str) -> float:
     pid = wait_condition(
         lambda: self.executor.get_output(f"pgrep {process_name}$"),
         timeout=3)
     if pid:
         return float(
             self.executor.get_output(f"ps -p {pid} -o %cpu").split("%CPU")
             [1].strip()).__round__(2)
     raise LookupError(f'Process "{process_name}" not found')
Beispiel #6
0
 def read_plist(self) -> Dict[str, Any]:
     payload = dict()
     if not wait_condition(lambda: os.path.exists(self.plist), timeout=15):
         raise PropertyListMissing
     try:
         payload = biplist.readPlist(self.plist)
     except (biplist.NotBinaryPlistException, biplist.InvalidPlistException):
         raise
     finally:
         return payload
 def fill(self, with_text: str, pause: float = 0.01):
     for _ in range(2):
         self.text = ""
         self.focus()
         time.sleep(0.5)
         keyboard.write(with_text, pause=pause)
         if wait_condition(lambda: len(self.text) == len(with_text),
                           timeout=0.5):
             break
     if not len(self.text) == len(with_text):
         raise KeyboardInterrupt(
             f'"{with_text}" expected but "{self.text}" received.')
 def is_frontmost(self) -> bool:
     return wait_condition(lambda: self._read_attribute("AXFrontmost"),
                           timeout=5)
 def is_hidden(self) -> bool:
     return wait_condition(lambda: self._read_attribute("AXHidden"),
                           timeout=3)
Beispiel #10
0
 def wait_displayed(self,
                    timeout: int = 5,
                    region: Optional[Region] = None) -> Union[None, Point]:
     return wait_condition(lambda: self.detect_on_screen(region),
                           timeout=timeout)
Beispiel #11
0
 def wait_vanish(self,
                 timeout: int = 15,
                 region: Optional[Region] = None) -> bool:
     return wait_condition(lambda: self.detect_on_screen(region) is None,
                           timeout=timeout)
 def wait_displayed(self, timeout: Union[int, float] = 5):
     return wait_condition(self.is_exists, timeout=timeout)
Beispiel #13
0
 def did_reload_button_appear(self) -> bool:
     return wait_condition(
         lambda: self.stop_reload_button.get_ax_attribute("AXTitle") ==
         "Reload this page",
         exceptions=EXCEPTIONS,
     )
 def wait_state(self, state):
     return wait_condition(lambda: self.get_state() == state)
 def is_disabled(self):
     return wait_condition(lambda: self._is_enabled() is False)
 def is_enabled(self):
     return wait_condition(self._is_enabled, timeout=3)
 def __eq__(self, other):
     return wait_condition(lambda: self.text == other, timeout=1)
 def wait_enabled(self, timeout: int) -> bool:
     return wait_condition(self._is_enabled, timeout=timeout)
 def did_user_service_quit(self, service: str) -> bool:
     return wait_condition(lambda: service not in self.user_services)
 def did_system_service_launch(self, service: str) -> bool:
     return wait_condition(lambda: service in self.system_services)
 def is_enabled(self):
     return wait_condition(self._is_enabled)
 def wait_process_disappeared(self, process_name, timeout=10):
     return wait_condition(lambda: process_name not in self.processes_list,
                           timeout=timeout)
Beispiel #23
0
 def request_webpage(self, url: str):
     as_wrapper.tell_app(
         self.name, f'make new document with properties {{URL:"{url}"}}')
     wait_condition(lambda: self.native_window is not None)
 def wait_vanish(self, timeout: [int, float] = 5) -> bool:
     return wait_condition(lambda: self.__get_axrole() is None, timeout=timeout)
 def wait_vanish(self, timeout: [int, float] = 5) -> bool:
     self.wait_displayed(timeout=0.3)
     return wait_condition(lambda: self.is_exists() is False,
                           timeout=timeout)
 def url(self) -> str:
     webview = self.__perform_lookup()
     wait_condition(lambda: webview.get_ax_attribute("AXURL"), timeout=30)
     wait_condition(lambda: webview.get_ax_attribute("AXURL").startswith("https://"), timeout=30)
     return str(webview.get_ax_attribute("AXURL"))
 def __wait_children(self):
     wait_condition(
         lambda: self.item.get_ax_attribute("AXChildren"),
         exceptions=(AttributeError, AXErrorInvalidUIElement),
     )
 def wait_text(self, text: str, where: Region, timeout: int = 10) -> bool:
     return wait_condition(lambda: self.recognize(region=where) == text,
                           timeout=timeout)
 def did_vanish(self) -> bool:
     return wait_condition(lambda: self.__get_axrole() is None)