コード例 #1
0
    def __complete_mobile_search(self, close=False):
        self.__sys_out("Starting mobile search", 1)

        try:
            driver = Driver.get_driver(self.path, Driver.MOBILE_DEVICE,
                                       self.headless)
            self.__login(driver)

            self.completion.mobile_search = self.__search(
                driver, Driver.MOBILE_DEVICE)
            if self.completion.mobile_search:
                self.__sys_out("Successfully completed mobile search", 1, True)
            else:
                self.__sys_out("Failed to complete mobile search", 1, True)
        except:
            try:
                Driver.close(driver)
            except:  # not yet initialized
                pass
            raise

        if close:
            Driver.close(driver)
        else:
            return driver
コード例 #2
0
 def complete_both_searches(self, search_hist, print_stats=True):
     self.search_hist = search_hist
     self.__complete_edge_search()
     self.__complete_web_search(close=True)
     driver = self.__complete_mobile_search()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
コード例 #3
0
ファイル: rewards.py プロジェクト: connect-dots/bing-rewards
 def complete_web_search_and_offers(self, search_hist, print_stats=True):
     self.search_hist = search_hist
     self.__complete_edge_search(close=True)
     driver = self.__complete_web_search()
     self.__complete_offers(driver)
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
コード例 #4
0
 def complete_all(self, print_stats=True):
     driver = self.__complete_web_search()
     self.__complete_offers(driver)
     Driver.close(driver)
     driver = self.__complete_mobile_search()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
コード例 #5
0
class BasePage:
    """ Base web page that opens window with desired URL and it has methods to work with elements using xpath. """

    URL = None
    """ str: If set, after initialization of page object, browser is redirected to this URL. """

    def __init__(self, driver=None):
        if driver:
            self.driver = driver
        else:
            self.driver = Driver()
        if self.URL:
            self.driver.driver.get(self.URL)
        self.logger = logging.getLogger(str(settings.PROJECT_DIR))
        self.logger.info(f'Class \'{self.__class__.__name__}\' successfully initialized.')

    def close(self):
        self.driver.close()

    def get_element_by_xpath(self, xpath):
        return WebDriverWait(self.driver, 20).until(
            EC.presence_of_element_located((By.XPATH, xpath))
        )

    def get_elements_by_xpath(self, xpath):
        return self.driver.driver.find_elements_by_xpath(xpath)

    def click_element_by_xpath(self, xpath, scroll_to=False):
        if scroll_to:
            self.scroll_to_element_by_xpath(xpath)
            time.sleep(1)
        self.driver.execute_script("arguments[0].click();", self.get_element_by_xpath(xpath))
        time.sleep(0.3)

    def scroll_to_element_by_xpath(self, xpath):
        self.driver.execute_script(
            'arguments[0].scrollIntoView({behavior: "smooth"});', self.get_element_by_xpath(xpath)
        )

    def set_value_by_xpath(self, xpath, value):
        elem = self.get_element_by_xpath(xpath)
        elem.clear()
        elem.send_keys(value)
        time.sleep(0.3)

    @staticmethod
    def get_child_by_xpath(elem, xpath):
        return WebDriverWait(elem, 10).until(lambda _: elem.find_element_by_xpath(xpath))

    def click_child_by_xpath(self, elem, xpath):
        self.driver.execute_script('arguments[0].click();', self.get_child_by_xpath(elem, xpath))

    def get_child_text_by_xpath(self, elem, xpath):
        return self.get_child_by_xpath(elem, xpath).text
コード例 #6
0
    def __complete_offers(self, driver=None):
        self.__sys_out("Starting offers", 1)

        try:
            if not driver:
                driver = Driver.get_driver(self.path, Driver.WEB_DEVICE,
                                           self.headless)
                self.__login(driver)

            self.completion.offers = self.__offers(driver)
            if self.completion.offers == -1 or self.completion.offers == False:
                self.__sys_out("Failed to complete offers", 1, True)
            else:
                self.__sys_out("Successfully completed offers", 1, True)
        except:
            try:
                Driver.close(driver)
            except:
                pass
            raise

        return driver
コード例 #7
0
 def complete_offers(self, print_stats=True):
     driver = self.__complete_offers()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
コード例 #8
0
 def complete_web_search(self, search_hist, print_stats=True):
     self.search_hist = search_hist
     driver = self.__complete_web_search()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
コード例 #9
0
                        type=str,
                        help='Recipient email address for error emails.')
    parser.add_argument('-a',
                        '--from-password',
                        type=str,
                        help='Password of sender email account.')
    parser.add_argument('-e',
                        '--headless',
                        action='store_true',
                        default=False,
                        help='Run browser in headless mode.')
    return parser.parse_args()


if __name__ == '__main__':

    _init_logging()
    args = _parse_args()
    driver = Driver(headless=args.headless)
    try:
        GSLoginPage(driver=driver).login(args.name, args.password)
        GSChallengesPage(driver=driver).process_all_challenges()
    except Exception as e:
        logging.getLogger(str(settings.PROJECT_DIR)).error(
            f'Because of following error, automation is stopped and email is sent: {e}'
        )
        send_error_email(args.from_address, args.from_password,
                         args.to_address, str(e))
    finally:
        driver.close()
コード例 #10
0
 def complete_web_search_and_offers(self, print_stats=True):
     driver = self.__complete_web_search()
     self.__complete_offers(driver)
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)
コード例 #11
0
 def complete_mobile_search(self, print_stats=True):
     driver = self.__complete_mobile_search()
     if print_stats:
         self.__print_stats(driver)
     Driver.close(driver)