示例#1
0
 def navigate(self, driver, timeout=10):
     log.info('Navigating ' + str(self))
     if remove_qs(driver.current_url) != self.route_start:
         log.info('Navigating to route start: {}'.format(self.route_start))
         driver.get(self.route_start)
     for waypoint in self.waypoints:
         try:
             self.navigate_waypoint(driver, waypoint, timeout)
             valid_dest = [
                 waypnt.dest for waypnt in
                 self.waypoints[self.waypoints.index(waypoint) + 1:]
             ]
         except NavigationException as e:
             if remove_qs(driver.current_url) == AUTH_URL:
                 log.error('Handling login redirect')
                 wait_for_auth(driver)
             elif remove_qs(driver.current_url) in valid_dest:
                 log.warning("Navigated to valid dest '{}'".format(
                     remove_qs(driver.current_url)))
             else:
                 log.warning(
                     "Current URL '{}' does not match target\n"
                     "Handling possible redirect (timeout in {}s)".format(
                         remove_qs(driver.current_url), timeout))
                 try:
                     WebDriverWait(driver, timeout).until(
                         EC.url_contains(waypoint.dest))
                     log.info("Made it to '{}'".format(waypoint.dest))
                 except TimeoutException:
                     raise e
     log.info('Route complete')
示例#2
0
 def navigate(self, driver, timeout=20):
     log.info('Navigating ' + str(self))
     self.waypoints_reached = 0
     if remove_qs(driver.current_url) != self.route_start:
         log.info('Navigating to route start: {}'.format(self.route_start))
         driver.get(self.route_start)
     for waypoint in self.waypoints:
         try:
             valid_dest = [
                 waypnt.dest for waypnt in
                 self.waypoints[self.waypoints.index(waypoint)+1:]
             ]
             if remove_qs(driver.current_url) == BASE_URL + waypoint.dest:
                 log.warning("Already at dest: '{}'".format(waypoint.dest))
             else:
                 self.navigate_waypoint(driver, waypoint, timeout)
         except NavigationException as e:
             current = remove_qs(driver.current_url)
             if Patterns.AUTH in current:
                 log.warning('Handling login redirect')
                 wait_for_auth(driver)
             elif any(d in current for d in valid_dest):
                 log.warning("Navigated to valid dest '{}'".format(current))
             elif current == self.route_start and self.waypoints_reached:
                 raise RouteRedirectException()
             else:
                 log.warning(
                     "Current URL '{}' does not match target\n"
                     "Handling possible redirect (timeout in {}s)".format(
                         current, timeout
                     )
                 )
                 try:
                     WebDriverWait(driver, timeout).until(
                         EC.url_matches('|'.join(valid_dest))
                     )
                 except TimeoutException:
                     log.error(
                         "Timed out waiting for redirect to a valid dest\n"
                         "Current URL: '{}'".format(driver.current_url)
                     )
                     raise e
         self.waypoints_reached += 1
     log.info('Route complete')
示例#3
0
 def navigate(self, driver, timeout=10):
     log.info('Navigating ' + str(self))
     if remove_qs(driver.current_url) != self.route_start:
         log.info('Navigating to route start: {}'.format(self.route_start))
         driver.get(self.route_start)
     for waypoint in self.waypoints:
         try:
             self.navigate_waypoint(driver, waypoint, timeout)
             valid_dest = [
                 waypnt.dest for waypnt in
                 self.waypoints[self.waypoints.index(waypoint) + 1:]
             ]
         except NavigationException:
             if remove_qs(driver.current_url) == AUTH_URL:
                 log.error('Handling login redirect')
                 wait_for_auth(driver)
             elif remove_qs(driver.current_url) in valid_dest:
                 log.warning("Navigated to valid dest '{}'".format(
                     remove_qs(driver.current_url)))
             else:
                 raise
     log.info('Route complete')
示例#4
0
 def navigate_waypoint(self, driver, waypoint, timeout):
     log.info('Navigating ' + str(waypoint))
     elem = get_element(driver, waypoint.locator, timeout=timeout)
     jitter(.8)
     elem.click()
     try:
         WebDriverWait(driver, timeout).until(EC.staleness_of(elem))
     except TimeoutException:
         pass
     if remove_qs(driver.current_url) == BASE_URL + waypoint.dest:
         log.info("Navigated to '{}'".format(waypoint.dest))
     else:
         raise NavigationException("Navigation to '{}' failed".format(
             waypoint.dest))