Exemplo n.º 1
0
    def wait_for_pyo_page(self):
        selenium_utils.wait_for_any_title(self.driver,
                                          CHECKOUT_TITLES + SIGN_IN_TITLES)

        if self.driver.title in SIGN_IN_TITLES:
            log.info("Need to sign in again")
            self.login()
Exemplo n.º 2
0
 def wait_for_order_completed(self, test):
     if not test:
         selenium_utils.wait_for_any_title(self.driver,
                                           ORDER_COMPLETE_TITLES)
     else:
         log.info(
             "This is a test, so we don't need to wait for the order completed page."
         )
Exemplo n.º 3
0
    def something_in_stock(self):
        params = {"anticache": str(secrets.token_urlsafe(32))}

        for x in range(len(self.asin_list)):
            params[f"ASIN.{x + 1}"] = self.asin_list[x]
            params[f"Quantity.{x + 1}"] = 1

        f = furl(AMAZON_URLS["CART_URL"])
        f.set(params)
        self.driver.get(f.url)
        selenium_utils.wait_for_any_title(self.driver, ADD_TO_CART_TITLES)
        if self.driver.find_elements_by_xpath('//td[@class="price item-row"]'):
            log.info("One or more items in stock!")

            return True
        else:
            return False
Exemplo n.º 4
0
    def __init__(self, headless=False):
        self.notification_handler = NotificationHandler()
        if headless:
            enable_headless()
        options.add_argument(f"user-data-dir=.profile-amz")
        self.driver = webdriver.Chrome(executable_path=binary_path,
                                       options=options)
        self.wait = WebDriverWait(self.driver, 10)
        if path.exists(AUTOBUY_CONFIG_PATH):
            with open(AUTOBUY_CONFIG_PATH) as json_file:
                try:
                    config = json.load(json_file)
                    self.username = config["username"]
                    self.password = config["password"]
                    self.asin_list = config["asin_list"]
                    self.amazon_website = config.get("amazon_website",
                                                     "amazon.com")
                    assert isinstance(self.asin_list, list)
                except Exception:
                    raise InvalidAutoBuyConfigException(
                        "amazon_config.json file not formatted properly.")
        else:
            raise InvalidAutoBuyConfigException(
                "Missing amazon_config.json file.")

        for key in AMAZON_URLS.keys():
            AMAZON_URLS[key] = AMAZON_URLS[key].format(self.amazon_website)
        print(AMAZON_URLS)
        self.driver.get(AMAZON_URLS["BASE_URL"])
        if self.is_logged_in():
            log.info("Already logged in")
        else:
            log.info("Lets log in.")
            selenium_utils.button_click_using_xpath(
                self.driver, '//*[@id="nav-link-accountList"]/div/span')
            selenium_utils.wait_for_any_title(self.driver, SIGN_IN_TITLES)
            self.login()
            log.info("Waiting 15 seconds.")
            time.sleep(
                15
            )  # We can remove this once I get more info on the phone verification page.
Exemplo n.º 5
0
 def wait_for_pages(self, page_titles, t=30):
     log.debug(f"wait_for_pages({page_titles}, {t})")
     try:
         title = selenium_utils.wait_for_any_title(self.driver, page_titles, t)
         if not title in page_titles:
             log.error(
                 "{} is not a recognized title, report to #tech-support or open an issue on github".format()
             )
         pass
     except Exception as e:
         log.debug(e)
         pass
Exemplo n.º 6
0
 def wait_for_pages(self, page_titles, t=30):
     log.debug(f"wait_for_pages({page_titles}, {t})")
     selenium_utils.wait_for_any_title(self.driver, page_titles, t)
Exemplo n.º 7
0
 def wait_for_pages(self, page_titles, t=30):
     try:
         selenium_utils.wait_for_any_title(self.driver, page_titles, t)
     except Exception as e:
         log.debug(f"wait_for_pages exception: {e}")
         pass
Exemplo n.º 8
0
 def wait_for_cart_page(self):
     selenium_utils.wait_for_any_title(self.driver, SHOPING_CART_TITLES)
     log.info("On cart page.")