Beispiel #1
0
 def setUpClass(cls):
     cmd = ("node", "app.js")
     env = os.environ.copy()
     env.update({"PORT": "3000",
                 "NO_LOCAL_CONFIG": "true",
                 "NODE_ENV": "test"})
     cls.node_app = subprocess.Popen(cmd, env=env)
     cls.drvr = driver.create()
     cls.drvr.implicitly_wait(20)
 def setUp(self):
     super(FrontEndSuite, self).setUp()
     cmd = ("node", "app.js")
     env = os.environ.copy()
     env.update({"PORT": "3000",
                 "NO_LOCAL_CONFIG": "true",
                 "NODE_ENV": "test"})
     self.node_app = subprocess.Popen(cmd, env=env)
     self.addCleanup(kill_app, self.node_app)
     self.drvr = driver.create()
     self.drvr.implicitly_wait(20)
 def setUpClass(cls):
     # XXX: we should DRY-ify the server startup via python
     # scripts. For now we do that in:
     #   - test/frontend/test_frontend_all.py
     #   - test/functional/browser_test.py
     cmd = ("node", "app.js")
     env = os.environ.copy()
     env.update({"PORT": "3000",
                 "NO_LOCAL_CONFIG": "true",
                 "NODE_ENV": "test",
                 "SESSION_SECRET": "unguessable"})
     cls.node_app = subprocess.Popen(cmd, env=env)
     cls.drvr = driver.create()
     cls.drvr.implicitly_wait(20)
Beispiel #4
0
 def setUpClass(cls):
     # XXX: we should DRY-ify the server startup via python
     # scripts. For now we do that in:
     #   - test/frontend/test_frontend_all.py
     #   - test/functional/browser_test.py
     cmd = ("node", "app.js")
     env = os.environ.copy()
     env.update({
         "PORT": "3000",
         "NO_LOCAL_CONFIG": "true",
         "NODE_ENV": "test",
         "SESSION_SECRET": "unguessable"
     })
     cls.node_app = subprocess.Popen(cmd, env=env)
     cls.drvr = driver.create()
     cls.drvr.implicitly_wait(20)
Beispiel #5
0
 def setUp(self):
     super(WithLarry, self).setUp()
     self.larry = driver.create("larry")
Beispiel #6
0
 def setUp(self):
     super(WithBob, self).setUp()
     self.bob = driver.create("bob")
Beispiel #7
0
 def setUpClass(cls):
     super(WithSingleBob, cls).setUpClass()
     cls.bob = driver.create("bob")
