-
Notifications
You must be signed in to change notification settings - Fork 20
/
tests.py
61 lines (42 loc) · 1.9 KB
/
tests.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
61
import time, threading
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from utils import import_proxies_from_file, get_user_agent
from bot import transfer_session
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def add_to_cart(driver, cc='NL'):
if cc == 'US':
url = 'http://www.adidas.com/on/demandware.store/Sites-adidas-US-Site/en_US/Cart-MiniAddProduct?pid=BA8561_560&masterPid=BA8561&Quantity=1&ajax=true'
else:
url = 'http://www.adidas.nl/on/demandware.store/Sites-adidas-NL-Site/nl_NL/Cart-MiniAddProduct?pid=BB0945_560&masterPid=BB0945&Quantity=1&ajax=true'
driver.get(url)
return url
def _transfer_test():
# which proxy to use? 0 = first
# TODO: add a better way to specify the proxy
PROXY_INDEX = 0
# Session Transfer Testing
PROXIES = import_proxies_from_file()
proxy, proxy_auth = PROXIES[PROXY_INDEX]
service_args = ['--proxy={}'.format(proxy), '--proxy-type=html', '--ignore-ssl-errors=true']
if proxy_auth:
service_args.append('--proxy-auth={}'.format(proxy_auth))
browser = webdriver.PhantomJS(executable_path='bin/phantomjs', service_args=service_args)
browser.set_page_load_timeout(30)
add_to_cart(browser, cc='US')
payload = {
'browser': browser,
'user_agent': get_user_agent(),
'proxy': proxy
}
# Test transferring session (go to ipecho.net to see ip, got to cart to see if in cart)
threading.Thread(target=transfer_session, kwargs={'browser': payload}).start()
time.sleep(60 * 60)
def _test_phantomjs_dynamic_cookies():
# Use http://tools.yzy.io/hmac.html as PRODUCT_URL to test
# That page will set a (fake) hmac cookie after 10 seconds
pass
_transfer_test()