summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author= <=>2019-03-11 13:07:08 -0400
committer= <=>2019-03-11 13:07:08 -0400
commitf43e99defd7b484d161c904772e7241c95379d0a (patch)
tree18d3f8a9dc85a8777453d64a7890b50159eb5262
parent5973dc639ce9d1dfda927562683d6a3d09760653 (diff)
state restart, more options, better click item resiliency #791
-rw-r--r--tests/testcases/common.py48
-rw-r--r--tests/testcases/state.py21
-rw-r--r--tests/testcases/test.py36
-rw-r--r--tests/testcases/wizard.py9
-rw-r--r--www/templates/menu.html2
-rw-r--r--www/templates/state.html2
6 files changed, 100 insertions, 18 deletions
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()
+
diff --git a/www/templates/menu.html b/www/templates/menu.html
index 0d91205f..b9cf92c3 100644
--- a/www/templates/menu.html
+++ b/www/templates/menu.html
@@ -72,7 +72,7 @@
</ion-item>
<!--<ion-item ng-click="navigateView('app.state')" menu-close>-->
- <ion-item id="menu-move-7" href="#/app/state" ng-click="go('/app/state')">
+ <ion-item id="testaut_menu_state" href="#/app/state" ng-click="go('/app/state')">
<span class=" item-icon-left">
<i class="icon ion-information-circled"></i>
</span> {{'kMenuSystemStatus'|translate}}
diff --git a/www/templates/state.html b/www/templates/state.html
index b534b693..bdad22d0 100644
--- a/www/templates/state.html
+++ b/www/templates/state.html
@@ -13,7 +13,7 @@
<div class="row">
<div class="col text-center">
<a class="button button-small button-outline button-dark " ng-click="selectCustomState();" href="">{{'kChangeState'|translate}}</a>
- <a class="button button-small button-outline button-dark " ng-click="controlZM('restart');" href="">{{'kRestart'
+ <a id="testaut_state_restart_button" class="button button-small button-outline button-dark " ng-click="controlZM('restart');" href="">{{'kRestart'
| translate}}</a>
<a class="button button-small button-outline button-dark" href="" ng-click="controlZM('stop');">{{'kStop'
| translate}}</a>