From a950371d2a8e9045d50b5b6a25861f5694c0ac56 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Wed, 28 Mar 2018 10:47:31 +0530 Subject: [PATCH] Fix tests for firstboot, users and groups - Make browser actions independent of language - Increase timeout for submit actions since actions like enable take too long on slower machines Signed-off-by: Joseph Nuthalapati Reviewed-by: James Valleroy --- .../features/configuration.feature | 2 +- .../step_definitions/interface.py | 7 +- functional_tests/support/interface.py | 73 +++++++++++-------- functional_tests/support/service.py | 2 +- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/functional_tests/features/configuration.feature b/functional_tests/features/configuration.feature index bd4794ba0..4dc34c994 100644 --- a/functional_tests/features/configuration.feature +++ b/functional_tests/features/configuration.feature @@ -15,7 +15,7 @@ # along with this program. If not, see . # -@system @essential +@system @essential @configuration Feature: Configuration Configure the system. diff --git a/functional_tests/step_definitions/interface.py b/functional_tests/step_definitions/interface.py index 69a2c3c46..d3b42f160 100644 --- a/functional_tests/step_definitions/interface.py +++ b/functional_tests/step_definitions/interface.py @@ -41,12 +41,7 @@ def prompted_for_login(browser): @given(parsers.parse("the user {name:w} doesn't exist")) def new_user_does_not_exist(browser, name): - interface.nav_to_module(browser, 'users') - delete_link = browser.find_link_by_href( - '/plinth/sys/users/' + name + '/delete/') - if delete_link: - delete_link.first.click() - browser.find_by_value('Delete ' + name).click() + interface.delete_user(browser, name) @given(parsers.parse('the user {name:w} exists')) diff --git a/functional_tests/support/interface.py b/functional_tests/support/interface.py index 0b47c75b1..300318adf 100644 --- a/functional_tests/support/interface.py +++ b/functional_tests/support/interface.py @@ -30,21 +30,21 @@ default_url = config['DEFAULT']['url'] def login(browser, url, username, password): browser.visit(url) - if browser.find_by_id('logout-nojs'): - return # already logged in + + # XXX browser.visit goes to the web page with no cookies, + # hence there should be some kind of session storage for this to work login_button = browser.find_link_by_href('/plinth/accounts/login/') if login_button: login_button.first.click() - login_submit = browser.find_by_value('Login') if login_button: browser.fill('username', username) browser.fill('password', password) - login_submit.click() + submit(browser) else: browser.visit(default_url + '/plinth/firstboot/welcome') - browser.find_by_value('Start Setup').click() - create_admin_account(browser, username, 'testingtesting') + submit(browser) # click the "Start Setup" button + create_admin_account(browser, username, password) login(browser, url, username, password) @@ -55,46 +55,50 @@ def is_login_prompt(browser): def nav_to_module(browser, module): - browser.find_link_by_href('/plinth/').first.click() - if module in sys_modules: - browser.find_link_by_href('/plinth/sys/').first.click() - browser.find_link_by_href('/plinth/sys/' + module + '/').first.click() - else: - browser.find_link_by_href('/plinth/apps/').first.click() - browser.find_link_by_href('/plinth/apps/' + module + '/').first.click() - - -def submit(browser, form_class=None): with wait_for_page_update(browser): - if form_class: - browser.find_by_css( - '.{} input[type=submit]'.format(form_class)).click() - else: - browser.find_by_css('input[type=submit]').click() + browser.find_link_by_href('/plinth/').first.click() + if module in sys_modules: + with wait_for_page_update(browser): + browser.find_link_by_href('/plinth/sys/').first.click() + with wait_for_page_update(browser): + browser.find_link_by_href( + '/plinth/sys/' + module + '/').first.click() + else: + with wait_for_page_update(browser): + browser.find_link_by_href('/plinth/apps/').first.click() + with wait_for_page_update(browser): + browser.find_link_by_href( + '/plinth/apps/' + module + '/').first.click() def create_user(browser, name, password): nav_to_module(browser, 'users') - browser.find_link_by_href('/plinth/sys/users/create/').first.click() + with wait_for_page_update(browser): + browser.find_link_by_href('/plinth/sys/users/create/').first.click() browser.find_by_id('id_username').fill(name) browser.find_by_id('id_password1').fill(password) browser.find_by_id('id_password2').fill(password) - browser.find_by_value('Create User').click() + submit(browser) def rename_user(browser, old_name, new_name): nav_to_module(browser, 'users') - browser.find_link_by_href( - '/plinth/sys/users/' + old_name + '/edit/').first.click() + with wait_for_page_update(browser): + browser.find_link_by_href( + '/plinth/sys/users/' + old_name + '/edit/').first.click() browser.find_by_id('id_username').fill(new_name) - browser.find_by_value('Save Changes').click() + submit(browser) def delete_user(browser, name): nav_to_module(browser, 'users') - browser.find_link_by_href( - '/plinth/sys/users/' + name + '/delete/').first.click() - browser.find_by_value('Delete ' + name).click() + with wait_for_page_update(browser): + delete_link = browser.find_link_by_href( + '/plinth/sys/users/' + name + '/delete/') + if delete_link: + delete_link.first.click() + if delete_link: + submit(browser) def is_user(browser, name): @@ -106,4 +110,13 @@ def create_admin_account(browser, username, password): browser.find_by_id('id_username').fill(username) browser.find_by_id('id_password1').fill(password) browser.find_by_id('id_password2').fill(password) - browser.find_by_value('Create Account').click() + submit(browser) + + +def submit(browser, form_class=None): + with wait_for_page_update(browser): + if form_class: + browser.find_by_css( + '.{} input[type=submit]'.format(form_class)).click() + else: + browser.find_by_css('input[type=submit]').click() diff --git a/functional_tests/support/service.py b/functional_tests/support/service.py index d5839f047..13396711b 100644 --- a/functional_tests/support/service.py +++ b/functional_tests/support/service.py @@ -60,7 +60,7 @@ def eventually(function, args=[], timeout=30): @contextmanager -def wait_for_page_update(browser, timeout=30): +def wait_for_page_update(browser, timeout=300): current_page = browser.find_by_tag('html').first yield WebDriverWait(browser, timeout).until(is_stale(current_page))