From f43e99defd7b484d161c904772e7241c95379d0a Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 11 Mar 2019 13:07:08 -0400 Subject: state restart, more options, better click item resiliency #791 --- tests/testcases/common.py | 48 +++++++++++++++++++++++++++++++++++++---------- tests/testcases/state.py | 21 +++++++++++++++++++++ tests/testcases/test.py | 36 ++++++++++++++++++++++++++++++++--- tests/testcases/wizard.py | 9 ++++++--- 4 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 tests/testcases/state.py (limited to 'tests') diff --git a/tests/testcases/common.py b/tests/testcases/common.py index 7895c205..e5b48513 100644 --- a/tests/testcases/common.py +++ b/tests/testcases/common.py @@ -49,6 +49,21 @@ def take_screenshot(id,fname): log ('Screenshot stored in '+fname) image_counter = image_counter + 1 +# generic element clicker, will try retry times +# because sometimes, async loaders interfere +def _click_with_retry(element,max_retry=3): + retry_count = 1 + while retry_count <= max_retry: + try: + element.click() + except: + log ('click error, try #{}...'.format(retry_count)) + retry_count = retry_count + 1 + sleep(2) + else: + retry_count = max_retry + 1 + pass + # makes sure we can see the element to avoid out of view issues def _goto_element(e): @@ -59,40 +74,52 @@ def _goto_element(e): def _wait_for_id(id=id,dur=15, save_screenshot=False, save_screenshot_file=None): log ('Waiting for '+id+'...') WebDriverWait(driver, dur).until(EC.presence_of_element_located((By.ID, id))) + # angular refresh? + sleep(0.2) if save_screenshot: take_screenshot(id,save_screenshot_file) + def get_element_attributes(id=id, save_screenshot=False, save_screenshot_file=None): _wait_for_id(id=id, save_screenshot=save_screenshot, save_screenshot_file = save_screenshot_file) element = driver.find_element_by_id(id) return element # handle ion-alerts. Only single button for now. May extend later if I need -def click_popup(save_screenshot=False, save_screenshot_file=None): +def click_popup(txt='ok', save_screenshot=False, save_screenshot_file=None): log ('Waiting for popup...') WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'popup-buttons'))) if save_screenshot: - take_screenshot(None,'wizard-save-results.png') - element = driver.find_element_by_class_name('popup-buttons') - element = element.find_element_by_tag_name('button') - element.click() - - + take_screenshot(None,'popup-results.png') + buttons = driver.find_element_by_class_name('popup-buttons') + buttons = buttons.find_elements_by_tag_name('button') + for element in buttons: + if element.text.lower() == txt: + log ('click_popup: clicking '+element.text) + _click_with_retry(element) + + else: + log ('click_popup: skipping '+element.text) + + # handle ion-toggle def tap_toggle(id, save_screenshot=False, save_screenshot_file=None): _wait_for_id(id=id, save_screenshot=save_screenshot, save_screenshot_file = save_screenshot_file) element = driver.find_element_by_id(id) _goto_element(element) element = element.find_element_by_tag_name('label') - element.click() + _click_with_retry(element) + # generates click event for any web element id -def click_item(id=id, save_screenshot=False, save_screenshot_file=None): +def click_item(id=id, save_screenshot=False, save_screenshot_file=None, retry=3): _wait_for_id(id=id, save_screenshot=save_screenshot, save_screenshot_file = save_screenshot_file) element = driver.find_element_by_id(id) _goto_element(element) - element.click() + _click_with_retry(element,retry) + + #sleep(wait) # generated double click event for any web element id @@ -111,4 +138,5 @@ def input_item(id=id,txt="you forgot to specify text", save_screenshot=False, sa element.clear() element.send_keys(txt) driver.hide_keyboard() + sleep(1) #sleep(wait) diff --git a/tests/testcases/state.py b/tests/testcases/state.py new file mode 100644 index 00000000..108cf29f --- /dev/null +++ b/tests/testcases/state.py @@ -0,0 +1,21 @@ +''' +Validates State view +''' + +import common as c +from time import sleep +import app + +def run_tests(self): + app.tap_menu_js() + c.log ('Validating state with restart') + c.click_item('testaut_menu_state') + c.click_item('testaut_state_restart_button') + c.click_popup(save_screenshot=True, save_screenshot_file='state-restart-prompt.png') + # Wait for state change to show + sleep(2) + c.take_screenshot(None,'state-after-restart.png') + + + + diff --git a/tests/testcases/test.py b/tests/testcases/test.py index e2d095d9..2dd4b6af 100644 --- a/tests/testcases/test.py +++ b/tests/testcases/test.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + ''' Main zmNinja test driver Invokes other test cases @@ -8,13 +10,14 @@ from time import sleep,localtime,strftime from appium import webdriver import os import glob - +import errno import common as c import wizard import app import montage -import errno +import state + class ZmninjaAndroidTests(unittest.TestCase): 'Class to run tests against zmNinja' @@ -54,6 +57,7 @@ class ZmninjaAndroidTests(unittest.TestCase): configs = []; # Add as many as you need + configs.append ({ 'portal': 'https://demo.zoneminder.com/zm', 'user': 'zmuser', @@ -63,15 +67,39 @@ class ZmninjaAndroidTests(unittest.TestCase): 'use_basic_auth': False, 'basic_user': None, 'basic_password': None, - 'screenshot_dir': './screenshots' + 'screenshot_dir': './screenshots', + 'restart': False, + 'prompt': False }) + configs.append ({ + 'portal': 'https://10.6.1.16/zm', + 'user': 'admin', + 'password': 'admin', + 'use_auth': True, + 'use_zm_auth': True, + 'use_basic_auth': False, + 'basic_user': None, + 'basic_password': None, + 'screenshot_dir': './screenshots', + 'restart': True, + 'prompt': True + }) self.wait_for_app_start() isFirstRun = True for config in configs: + + c.log ('\n\n***** Test Run for: {} *****\n\n'.format(config['portal'])) + if config['prompt']: + proceed = input ("Should I run this profile? [y/N]") + if proceed.lower() != 'y': + c.log ('Skipping profile') + continue + + c.testConfig = config run_dir = strftime('%b-%d-%I_%M_%S%p', localtime()) c.testConfig['screenshot_dir'] = './screenshots/'+run_dir @@ -91,6 +119,8 @@ class ZmninjaAndroidTests(unittest.TestCase): wizard.run_tests(self, isFirstRun) isFirstRun = False montage.run_tests(self) + if c.testConfig['restart']: + state.run_tests(self) diff --git a/tests/testcases/wizard.py b/tests/testcases/wizard.py index 0bcbe4a0..9f3e2f3d 100644 --- a/tests/testcases/wizard.py +++ b/tests/testcases/wizard.py @@ -51,14 +51,17 @@ def run_tests(self, isFirstRun = False): self.assertEqual(api_color,success_color) # Wait for bit for cgi-bin. Don't really care, but hey if we catch it, cool - sleep(3) + sleep(5) c.take_screenshot(None,'wizard-detection-results.png') + c.click_item('testaut_wizard_goto_login') c.click_item('testaut_settings_save') # discard the popup and get to sane state - c.click_popup(save_screenshot=True, save_screenshot_file='./screenshots/wizard-save-report.png') - sleep(3) + c.click_popup(save_screenshot=True, save_screenshot_file='wizard-save-report.png') + # we need this because at the end of wizard, it shows the menu, + # so close it app.tap_menu_js() + -- cgit v1.2.3