Added console CI tests and test.sh to execute them
This commit is contained in:
parent
cefbc70ede
commit
5d544c836c
|
@ -0,0 +1 @@
|
|||
*.pyc
|
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from include.common_classes_60 import PandoraWebDriverTestCase
|
||||
from include.common_functions_60 import login
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.support.ui import Select
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
from selenium.common.exceptions import NoAlertPresentException
|
||||
import unittest, time, re
|
||||
|
||||
class PAN1(PandoraWebDriverTestCase):
|
||||
test_name = u'PAN_1'
|
||||
test_description = u'Tests that an Administrator user can access the Setup'
|
||||
tickets_associated = []
|
||||
|
||||
def test_pan1(self):
|
||||
driver = self.driver
|
||||
#login(driver,"admin","t3st1ng!",self.base_url)
|
||||
login(driver,"admin","pandora",self.base_url)
|
||||
#driver.find_element_by_css_selector("#subSetup > li.sub_subMenu > a > div.submenu_text.submenu2_text_middle").click()
|
||||
element = driver.find_element_by_css_selector("#subSetup > li.sub_subMenu > a > div.submenu_text.submenu2_text_middle")
|
||||
driver.execute_script("arguments[0].click();", element)
|
||||
self.assertEqual("IP list with API access", driver.find_element_by_id("table2-15-0").text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from unittest import TestResult, TestCase
|
||||
from common_functions_60 import *
|
||||
from datetime import datetime
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.support.ui import Select
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
from selenium.common.exceptions import NoAlertPresentException
|
||||
|
||||
|
||||
class ArticaTestResult(TestResult):
|
||||
success = []
|
||||
def addSuccess(self, test):
|
||||
self.success.append((test,u'Success'))
|
||||
TestResult.addSuccess(self, test)
|
||||
|
||||
|
||||
|
||||
class PandoraWebDriverTestCase(TestCase):
|
||||
test_name = u'' #Name of the test.
|
||||
test_description = u'' #Description of the test
|
||||
time_started = None
|
||||
time_elapsed = None #Total time of the test
|
||||
tickets_associated = []
|
||||
|
||||
def setUp(self):
|
||||
self.time_started = datetime.now()
|
||||
self.driver = webdriver.Firefox()
|
||||
self.driver.implicitly_wait(30)
|
||||
self.base_url = "http://localhost/"
|
||||
self.verificationErrors = []
|
||||
self.accept_next_alert = True
|
||||
super(PandoraWebDriverTestCase, self).setUp()
|
||||
|
||||
def is_element_present(self, how, what):
|
||||
try: self.driver.find_element(by=how, value=what)
|
||||
except NoSuchElementException, e: return False
|
||||
return True
|
||||
|
||||
def is_alert_present(self):
|
||||
try: self.driver.switch_to_alert()
|
||||
except NoAlertPresentException, e: return False
|
||||
return True
|
||||
|
||||
def close_alert_and_get_its_text(self):
|
||||
try:
|
||||
alert = self.driver.switch_to_alert()
|
||||
alert_text = alert.text
|
||||
if self.accept_next_alert:
|
||||
alert.accept()
|
||||
else:
|
||||
alert.dismiss()
|
||||
return alert_text
|
||||
finally: self.accept_next_alert = True
|
||||
|
||||
def tearDown(self):
|
||||
tack = datetime.now()
|
||||
diff = tack - self.time_started
|
||||
self.time_elapsed = diff.seconds
|
||||
self.driver.quit()
|
||||
self.assertEqual([], self.verificationErrors)
|
||||
super(PandoraWebDriverTestCase, self).tearDown()
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from selenium import selenium
|
||||
|
||||
def login(driver,user="admin",passwd="pandora",pandora_url="http://127.0.0.1/"):
|
||||
driver.get(pandora_url+"/pandora_console/index.php")
|
||||
driver.find_element_by_id("nick").clear()
|
||||
driver.find_element_by_id("nick").send_keys(user)
|
||||
driver.find_element_by_id("pass").clear()
|
||||
driver.find_element_by_id("pass").send_keys(passwd)
|
||||
driver.find_element_by_id("submit-login_button").click()
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
from unittest import *
|
||||
from console.include.common_functions_60 import *
|
||||
from console.include.common_classes_60 import *
|
||||
import subprocess, os, time
|
||||
|
||||
def get_test_file(test_list):
|
||||
#return [test[0].split(' ')[0].split('.')[0].split('<')[1] for test in test_list]
|
||||
return [test[0].test_name for test in test_list]
|
||||
|
||||
a = TestLoader()
|
||||
tests = a.discover(start_dir='console',pattern='PAN*.py')
|
||||
c = ArticaTestResult()
|
||||
tests.run(c)
|
||||
|
||||
print "Tests failed: %s" % (get_test_file(c.failures))
|
||||
print "Tests succeeded: %s" % (get_test_file(c.success))
|
||||
print "Tests skipped: %s" % (get_test_file(c.skipped))
|
||||
print "Tests with errors: %s" % (get_test_file(c.errors))
|
||||
|
||||
if (len(c.failures)+len(c.errors)+len(c.skipped)) != 0:
|
||||
exit(1)
|
||||
|
||||
else:
|
||||
exit(0)
|
|
@ -50,3 +50,6 @@ service pandora_agent_daemon start
|
|||
check "Starting the Pandora FMS Agent" $?
|
||||
|
||||
exit 0
|
||||
|
||||
#Run console CI tests
|
||||
cd /tmp/pandorafms/tests && chmod +x run_console_tests.py && ./run_console_tests.py
|
||||
|
|
Loading…
Reference in New Issue