diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-04-26 10:29:05 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-04-26 10:29:05 +0200 |
commit | 67b37dd31ebb2ffa53c5ea169fb7c711e56785e3 (patch) | |
tree | e3503176518b8b645736b5f37a983029152dbccc | |
parent | 3777d850ebfb730fc309813c3effff08bda69910 (diff) |
putting tests inside "unittest" classes
-rw-r--r-- | selenium/wallet-test.py | 112 |
1 files changed, 71 insertions, 41 deletions
diff --git a/selenium/wallet-test.py b/selenium/wallet-test.py index 718fb5ccf..6027d8e1d 100644 --- a/selenium/wallet-test.py +++ b/selenium/wallet-test.py @@ -1,31 +1,36 @@ from selenium import webdriver import time +import unittest + + +def client_setup(): + """Return a Chrome browser the extension's id""" + co = webdriver.ChromeOptions() + co.add_argument("load-extension=/home/marcello/wallet-webex") + cap = webdriver.DesiredCapabilities.CHROME.copy() + cap['loggingPrefs'] = {'driver': 'INFO', 'browser': 'INFO'} + client = webdriver.Chrome(chrome_options=co, desired_capabilities=cap) + client.get('https://taler.net') + listener = """\ + document.addEventListener('taler-id', function(evt){ + window['extId'] = evt.detail.id; + }); + var evt = new CustomEvent('taler-query-id'); + document.dispatchEvent(evt); + """ + client.execute_script(listener) + poll = """\ + if(window.extId) + return window.extId; + else return false; + """ + # Todo: put some delay in polling + ext_id = client.execute_script(poll) + return {'client': client, 'ext_id': ext_id} + -co = webdriver.ChromeOptions() -co.add_argument("load-extension=/home/marcello/Taler/wallet-webex") -cap = webdriver.DesiredCapabilities.CHROME.copy() -cap['loggingPrefs'] = {'driver': 'INFO', 'browser': 'INFO'} -client = webdriver.Chrome(chrome_options=co, desired_capabilities=cap) -client.get('https://taler.net') -listener = """\ - document.addEventListener('taler-id', function(evt){ - window['extId'] = evt.detail.id; - }); - var evt = new CustomEvent('taler-query-id'); - document.dispatchEvent(evt); - """ -client.execute_script(listener) -poll = """\ - if(window.extId) - return window.extId; - else return false; - """ -# TODO intelligent poller needed -time.sleep(1) -ext_id = client.execute_script(poll) - -# if client has error from its activity, ptints it and returns True def is_error(client): + """In case of errors in the browser, print them and return True""" for log_type in ['browser']: for log in client.get_log(log_type): if log['level'] is 'error': @@ -33,24 +38,49 @@ def is_error(client): return True -labels = ['balance'] -# labels = ['balance', 'history', 'debug'] -for l in labels: - client.get('chrome-extension://' + ext_id + '/popup/popup.html#/' + l) -# TODO assert here -is_error(client) +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'] + for l in labels: + self.client.get('chrome-extension://' + self.ext_id + '/popup/popup.html#/' + l) + self.assertNotEqual(True, is_error(self.client)) + +class BankTestCase(unittest.TestCase): + """Test withdrawal (after registering a new user)""" + def setUp(self): + ret = client_setup() + self.client = ret['client'] + self.ext_id = ret['ext_id'] + + def tearDown(self): + self.client.close() + + + def test_withdrawal(self): + bank_url = 'http://127.0.0.1:9898' + self.client.get(bank_url + '/accounts/register') -# visit bank and trigger withdrawal -client.get('https://bank.test.taler.net') -client.get('https://bank.test.taler.net/accounts/register') + register = """\ + var form = document.getElementsByTagName('form')[0]; + form.username.value = '%s'; + form.password.value = 'test'; + form.submit(); + """ % str(int(time.time())) # need fresh username -register = """\ - var form = document.getElementsByTagName('form'); - form.username.value = 'test'; - form.password.value = 'test'; - form.submit(); - """ + self.client.execute_script(register) + self.assertNotEqual(True, is_error(self.client)) -# TODO assert here -client.execute_script(register) +if __name__ == '__main__': + unittest.main() |