Beispiel #8
0
def main():
    parser = args.create_parser()
    parser.add_argument("--email", type=str, help="Amazon account email")
    parser.add_argument("--password", type=str, help="Amazon account password")
    parser.add_argument("--morning-only",
                        dest='morning_only',
                        action='store_true')
    parser.add_argument("--no-morning-only",
                        dest='morning_only',
                        action='store_false')
    parser.set_defaults(morning_only=True)
    a = parser.parse_args()

    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.INFO,
                        datefmt='%Y-%m-%d %H:%M:%S')

    try:
        d = driver.create(a.selenium_driver, a.headless, a.private,
                          a.user_agent)
        d.set_window_size(640, 480)
        d.implicitly_wait(a.short_timeout_secs)
        amazon.signin(d, a.email, a.password, a.short_timeout_secs,
                      a.long_timeout_secs)

        while True:
            try:
                logging.info("Loading localmarket and checking out...")
                d.get("https://www.amazon.com/cart/localmarket")
                el = WebDriverWait(d, a.long_timeout_secs).until(
                    EC.element_to_be_clickable(
                        (By.CSS_SELECTOR,
                         "input[value='Proceed to checkout']")))
                el.click()

                while True:
                    el = WebDriverWait(d, a.long_timeout_secs).until(
                        EC.presence_of_element_located((
                            By.CSS_SELECTOR,
                            "[name=proceedToCheckout], #subsContinueButton, .ufss-date-select-toggle-container button"
                        )))
                    if el.get_attribute("name") == "proceedToCheckout":
                        logging.info("Proceed to checkout...")
                        el = WebDriverWait(d, a.short_timeout_secs).until(
                            EC.element_to_be_clickable(
                                (By.NAME, "proceedToCheckout")))
                        el.click()
                        WebDriverWait(d, a.long_timeout_secs).until(
                            EC.staleness_of(el))
                    elif el.get_attribute("id") == "subsContinueButton":
                        logging.info("Will allow substitution.")
                        el = WebDriverWait(d, a.short_timeout_secs).until(
                            EC.element_to_be_clickable(
                                (By.ID, "subsContinueButton")))
                        el.click()
                        WebDriverWait(d, a.long_timeout_secs).until(
                            EC.staleness_of(el))
                    else:
                        break

                dates = d.find_elements_by_css_selector(
                    ".ufss-date-select-toggle-container")
                logging.info("Checking %d dates..." % len(dates))
                for date in dates:
                    btn = date.find_element_by_tag_name("button")
                    date_str = btn.get_attribute("name")
                    try:
                        date.find_element_by_class_name("a-button-unavailable")
                        logging.warning("%s not available." % date_str)
                    except NoSuchElementException:
                        logging.info("Will use %s." % date_str)
                        try:
                            date.find_element_by_class_name(
                                "a-button-selected")
                        except NoSuchElementException:
                            btn.click()
                        time.sleep(1)
                        slot_ctns = d.find_elements_by_class_name(
                            "ufss-slot-container")
                        for index, slot_ctn in enumerate(slot_ctns, start=1):
                            time_str = slot_ctn.find_element_by_class_name(
                                "ufss-aok-offscreen").get_attribute(
                                    "innerText")
                            price_str = slot_ctn.find_element_by_class_name(
                                "ufss-slot-price-text").get_attribute(
                                    "innerText")
                            logging.info("Found slot '%s', price is '%s'." %
                                         (time_str, price_str))
                            if price_str == "FREE" and (
                                    not a.morning_only
                                    or time_str.endswith('AM')):
                                logging.info("Will use %s." % time_str)
                                btn = WebDriverWait(
                                    d, a.short_timeout_secs
                                ).until(
                                    EC.element_to_be_clickable((
                                        By.CSS_SELECTOR,
                                        ".ufss-slot-container:nth-child(%d) button"
                                        % index)))
                                d.execute_script(
                                    "arguments[0].scrollIntoView();", btn)
                                btn.click()
                                WebDriverWait(d, a.short_timeout_secs).until(
                                    EC.element_to_be_clickable(
                                        (By.CSS_SELECTOR,
                                         "input[type=submit]"))).click()
                                WebDriverWait(d, a.long_timeout_secs).until(
                                    EC.element_to_be_clickable((
                                        By.CSS_SELECTOR,
                                        "#order-summary-container #continue-top"
                                    ))).click()
                                WebDriverWait(d, a.long_timeout_secs).until(
                                    EC.element_to_be_clickable(
                                        (By.NAME, "placeYourOrder1"))).click()
                                return
            except TimeoutException:
                logging.warning("Timeout. Will retry")
            logging.info("Sleep before retry.")
            time.sleep(a.long_timeout_secs)

    except TimeoutException:
        logging.warning("Timeout.")
    finally:
        pass
Beispiel #9
0
_sleep_seconds = const(300)
_step_speed_in_ms = const(
    8)  # The larger, the slower RPM.Either FULL_STEP or HALF_STEP
_sweep_steps = const(15)


def sweep() -> None:
    for i in range(5):
        motor.step(_sweep_steps)
        time.sleep(2)
        motor.step(_sweep_steps, -1)
        time.sleep(2)


if __name__ == '__main__':
    '''
    IN1 -->  D8:15
    IN2 -->  D7:13
    IN3 -->  D6:12
    IN4 -->  D5:14
    '''
    motor = driver.create(Pin(15, Pin.OUT),
                          Pin(13, Pin.OUT),
                          Pin(12, Pin.OUT),
                          Pin(14, Pin.OUT),
                          delay=_step_speed_in_ms)

    while True:
        sweep()
        time.sleep(_sleep_seconds)
Beispiel #10
0
 def setUp(self):
     super(WithAlice, self).setUp()
     self.alice = driver.create("alice")