Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Commit

Permalink
Update to new checkout flow + add expensive shirt for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
philippnormann committed Oct 27, 2020
1 parent f438386 commit 86d754b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 91 deletions.
22 changes: 11 additions & 11 deletions config/customer_template.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"locale": "de-de",
"locale": "en-us",
"billing": {
"first-name": "Jensen",
"last-name": "Huang",
"address-line-1": "Einsteinstr. 172",
"address-line-1": "2788 San Tomas Expy",
"address-line-2": "",
"state": "",
"city": "München",
"post-code": "81677",
"country": "DE",
"state": "CA",
"city": "Santa Clara",
"post-code": "95051",
"country": "US",
"email": "[email protected]",
"phone": "408-486-2000"
},
"shipping": {
"first-name": "Lisa",
"last-name": "Su",
"address-line-1": "Einsteinring 24",
"address-line-1": "2485 Augustine Dr",
"address-line-2": "",
"state": "",
"city": "Aschheim",
"post-code": "85609",
"country": "DE",
"state": "CA",
"city": "Santa Clara",
"post-code": "95054",
"country": "US",
"phone": "89-4505-3199",
"speed": "shippingOptionID2",
"backup-speed": true
Expand Down
4 changes: 4 additions & 0 deletions data/gpus.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
"rtx-2060-super": {
"name": "GeForce RTX 2060 Super",
"url": "/geforce/graphics-cards/rtx-2060-super"
},
"expensive-shirt": {
"name": "Expensive Shirt (Test Product)",
"url": "/geforce/graphics-cards/30-series/"
}
}
45 changes: 30 additions & 15 deletions data/skus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"titan-rtx": "5254456900",
"rtx-2080-super": "5335703700",
"rtx-2070-super": "5394901600",
"rtx-2060-super": "5394902900"
"rtx-2060-super": "5394902900",
"expensive-shirt": "5444021500"
},
"fr-fr": {
"rtx-3090": "5438761500",
Expand All @@ -15,7 +16,8 @@
"titan-rtx": "5256301100",
"rtx-2080-super": "5336531100",
"rtx-2070-super": "5394901900",
"rtx-2060-super": "5394903200"
"rtx-2060-super": "5394903200",
"expensive-shirt": "5444021500"
},
"de-de": {
"rtx-3090": "5438761400",
Expand All @@ -24,7 +26,8 @@
"titan-rtx": "5256301000",
"rtx-2080-super": "5335703700",
"rtx-2070-super": "5394901600",
"rtx-2060-super": "5394902900"
"rtx-2060-super": "5394902900",
"expensive-shirt": "5444021500"
},
"en-gb": {
"rtx-3090": "5438792700",
Expand All @@ -33,7 +36,8 @@
"titan-rtx": "5256301200",
"rtx-2080-super": "5336531200",
"rtx-2070-super": "5394902000",
"rtx-2060-super": "5394903300"
"rtx-2060-super": "5394903300",
"expensive-shirt": "5444021500"
},
"es-es": {
"rtx-3090": "5438794700",
Expand All @@ -42,7 +46,8 @@
"titan-rtx": "5256301400",
"rtx-2080-super": "5336531400",
"rtx-2070-super": "5394901700",
"rtx-2060-super": "5394903000"
"rtx-2060-super": "5394903000",
"expensive-shirt": "5444021500"
},
"it-it": {
"rtx-3090": "5438796100",
Expand All @@ -51,7 +56,8 @@
"titan-rtx": "5256302000",
"rtx-2080-super": "5336532000",
"rtx-2070-super": "5394902100",
"rtx-2060-super": "5394903400"
"rtx-2060-super": "5394903400",
"expensive-shirt": "5444021500"
},
"pl-pl": {
"rtx-3090": "5438797600",
Expand All @@ -60,7 +66,8 @@
"titan-rtx": "5256301600",
"rtx-2080-super": "5336531600",
"rtx-2070-super": "5394902300",
"rtx-2060-super": "5394903700"
"rtx-2060-super": "5394903700",
"expensive-shirt": "5444021500"
},
"nb-no": {
"rtx-3090": "5438797100",
Expand All @@ -69,7 +76,8 @@
"titan-rtx": "5256301700",
"rtx-2080-super": "5336531700",
"rtx-2070-super": "5394902600",
"rtx-2060-super": "5394903600"
"rtx-2060-super": "5394903600",
"expensive-shirt": "5444021500"
},
"sv-se": {
"rtx-3090": "5438761600",
Expand All @@ -78,7 +86,8 @@
"titan-rtx": "5256301300",
"rtx-2080-super": "5336531300",
"rtx-2070-super": "5394902500",
"rtx-2060-super": "5394903900"
"rtx-2060-super": "5394903900",
"expensive-shirt": "5444021500"
},
"da-dk": {
"rtx-3090": "5438793200",
Expand All @@ -87,7 +96,8 @@
"titan-rtx": "5256301800",
"rtx-2080-super": "5336531800",
"rtx-2070-super": "5394901800",
"rtx-2060-super": "5394903100"
"rtx-2060-super": "5394903100",
"expensive-shirt": "5444021500"
},
"fr-be": {
"rtx-3090": "5438795600",
Expand All @@ -96,7 +106,8 @@
"titan-rtx": "5256301500",
"rtx-2080-super": "5336531500",
"rtx-2070-super": "5336534300",
"rtx-2060-super": "5394902700"
"rtx-2060-super": "5394902700",
"expensive-shirt": "5444021500"
},
"de-at": {
"rtx-3090": "5444941400",
Expand All @@ -105,7 +116,8 @@
"titan-rtx": "5256301000",
"rtx-2080-super": "5335703700",
"rtx-2070-super": "5394901600",
"rtx-2060-super": "5394902900"
"rtx-2060-super": "5394902900",
"expensive-shirt": "5444021500"
},
"cs-cz": {
"rtx-3090": "5438793600",
Expand All @@ -114,7 +126,8 @@
"titan-rtx": "5256301900",
"rtx-2080-super": "5336531900",
"rtx-2070-super": "5394901500",
"rtx-2060-super": "5394902800"
"rtx-2060-super": "5394902800",
"expensive-shirt": "5444021500"
},
"fi-fi": {
"rtx-3090": "5438793200",
Expand All @@ -123,7 +136,8 @@
"titan-rtx": "5256301800",
"rtx-2080-super": "5336531800",
"rtx-2070-super": "5394901800",
"rtx-2060-super": "5394903100"
"rtx-2060-super": "5394903100",
"expensive-shirt": "5444021500"
},
"nl-nl": {
"rtx-3090": "5438796600",
Expand All @@ -132,6 +146,7 @@
"titan-rtx": "5256302100",
"rtx-2080-super": "5336532100",
"rtx-2070-super": "5394902200",
"rtx-2060-super": "5394903500"
"rtx-2060-super": "5394903500",
"expensive-shirt": "5444021500"
}
}
151 changes: 86 additions & 65 deletions sniper/checkout.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import logging
import random
import string
Expand Down Expand Up @@ -33,7 +34,57 @@ def get_product_page(driver, promo_locale, gpu):
return False


