selenium tests in "/component" form + fetching baseurl from env
This commit is contained in:
parent
07715206e5
commit
5ea6f8dd00
@ -1,13 +1,22 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Tests for the wallet. It looks for an env variable called TALER_BASEURL
|
||||||
|
where it appends "/banks" etc. in order to find bank and shops. If not
|
||||||
|
found, it defaults to https://test.taler.net/
|
||||||
|
"""
|
||||||
|
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
|
from urllib import parse
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
bank = 'http://bank.test.taler.net'
|
taler_baseurl = os.environ['TALER_BASEURL'] if 'TALER_BASEURL' in os.environ else 'https://test.taler.net/'
|
||||||
donations = 'http://shop.test.taler.net'
|
|
||||||
|
|
||||||
def client_setup():
|
def client_setup():
|
||||||
"""Return a dict containing the driver and the extension's id"""
|
"""Return a dict containing the driver and the extension's id"""
|
||||||
@ -27,10 +36,19 @@ def client_setup():
|
|||||||
document.dispatchEvent(evt);
|
document.dispatchEvent(evt);
|
||||||
"""
|
"""
|
||||||
client.execute_script(listener)
|
client.execute_script(listener)
|
||||||
client.implicitly_wait(5)
|
|
||||||
html = client.find_element(By.TAG_NAME, "html")
|
html = client.find_element(By.TAG_NAME, "html")
|
||||||
return {'client': client, 'ext_id': html.get_attribute('data-taler-wallet-id')}
|
return {'client': client, 'ext_id': html.get_attribute('data-taler-wallet-id')}
|
||||||
|
|
||||||
|
# Note that the db appears to be reset automatically by the driver
|
||||||
|
def destroy_db(client, ext_id):
|
||||||
|
url = 'chrome-extension://' + ext_id + '/popup/popup.html#/debug'
|
||||||
|
client.get(url)
|
||||||
|
button = client.find_element(By.XPATH, "//div[@id='content']/button[3]")
|
||||||
|
button.click()
|
||||||
|
time.sleep(4)
|
||||||
|
alert = client.switch_to.alert
|
||||||
|
alert.accept()
|
||||||
|
|
||||||
|
|
||||||
def is_error(client):
|
def is_error(client):
|
||||||
"""Return True in case of errors in the browser, False otherwise"""
|
"""Return True in case of errors in the browser, False otherwise"""
|
||||||
@ -44,7 +62,7 @@ def is_error(client):
|
|||||||
|
|
||||||
def make_donation(client):
|
def make_donation(client):
|
||||||
"""Make donation at shop.test.taler.net. Assume the wallet has coins"""
|
"""Make donation at shop.test.taler.net. Assume the wallet has coins"""
|
||||||
client.get(donations)
|
client.get(parse.urljoin(taler_baseurl, "shop"))
|
||||||
form = client.find_element(By.TAG_NAME, "form")
|
form = client.find_element(By.TAG_NAME, "form")
|
||||||
form.submit() # amount and receiver chosen
|
form.submit() # amount and receiver chosen
|
||||||
confirm_taler = client.find_element(By.XPATH, "//form//input[@type='button']")
|
confirm_taler = client.find_element(By.XPATH, "//form//input[@type='button']")
|
||||||
@ -53,10 +71,23 @@ def make_donation(client):
|
|||||||
confirm_pay = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='accept']")))
|
confirm_pay = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='accept']")))
|
||||||
confirm_pay.click()
|
confirm_pay.click()
|
||||||
|
|
||||||
|
|
||||||
|
def buy_article(client):
|
||||||
|
"""Buy article at blog.test.taler.net. Assume the wallet has coins"""
|
||||||
|
client.get(parse.urljoin(taler_baseurl, "blog"))
|
||||||
|
teaser = client.find_element(By.XPATH, "//ul/h3/a[1]") # Pick 'Foreword' chapter
|
||||||
|
teaser.click()
|
||||||
|
wait = WebDriverWait(client, 10)
|
||||||
|
confirm_pay = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='accept']")))
|
||||||
|
confirm_pay.click()
|
||||||
|
|
||||||
|
|
||||||
def register(client):
|
def register(client):
|
||||||
"""Register a new user to the bank delaying its execution until the
|
"""Register a new user to the bank delaying its execution until the
|
||||||
profile page is shown"""
|
profile page is shown"""
|
||||||
client.get(bank + '/accounts/register')
|
client.get(parse.urljoin(taler_baseurl, "bank"))
|
||||||
|
register_link = client.find_element(By.XPATH, "//a[@href='/accounts/register/']")
|
||||||
|
register_link.click()
|
||||||
client.find_element(By.TAG_NAME, "form")
|
client.find_element(By.TAG_NAME, "form")
|
||||||
register = """\
|
register = """\
|
||||||
var form = document.getElementsByTagName('form')[0];
|
var form = document.getElementsByTagName('form')[0];
|
||||||
@ -107,6 +138,8 @@ def withdraw(client):
|
|||||||
|
|
||||||
ret = client_setup()
|
ret = client_setup()
|
||||||
client = ret['client']
|
client = ret['client']
|
||||||
|
client.implicitly_wait(10)
|
||||||
withdraw(client)
|
withdraw(client)
|
||||||
make_donation(client)
|
make_donation(client)
|
||||||
# client.close()
|
buy_article(client)
|
||||||
|
client.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user