-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_amazonFresh.py
60 lines (44 loc) · 2.33 KB
/
test_amazonFresh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import yagmail
import numpy as np
EMAIL_SENDER = '' # An alert email will be sent from this gmail address
PASSWORD_SENDER = '' # Password for the sender's email address
CHROME_PROFILE_PATH = '' # Path to your Chrome default profile, e.g., C:\Users\username\AppData\Local\Google\Chrome\User Data
CHROME_DRIVER_PATH = '' # Path where your chromedriver is located e.g., C:\Users\username\Tools\chromedriver.exe
EMAILS = [] # A list of emails addresses to receive the alert e.g, ['abc.gmail.com', 'xyz.gmail.com']
AMZ_FRESH_SELECT_TIME_PAGE_LINK = '' # The reserve time slot link (see README)
DATES = ['2020-04-06', '2020-04-07'] # Check available slots in these dates.
class TestAmazonFresh():
def setup_method(self, method):
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir={}'.format(CHROME_PROFILE_PATH)) #Path to your chrome profile
self.driver = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH, options=options)
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_amazonFresh(self):
def send_notification():
message = 'Hey, time for Amazon Fresh!!!'
for email in EMAILS:
yagmail.SMTP(EMAIL_SENDER, PASSWORD_SENDER).send(email, 'Amazon Fresh is opening slots!', message)
time.sleep(1200)
while True:
self.driver.get(AMZ_FRESH_SELECT_TIME_PAGE_LINK)
for date in DATES:
time.sleep(np.random.randint(low=1, high=5))
self.driver.find_element(By.CSS_SELECTOR, '#date-button-{}-announce .a-section:nth-child(2)'.format(date)).click()
elements = self.driver.find_elements(By.CSS_SELECTOR, '#slot-button-root-{}-UNATTENDED-Start-05-00-End-07-00 .a-label'.format(date))
if len(elements) > 0:
send_notification()
time.sleep(np.random.randint(low=60, high=300))