instantiating and using_one_ wait object, plus
porting all DOM operations to use waits.
This commit is contained in:
parent
38185fb187
commit
ca2073c22a
@ -22,9 +22,11 @@ import os
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
|
logging.basicConfig(format='%(levelname)s: %(message)s',
|
||||||
|
level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
taler_baseurl = os.environ.get('TALER_BASEURL', 'https://test.taler.net/')
|
taler_baseurl = os.environ.get('TALER_BASEURL',
|
||||||
|
'https://test.taler.net/')
|
||||||
display = Display(visible=0, size=(1024, 768))
|
display = Display(visible=0, size=(1024, 768))
|
||||||
|
|
||||||
def kill_display():
|
def kill_display():
|
||||||
@ -38,7 +40,6 @@ def abort(client):
|
|||||||
kill_display()
|
kill_display()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def client_setup(args):
|
def client_setup(args):
|
||||||
"""Return a dict containing the driver and the extension's id"""
|
"""Return a dict containing the driver and the extension's id"""
|
||||||
co = webdriver.ChromeOptions()
|
co = webdriver.ChromeOptions()
|
||||||
@ -56,7 +57,8 @@ def client_setup(args):
|
|||||||
if not args.withhead:
|
if not args.withhead:
|
||||||
display.start()
|
display.start()
|
||||||
if args.remote:
|
if args.remote:
|
||||||
client = webdriver.Remote(desired_capabilities=cap, command_executor=args.remote)
|
client = webdriver.Remote(desired_capabilities=cap,
|
||||||
|
command_executor=args.remote)
|
||||||
else:
|
else:
|
||||||
client = webdriver.Chrome(desired_capabilities=cap)
|
client = webdriver.Chrome(desired_capabilities=cap)
|
||||||
client.get('https://taler.net')
|
client.get('https://taler.net')
|
||||||
@ -100,7 +102,8 @@ def make_donation(client, amount_menuentry):
|
|||||||
the wallet has coins. Just donate to the default receiver"""
|
the wallet has coins. Just donate to the default receiver"""
|
||||||
client.get(parse.urljoin(taler_baseurl, "donations"))
|
client.get(parse.urljoin(taler_baseurl, "donations"))
|
||||||
try:
|
try:
|
||||||
form = client.find_element(By.TAG_NAME, "form")
|
form = wait.until(EC.visibility_of_element_located((By.TAG_NAME,
|
||||||
|
"form")))
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error('No donation form found')
|
logger.error('No donation form found')
|
||||||
return False
|
return False
|
||||||
@ -109,7 +112,7 @@ def make_donation(client, amount_menuentry):
|
|||||||
dropdown = client.find_element(By.XPATH, xpath_menu)
|
dropdown = client.find_element(By.XPATH, xpath_menu)
|
||||||
for option in dropdown.find_elements_by_tag_name("option"):
|
for option in dropdown.find_elements_by_tag_name("option"):
|
||||||
if option.get_attribute("innerHTML") == amount_menuentry:
|
if option.get_attribute("innerHTML") == amount_menuentry:
|
||||||
option = WebDriverWait(client, 10).until(EC.visibility_of(option))
|
option = wait.until(EC.visibility_of(option))
|
||||||
option.click()
|
option.click()
|
||||||
break
|
break
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
@ -117,9 +120,9 @@ def make_donation(client, amount_menuentry):
|
|||||||
' is not offered by this shop to donate")
|
' is not offered by this shop to donate")
|
||||||
return False
|
return False
|
||||||
form.submit()
|
form.submit()
|
||||||
wait = WebDriverWait(client, 10)
|
|
||||||
try:
|
try:
|
||||||
confirm_taler = wait.until(EC.element_to_be_clickable((By.ID, "select-payment-method")))
|
confirm_taler = wait.until(EC.element_to_be_clickable((By.ID,
|
||||||
|
"select-payment-method")))
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error('Could not trigger contract on donation shop')
|
logger.error('Could not trigger contract on donation shop')
|
||||||
return False
|
return False
|
||||||
@ -138,10 +141,11 @@ def make_donation(client, amount_menuentry):
|
|||||||
|
|
||||||
def check_article(client, title):
|
def check_article(client, title):
|
||||||
try:
|
try:
|
||||||
client.find_element(By.XPATH,
|
wait.until(EC.visibility_of_element_located((By.XPATH,
|
||||||
"//h1[contains(., '%s')]" % title.replace("_", " "))
|
"//h1[contains(., '%s')]" % title.replace("_", " "))))
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("Article '%s' not shown on this (%s) page" % (title, client.current_url))
|
logger.error("Article '%s' not shown on this (%s) page\
|
||||||
|
" % (title, client.current_url))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -156,10 +160,7 @@ def buy_article(client, title, fulfillment_url=None):
|
|||||||
if check_article(client, title):
|
if check_article(client, title):
|
||||||
return fulfillment_url
|
return fulfillment_url
|
||||||
return False
|
return False
|
||||||
|
|
||||||
client.get(parse.urljoin(taler_baseurl, "shop"))
|
client.get(parse.urljoin(taler_baseurl, "shop"))
|
||||||
wait = WebDriverWait(client, 20)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
teaser = wait.until(EC.element_to_be_clickable((By.XPATH,
|
teaser = wait.until(EC.element_to_be_clickable((By.XPATH,
|
||||||
"//h3/a[@href=\"/essay/%s\"]" % title)))
|
"//h3/a[@href=\"/essay/%s\"]" % title)))
|
||||||
@ -186,28 +187,27 @@ def register(client):
|
|||||||
until the profile page is shown"""
|
until the profile page is shown"""
|
||||||
client.get(parse.urljoin(taler_baseurl, "bank"))
|
client.get(parse.urljoin(taler_baseurl, "bank"))
|
||||||
try:
|
try:
|
||||||
register_link = client.find_element(By.XPATH,
|
register_link = wait.until(EC.element_to_be_clickable((By.XPATH,
|
||||||
"//a[@href='/accounts/register/']")
|
"//a[@href='/accounts/register/']")))
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("Could not find register link on bank's homepage")
|
logger.error("Could not find register link on bank's homepage")
|
||||||
return False
|
return False
|
||||||
register_link.click()
|
register_link.click()
|
||||||
try:
|
try:
|
||||||
client.find_element(By.TAG_NAME, "form")
|
wait.until(EC.visibility_of_element_located((By.TAG_NAME, "form")))
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("Register form not found")
|
logger.error("Register form not found")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
register = """\
|
register = """\
|
||||||
var form = document.getElementsByTagName('form')[0];
|
var form = document.getElementsByTagName('form')[0];
|
||||||
form.username.value = '%s';
|
form.username.value = '%s';
|
||||||
form.password.value = 'test';
|
form.password.value = 'test';
|
||||||
form.submit();
|
form.submit();
|
||||||
""" % str(int(time.time()))
|
""" % str(int(time.time()))
|
||||||
|
|
||||||
client.execute_script(register)
|
client.execute_script(register)
|
||||||
try:
|
try:
|
||||||
button = client.find_element(By.ID, "select-exchange")
|
wait.until(EC.element_to_be_clickable((By.ID,
|
||||||
|
"select-exchange")))
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("Selecting exchange impossible")
|
logger.error("Selecting exchange impossible")
|
||||||
return False
|
return False
|
||||||
@ -216,26 +216,27 @@ def register(client):
|
|||||||
|
|
||||||
def withdraw(client, amount_menuentry):
|
def withdraw(client, amount_menuentry):
|
||||||
"""Register and withdraw (1) KUDOS for a fresh user"""
|
"""Register and withdraw (1) KUDOS for a fresh user"""
|
||||||
wait = WebDriverWait(client, 10)
|
|
||||||
# trigger withdrawal button
|
# trigger withdrawal button
|
||||||
try:
|
try:
|
||||||
button = client.find_element(By.ID, "select-exchange")
|
button = wait.until(EC.element_to_be_clickable((By.ID,
|
||||||
|
"select-exchange")))
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("Selecting exchange impossible")
|
logger.error("Selecting exchange impossible")
|
||||||
return False
|
return False
|
||||||
xpath_menu = '//select[@id="reserve-amount"]'
|
xpath_menu = '//select[@id="reserve-amount"]'
|
||||||
try:
|
try:
|
||||||
|
# No need to wait: if 'button' above exists, then
|
||||||
|
# menu elements do.
|
||||||
dropdown = client.find_element(By.XPATH, xpath_menu)
|
dropdown = client.find_element(By.XPATH, xpath_menu)
|
||||||
for option in dropdown.find_elements_by_tag_name("option"):
|
for option in dropdown.find_elements_by_tag_name("option"):
|
||||||
if option.get_attribute("innerHTML") == amount_menuentry:
|
if option.get_attribute("innerHTML") == amount_menuentry:
|
||||||
option = WebDriverWait(client, 10).until(EC.visibility_of(option))
|
option = wait.until(EC.visibility_of(option))
|
||||||
option.click()
|
option.click()
|
||||||
break
|
break
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("amount '" + str(amount_value) + "' \
|
logger.error("amount '" + str(amount_value) + "' \
|
||||||
is not offered by this bank to withdraw")
|
is not offered by this bank to withdraw")
|
||||||
return False
|
return False
|
||||||
# confirm amount
|
|
||||||
button.click()
|
button.click()
|
||||||
# Confirm exchange (in-wallet page)
|
# Confirm exchange (in-wallet page)
|
||||||
try:
|
try:
|
||||||
@ -246,8 +247,11 @@ def withdraw(client, amount_menuentry):
|
|||||||
return False
|
return False
|
||||||
accept_exchange.click()
|
accept_exchange.click()
|
||||||
try:
|
try:
|
||||||
answer = client.find_element(By.XPATH, "//input[@name='pin_0']")
|
answer = wait.until(EC.element_to_be_clickable((By.XPATH,
|
||||||
question = client.find_element(By.XPATH, "//span[@class='captcha-question']/div")
|
"//input[@name='pin_0']")))
|
||||||
|
question = wait.until(EC.element_to_be_clickable((By.XPATH,
|
||||||
|
"//span[@class='captcha-question']/div")))
|
||||||
|
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("Captcha page unavailable or malformed")
|
logger.error("Captcha page unavailable or malformed")
|
||||||
return False
|
return False
|
||||||
@ -257,6 +261,8 @@ def withdraw(client, amount_menuentry):
|
|||||||
res = {'+': op1 + op2, '-': op1 - op2, u'\u00d7': op1 * op2}
|
res = {'+': op1 + op2, '-': op1 - op2, u'\u00d7': op1 * op2}
|
||||||
answer.send_keys(res[questionTok[3]])
|
answer.send_keys(res[questionTok[3]])
|
||||||
try:
|
try:
|
||||||
|
# No need to wait, if CAPTCHA elements exists
|
||||||
|
# then submitting button has to.
|
||||||
form = client.find_element(By.TAG_NAME, "form")
|
form = client.find_element(By.TAG_NAME, "form")
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("Could not submit captcha answer")
|
logger.error("Could not submit captcha answer")
|
||||||
@ -264,13 +270,13 @@ def withdraw(client, amount_menuentry):
|
|||||||
form.submit()
|
form.submit()
|
||||||
# check outcome
|
# check outcome
|
||||||
try:
|
try:
|
||||||
client.find_element(By.CLASS_NAME, "informational-ok")
|
wait.until(EC.presence_of_element_located((By.CLASS_NAME,
|
||||||
|
"informational-ok")))
|
||||||
except NoSuchElementException:
|
except NoSuchElementException:
|
||||||
logger.error("Withdrawal not completed")
|
logger.error("Withdrawal not completed")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--ext', help="packed extension (.crx file)",
|
parser.add_argument('--ext', help="packed extension (.crx file)",
|
||||||
metavar="CRX", type=str, dest="ext")
|
metavar="CRX", type=str, dest="ext")
|
||||||
@ -286,7 +292,7 @@ parser.add_argument('--with-head',
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
client = client_setup(args)['client']
|
client = client_setup(args)['client']
|
||||||
client.implicitly_wait(10)
|
wait = WebDriverWait(client, 20)
|
||||||
|
|
||||||
if not register(client):
|
if not register(client):
|
||||||
abort(client)
|
abort(client)
|
||||||
|
Loading…
Reference in New Issue
Block a user