def fill_out_shipping(driver, timeout, customer):
logging.info('Filling out shipping details...')
shipping_expanded = False
while not shipping_expanded:
try:
driver.find_element(By.ID, 'shippingName1').send_keys(
customer['shipping']['first-name'])
shipping_expanded = True
except ElementNotInteractableException:
expand_shipping_button = driver.find_element(
By.ID, 'shippingDifferentThanBilling')
scroll_to(driver, expand_shipping_button)
expand_shipping_button.click()
shipping_visible = EC.visibility_of_element_located(
(By.ID, 'shippingName1'))
WebDriverWait(driver, timeout).until(shipping_visible)

driver.find_element(By.ID, 'shippingName2').send_keys(
customer['shipping']['last-name'])

driver.find_element(By.ID, 'shippingAddress1').send_keys(
customer['shipping']['address-line-1'])
driver.find_element(By.ID, 'shippingAddress2').send_keys(
customer['shipping']['address-line-2'])

try:
driver.find_element(By.ID, 'shippingState')
state_select = Select(driver.find_element_by_id('shippingState'))
state_select.select_by_value(customer['shipping']['state'])
except NoSuchElementException:
pass

try:
driver.find_element(By.ID, 'shippingCountry')
country_select = Select(
driver.find_element_by_id('shippingCountry'))
country_select.select_by_value(customer['shipping']['country'])
except NoSuchElementException:
pass

driver.find_element(By.ID, 'shippingCity').send_keys(
customer['shipping']['city'])
driver.find_element(By.ID, 'shippingPostalCode').send_keys(
customer['shipping']['post-code'])

driver.find_element(By.ID, 'shippingPhoneNumber').send_keys(
customer['shipping']['phone'])


