def drag_and_drop(self, destination):
     Log.info("Drag and Drop on %s" % self.name)
     element = self.get_element()
     if not isinstance(destination, WebElement):
         destination = destination.get_element()
     ActionChains(element.parent).drag_and_drop(element,
                                                destination).perform()
Example #2
0
 def exists(self, wait_time: int = 0) -> bool:
     Log.info("Checking if '%s' element exists" % self.name)
     try:
         self.wait_for.presence_of_element_located(wait_time)
         return True
     except (NoSuchElementException, TimeoutException):
         return False
Example #3
0
 def alert_is_present(self,
                      wait_time: int = page_load_time,
                      poll_frequency=POLL_FREQUENCY,
                      ignored_exceptions=None):
     Log.info('Expect an alert to be present.')
     return self.condition(wait_time, alert_is_present(), poll_frequency,
                           ignored_exceptions)
Example #4
0
 def get_rows_by_attribute_value(self,
                                 column_name: str,
                                 attribute_name: str,
                                 attribute_value: str,
                                 wait_time: int = element_load_time) -> T:
     Log.debug(
         f"Getting rows by column {column_name} by attribute {attribute_name} and value {attribute_value} "
         f"from the table: {self.name}")
     out = list()
     end_time = time.time() + wait_time
     while True:
         content = self.get_content()
         for row in content:
             column = getattr(row, column_name)
             if column.exists():
                 act_attr_value = getattr(
                     row, column_name).get_attribute(attribute_name)
                 if act_attr_value == attribute_value:
                     out.append(row)
         if self.next_page():
             return self.get_rows_by_attribute_value(
                 column_name, attribute_name, attribute_value, wait_time)
         elif out or time.time() > end_time:
             break
     return out
Example #5
0
 def get_row_by_index(self,
                      index: int,
                      wait_time: int = element_load_time) -> T:
     Log.info("Getting row by index %s from the table: %s" %
              (index, self.name))
     rows = self.get_content(wait_time=wait_time)
     return rows[index]
Example #6
0
 def inject_waiter(self):
     Log.debug(
         "Injecting JavaScrip HTTP requests waiter into '%s' element" %
         self.element_name)
     with open(js_waiter_file, 'r') as content:
         js_waiter = content.read()
         self.execute(js_waiter)
Example #7
0
 def execute_action(self,
                    action,
                    element_condition:
                    expected_conditions = presence_of_element_located,
                    *args):
     try:
         obj = getattr(self.get_element(element_condition), action)
         if isinstance(obj, str):
             self.__retry_count = 0
             return obj
         else:
             if self.action_element:
                 self.inject_js_waiter()
             if args:
                 value = obj(*args)
             else:
                 value = obj()
             if self.action_element:
                 self.wait_until_http_requests_are_finished()
             return value
     except (StaleElementReferenceException, WebDriverException,
             InvalidElementStateException) as e:
         if self.__retry_count <= 2:
             self.__retry_count += 1
             Log.error('Error on performing \'%s\' action. Retrying...' %
                       action)
             Log.error(e.msg)
             time.sleep(retry_delay)
             if 'is not clickable at point' in e.msg:
                 self.scroll_to_element()
             return self.execute_action(action, element_condition, *args)
         else:
             raise e
 def wait_for_text_to_be_present_in_element(
         self, wait_time: int = element_load_time, text: str = ""):
     Log.info('Waiting for the text %s to be present' % self.name)
     x = WebDriverWait(self.get_element().parent, wait_time).until(
         expected_conditions.text_to_be_present_in_element(
             self.locator, text))
     return x
Example #9
0
 def url_changes(self,
                 url: str,
                 wait_time: int = page_load_time,
                 poll_frequency=POLL_FREQUENCY,
                 ignored_exceptions=None):
     Log.info('An expectation for checking the current url.')
     return self.condition(wait_time, url_changes(url), poll_frequency,
                           ignored_exceptions)
Example #10
0
 def title_is(self,
              title: str,
              wait_time: int = page_load_time,
              poll_frequency=POLL_FREQUENCY,
              ignored_exceptions=None):
     Log.info('An expectation for checking the title of a page.')
     return self.condition(wait_time, title_is(title), poll_frequency,
                           ignored_exceptions)
