putting tests inside "unittest" classes
This commit is contained in:
parent
3777d850eb
commit
67b37dd31e
@ -1,8 +1,12 @@
|
|||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
import time
|
import time
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
def client_setup():
|
||||||
|
"""Return a Chrome browser the extension's id"""
|
||||||
co = webdriver.ChromeOptions()
|
co = webdriver.ChromeOptions()
|
||||||
co.add_argument("load-extension=/home/marcello/Taler/wallet-webex")
|
co.add_argument("load-extension=/home/marcello/wallet-webex")
|
||||||
cap = webdriver.DesiredCapabilities.CHROME.copy()
|
cap = webdriver.DesiredCapabilities.CHROME.copy()
|
||||||
cap['loggingPrefs'] = {'driver': 'INFO', 'browser': 'INFO'}
|
cap['loggingPrefs'] = {'driver': 'INFO', 'browser': 'INFO'}
|
||||||
client = webdriver.Chrome(chrome_options=co, desired_capabilities=cap)
|
client = webdriver.Chrome(chrome_options=co, desired_capabilities=cap)
|
||||||
@ -20,12 +24,13 @@ poll = """\
|
|||||||
return window.extId;
|
return window.extId;
|
||||||
else return false;
|
else return false;
|
||||||
"""
|
"""
|
||||||
# TODO intelligent poller needed
|
# Todo: put some delay in polling
|
||||||
time.sleep(1)
|
|
||||||
ext_id = client.execute_script(poll)
|
ext_id = client.execute_script(poll)
|
||||||
|
return {'client': client, 'ext_id': ext_id}
|
||||||
|
|
||||||
|
|
||||||
# if client has error from its activity, ptints it and returns True
|
|
||||||
def is_error(client):
|
def is_error(client):
|
||||||
|
"""In case of errors in the browser, print them and return True"""
|
||||||
for log_type in ['browser']:
|
for log_type in ['browser']:
|
||||||
for log in client.get_log(log_type):
|
for log in client.get_log(log_type):
|
||||||
if log['level'] is 'error':
|
if log['level'] is 'error':
|
||||||
@ -33,24 +38,49 @@ def is_error(client):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PopupTestCase(unittest.TestCase):
|
||||||
|
"""Test wallet's popups"""
|
||||||
|
def setUp(self):
|
||||||
|
ret = client_setup()
|
||||||
|
self.client = ret['client']
|
||||||
|
self.ext_id = ret['ext_id']
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.client.close()
|
||||||
|
|
||||||
|
def test_popup(self):
|
||||||
|
# keeping only 'balance' to get tests faster. To be
|
||||||
|
# extended with 'history' and 'debug'
|
||||||
labels = ['balance']
|
labels = ['balance']
|
||||||
# labels = ['balance', 'history', 'debug']
|
|
||||||
for l in labels:
|
for l in labels:
|
||||||
client.get('chrome-extension://' + ext_id + '/popup/popup.html#/' + l)
|
self.client.get('chrome-extension://' + self.ext_id + '/popup/popup.html#/' + l)
|
||||||
|
self.assertNotEqual(True, is_error(self.client))
|
||||||
|
|
||||||
# TODO assert here
|
class BankTestCase(unittest.TestCase):
|
||||||
is_error(client)
|
"""Test withdrawal (after registering a new user)"""
|
||||||
|
def setUp(self):
|
||||||
|
ret = client_setup()
|
||||||
|
self.client = ret['client']
|
||||||
|
self.ext_id = ret['ext_id']
|
||||||
|
|
||||||
# visit bank and trigger withdrawal
|
def tearDown(self):
|
||||||
client.get('https://bank.test.taler.net')
|
self.client.close()
|
||||||
client.get('https://bank.test.taler.net/accounts/register')
|
|
||||||
|
|
||||||
|
def test_withdrawal(self):
|
||||||
|
bank_url = 'http://127.0.0.1:9898'
|
||||||
|
self.client.get(bank_url + '/accounts/register')
|
||||||
|
|
||||||
register = """\
|
register = """\
|
||||||
var form = document.getElementsByTagName('form');
|
var form = document.getElementsByTagName('form')[0];
|
||||||
form.username.value = 'test';
|
form.username.value = '%s';
|
||||||
form.password.value = 'test';
|
form.password.value = 'test';
|
||||||
form.submit();
|
form.submit();
|
||||||
"""
|
""" % str(int(time.time())) # need fresh username
|
||||||
|
|
||||||
# TODO assert here
|
self.client.execute_script(register)
|
||||||
client.execute_script(register)
|
self.assertNotEqual(True, is_error(self.client))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user