def fill_out_form(driver, timeout, customer):
logging.info('Filling out form...')
driver.find_element(By.ID, 'billingName1').send_keys(
customer['billing']['first-name'])
driver.find_element(By.ID, 'billingName2').send_keys(
Expand Down Expand Up @@ -70,69 +121,7 @@ def fill_out_form(driver, timeout, customer):
driver.find_element(By.ID, 'verEmail').send_keys(
customer['billing']['email'])

if 'shipping' in customer:
try:
shipping_speed = customer['shipping']['speed']
driver.find_element(By.ID, shipping_speed).click()
except Exception:
logging.warning(f'Could not find shipping speed {shipping_speed}')
if 'backup-speed' in customer['shipping']:
if customer['shipping']['backup-speed']:
logging.info('Continuing with default speed')
else:
logging.info(
'User opted to stop if shipping speed not found.')
exit()
else:
logging.warning(
'data/customer.json missing "backup-speed" option under "shipping", '
'continuing with default speed')

shipping_expanded = False
while not shipping_expanded:
try:
driver.find_element(By.ID, 'shippingName1').send_keys(
customer['shipping']['first-name'])
shipping_expanded = True
except ElementNotInteractableException:
expand_shipping_button = driver.find_element(
By.ID, 'shippingDifferentThanBilling')
scroll_to(driver, expand_shipping_button)
expand_shipping_button.click()
shipping_visible = EC.visibility_of_element_located(
(By.ID, 'shippingName1'))
WebDriverWait(driver, timeout).until(shipping_visible)

driver.find_element(By.ID, 'shippingName2').send_keys(
customer['shipping']['last-name'])

driver.find_element(By.ID, 'shippingAddress1').send_keys(
customer['shipping']['address-line-1'])
driver.find_element(By.ID, 'shippingAddress2').send_keys(
customer['shipping']['address-line-2'])

try:
driver.find_element(By.ID, 'shippingState')
state_select = Select(driver.find_element_by_id('shippingState'))
state_select.select_by_value(customer['shipping']['state'])
except NoSuchElementException:
pass

try:
driver.find_element(By.ID, 'shippingCountry')
country_select = Select(
driver.find_element_by_id('shippingCountry'))
country_select.select_by_value(customer['shipping']['country'])
except NoSuchElementException:
pass

driver.find_element(By.ID, 'shippingCity').send_keys(
customer['shipping']['city'])
driver.find_element(By.ID, 'shippingPostalCode').send_keys(
customer['shipping']['post-code'])

driver.find_element(By.ID, 'shippingPhoneNumber').send_keys(
customer['shipping']['phone'])
fill_out_shipping(driver, timeout, customer)

driver.find_element(By.ID, 'ccNum').send_keys(
customer['credit']['card'])
Expand All @@ -149,11 +138,39 @@ def fill_out_form(driver, timeout, customer):


def skip_address_check(driver):
driver.find_element(By.ID, 'billingAddressOptionRow2').click()
driver.find_element(By.ID, 'shippingAddressOptionRow2').click()
logging.info('Skipping address check...')
try:
driver.find_element(By.ID, 'billingAddressOptionRow2').click()
except NoSuchElementException:
pass
try:
driver.find_element(By.ID, 'shippingAddressOptionRow2').click()
except NoSuchElementException:
pass
driver.find_element(By.ID, 'selectionButton').click()


def select_shipping_speed(driver, timeout, customer):
try:
shipping_speed = customer['shipping']['speed']
WebDriverWait(driver, timeout).until(
EC.presence_of_element_located((By.ID, shipping_speed)))
driver.find_element(By.ID, shipping_speed).click()
except TimeoutException:
logging.warning(f'Could not find shipping speed {shipping_speed}')
if 'backup-speed' in customer['shipping']:
if customer['shipping']['backup-speed']:
logging.info('Continuing with default speed')
else:
logging.info(
'User opted to stop if shipping speed not found.')
sys.exit()
else:
logging.warning(
'data/customer.json missing "backup-speed" option under "shipping", '
'continuing with default speed')


def click_recaptcha(driver, timeout):
recaptcha_frame = driver.find_element(
By.CSS_SELECTOR, const.RECAPTCHA_FRAME_SELECTOR)
Expand Down Expand Up @@ -182,6 +199,7 @@ def submit_order(driver, timeout):
def checkout_guest(driver, timeout, customer, auto_submit=False):
proceeded_to_form = False
logging.info('Checking out as guest...')

while not proceeded_to_form:
try:
WebDriverWait(driver, timeout).until(
Expand All @@ -203,11 +221,14 @@ def checkout_guest(driver, timeout, customer, auto_submit=False):
driver.find_element(By.CSS_SELECTOR, const.SUBMIT_BUTTON_SELECTOR).click()

try:
logging.info('Skipping address check...')
driver.find_element(By.CLASS_NAME, 'dr_error')
skip_address_check(driver)
except NoSuchElementException:
pass

select_shipping_speed(driver, timeout, customer)


def checkout_paypal(driver, timeout):
proceeded_to_paypal = False
Expand Down

0 comments on commit 86d754b

Please sign in to comment.