Example #11
0
 def element_to_be_clickable(self,
                             wait_time: int = element_load_time,
                             poll_frequency=POLL_FREQUENCY,
                             ignored_exceptions=None):
     Log.info(
         'An Expectation for checking an element "%s" is visible and enabled such that you can click it.'
         % self.name)
     return self.condition(wait_time, element_to_be_clickable(self.locator),
                           poll_frequency, ignored_exceptions)
Example #12
0
 def number_of_windows_to_be(self,
                             num_windows: int,
                             wait_time: int = page_load_time,
                             poll_frequency=POLL_FREQUENCY,
                             ignored_exceptions=None):
     Log.info(
         'An expectation for the number of windows to be a certain value.')
     return self.condition(wait_time, number_of_windows_to_be(num_windows),
                           poll_frequency, ignored_exceptions)
Example #13
0
 def invisibility_of_element_located(self,
                                     wait_time: int = element_load_time,
                                     poll_frequency=POLL_FREQUENCY,
                                     ignored_exceptions=None):
     Log.info(
         'An Expectation for checking that an element "%s" is either invisible or not present on the DOM.'
         % self.name)
     return self.condition(wait_time,
                           invisibility_of_element_located(self.locator),
                           poll_frequency, ignored_exceptions)
Example #14
0
 def url_contains(self,
                  url: str,
                  wait_time: int = page_load_time,
                  poll_frequency=POLL_FREQUENCY,
                  ignored_exceptions=None):
     Log.info(
         'An expectation for checking that the current url contains a case-sensitive substring.'
     )
     return self.condition(wait_time, url_contains(url), poll_frequency,
                           ignored_exceptions)
Example #15
0
 def visibility_of(self,
                   wait_time: int = element_load_time,
                   poll_frequency=POLL_FREQUENCY,
                   ignored_exceptions=None):
     Log.info(
         'Waiting for the existing "%s" element on the page to be visible.'
         % self.name)
     return self.condition(
         wait_time, visibility_of(self.presence_of_element_located()),
         poll_frequency, ignored_exceptions)
Example #16
0
 def staleness_of(self,
                  wait_time: int = element_load_time,
                  poll_frequency=POLL_FREQUENCY,
                  ignored_exceptions=None):
     Log.info(
         'Wait until an element is no longer attached to the DOM. "%s" is the element to wait for'
         % self.name)
     return self.condition(wait_time,
                           staleness_of(self.presence_of_element_located()),
                           poll_frequency, ignored_exceptions)
Example #17
0
 def element_located_to_be_selected(self,
                                    wait_time: int = element_load_time,
                                    poll_frequency=POLL_FREQUENCY,
                                    ignored_exceptions=None):
     Log.info(
         'An expectation for the element "%s" to be located is selected.' %
         self.name)
     return self.condition(wait_time,
                           element_located_to_be_selected(self.locator),
                           poll_frequency, ignored_exceptions)
Example #18
0
 def presence_of_all_elements_located(self,
                                      wait_time: int = element_load_time,
                                      poll_frequency=POLL_FREQUENCY,
                                      ignored_exceptions=None):
     Log.info(
         'An expectation for checking that there is at least one element "%s" present on a web page.'
         % self.name)
     return self.condition(wait_time,
                           presence_of_all_elements_located(self.locator),
                           poll_frequency, ignored_exceptions)
Example #19
0
 def presence_of_element_located(self,
                                 wait_time: int = element_load_time,
                                 poll_frequency=POLL_FREQUENCY,
                                 ignored_exceptions=None):
     Log.info(
         'An expectation for checking that an element "%s" is present on the DOM of a page.'
         % self.name)
     return self.condition(wait_time,
                           presence_of_element_located(self.locator),
                           poll_frequency, ignored_exceptions)
Example #20
0
 def visibility_of_any_elements_located(self,
                                        wait_time: int = element_load_time,
                                        poll_frequency=0.5,
                                        ignored_exceptions=None):
     Log.info(
         'An expectation for checking that there is at least one element "%s" visible on a web page.'
         % self.name)
     return self.condition(wait_time,
                           visibility_of_any_elements_located(self.locator),
                           poll_frequency, ignored_exceptions)
Example #21
0
 def new_window_is_opened(self,
                          current_handles: list,
                          wait_time: int = page_load_time,
                          poll_frequency=POLL_FREQUENCY,
                          ignored_exceptions=None):
     Log.info(
         'An expectation that a new window will be opened and have the number of windows handles increase'
     )
     return self.condition(wait_time, new_window_is_opened(current_handles),
                           poll_frequency, ignored_exceptions)
Example #22
0
 def visibility_of_all_elements_located(self,
                                        wait_time: int = element_load_time,
                                        poll_frequency=0.5,
                                        ignored_exceptions=None):
     Log.info(
         'An expectation for checking that all elements "%s" are present on the DOM of a page and visible.'
         % self.name)
     return self.condition(wait_time,
                           visibility_of_all_elements_located(self.locator),
                           poll_frequency, ignored_exceptions)
Example #23
0
 def exists(
         self,
         wait_time: int = 0,
         condition: expected_conditions = presence_of_element_located
 ) -> bool:
     Log.info("Checking if '%s' element exists" % self.name)
     try:
         self.get_element(condition=condition, wait_time=wait_time)
         return True
     except (NoSuchElementException, TimeoutException):
         return False
Example #24
0
 def element_to_be_selected(self,
                            wait_time: int = element_load_time,
                            poll_frequency=POLL_FREQUENCY,
                            ignored_exceptions=None):
     Log.info(
         'An expectation for checking the selection "%s" is selected.' %
         self.name)
     return self.condition(
         wait_time,
         element_to_be_selected(self.presence_of_element_located()),
         poll_frequency, ignored_exceptions)
Example #25
0
 def exists(self, wait_time: int = 0):
     Log.debug(
         f"Window '{self.name}' existence verification. Wait time = {str(wait_time)}"
     )
     if self.get_driver():
         try:
             self.wait_for.visibility_of_element_located(self.load_time)
             return True
         except (NoSuchElementException, TimeoutException):
             Log.debug("Window '%s' was not found" % self.name)
     return False
Example #26
0
 def number_of_elements(self,
                        elements_count: int,
                        wait_time: int = element_load_time,
                        poll_frequency=0.5,
                        ignored_exceptions=None):
     Log.info(
         'An expectation for checking that number elements "%s" are present on the DOM of a page.'
         % self.name)
     return self.condition(
         wait_time, lambda driver: len(driver.find_elements(*self.locator))
         == elements_count, poll_frequency, ignored_exceptions)
Example #27
0
 def text_to_be_present_in_element_value(self,
                                         text: str,
                                         wait_time: int = element_load_time,
                                         poll_frequency=POLL_FREQUENCY,
                                         ignored_exceptions=None):
     Log.info(
         'Checking if the given text is present in the element\'s locator "%s", text.'
         % self.name)
     return self.condition(
         wait_time, text_to_be_present_in_element_value(self.locator, text),
         poll_frequency, ignored_exceptions)
Example #28
0
 def frame_to_be_available_and_switch_to_it(self,
                                            locator: Locator,
                                            wait_time: int = page_load_time,
                                            poll_frequency=POLL_FREQUENCY,
                                            ignored_exceptions=None):
     Log.info(
         'An expectation for checking whether the given frame "%s" is available to switch to.'
         % str(locator))
     return self.condition(wait_time,
                           frame_to_be_available_and_switch_to_it(locator),
                           poll_frequency, ignored_exceptions)
Example #29
0
 def wait_until_http_requests_are_finished(
         self, wait_time: int = http_request_wait_time):
     try:
         end_time = time.time() + wait_time
         while True:
             if not self.execute(
                     "return window.openHTTPs") or time.time() > end_time:
                 break
     except TimeoutException:
         Log.error('HTTP request execution time is more than %s seconds' %
                   wait_time)
         self.execute("window.openHTTPs=0")
Example #30
0
 def element_located_selection_state_to_be(
         self,
         is_selected: bool,
         wait_time: int = element_load_time,
         poll_frequency=POLL_FREQUENCY,
         ignored_exceptions=None):
     Log.info(
         'An expectation to locate an element "%s" and check if the selection state specified is in that '
         'state.' % self.name)
     return self.condition(
         wait_time, element_selection_state_to_be(self.locator,
                                                  is_selected),
         poll_frequency, ignored_exceptions)