Updated tests

This commit is contained in:
cesar991 2016-08-24 11:52:28 +02:00
parent fcb86b3f5c
commit d241218ae8
10 changed files with 318 additions and 68 deletions

View File

@ -26,6 +26,7 @@ RUN yum install -y \
xorg-x11-server-Xvfb; yum clean all;
RUN pip install pyvirtualdisplay
RUN pip install selenium
RUN pip install testtools
# Pandora FMS Console dependencies
RUN yum install -y \
@ -76,6 +77,7 @@ RUN yum install -y \
perl-XML-Simple \
perl-XML-SAX \
perl-NetAddr-IP \
perl-Scope-Guard \
net-snmp \
net-tools \
perl-IO-Socket-INET6 \

View File

@ -8,17 +8,26 @@ 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 PAN2(PandoraWebDriverTestCase):
test_name = u'PAN_2'
class Bulk_operations(PandoraWebDriverTestCase):
test_name = u'Bulk_operation'
test_description = u'Creation two agents and delete this agents using bulk operation'
tickets_associated = [3831]
tickets_associated = []
def test_pan2(self):
def test_A_delete_agent_bulk_operations(self):
u"""
Creation two agents and delete this agents using bulk operation'
Ticket Associated = 3831
"""
driver = self.driver
self.login()
detect_and_pass_all_wizards
create_agent(driver,"prueba masivas 1")
driver.find_element_by_css_selector("b").click()
@ -33,11 +42,9 @@ class PAN2(PandoraWebDriverTestCase):
Select(driver.find_element_by_id("id_agents")).select_by_visible_text("prueba masivas 1")
Select(driver.find_element_by_id("id_agents")).select_by_visible_text("prueba masivas 2")
driver.find_element_by_id("submit-go").click()
try:
self.assertRegexpMatches(self.close_alert_and_get_its_text(), r"^Are you sure[\s\S]$")
self.assertEqual(self.driver.find_element_by_xpath('//div[@id="main"]//td[contains(.,"Successfully deleted (2)")]').text,"Successfully deleted (2)")
except AssertionError as e:
self.verificationErrors.append(str(e))
self.assertRegexpMatches(self.close_alert_and_get_its_text(), r"^Are you sure[\s\S]$")
self.assertEqual(self.driver.find_element_by_xpath('//div[@id="main"]//td[contains(.,"Successfully deleted (2)")]').text,"Successfully deleted (2)")
if __name__ == "__main__":
unittest.main()

View File

@ -6,6 +6,7 @@ from include.reports_functions import create_report, delete_report
from include.user_functions import create_user
from include.agent_functions import create_agent
from include.module_functions import create_module
from include.event_functions import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
@ -53,14 +54,8 @@ class Miscellaneous (PandoraWebDriverTestCase):
time.sleep(10)
#Search events of our agent
click_menu_element(driver,"View events")
driver.find_element_by_xpath('//a[contains(.,"Event control filter")]').click()
driver.find_element_by_xpath('//a[contains(.,"Advanced options")]').click()
driver.find_element_by_id("text-text_agent").clear()
driver.find_element_by_id("text-text_agent").send_keys(u"次のライセンスに基づいていま")
driver.find_element_by_id("text-module_search").clear()
driver.find_element_by_id("text-module_search").send_keys(u"管理者ガイド")
driver.find_element_by_id("submit-update").click()
search_events(driver,agent_name=u"次のライセンスに基づいていま",module_name=u"管理者ガイド")
#Check that there are japanese characters present on the event
element = driver.find_element_by_xpath(u'//a[contains(.,"Alert fired (Critical condition) assigned to (管理者ガイド)")]')

View File

@ -0,0 +1,165 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import login, click_menu_element, detect_and_pass_all_wizards, logout, gen_random_string
from include.planned_downtime_functions import *
from include.alert_functions import *
from include.module_functions import *
from include.agent_functions import *
from include.event_functions import *
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
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re, datetime
class PAN13(PandoraWebDriverTestCase):
test_name = u'Planned_downtime'
test_description = u'Planed downtime test'
tickets_associated = []
def avoid_test_A_create_planned_downtime_Quiet(self):
u"""
Create and search planned downtime quiet
"""
driver = self.driver
self.login()
detect_and_pass_all_wizards(driver)
planned_name = gen_random_string(6)
create_planned_downtime(driver,planned_name,"Applications","Quiet","Once",description=planned_name)
time.sleep(10)
search_planned_downtime(driver,planned_name)
element = driver.find_element_by_xpath('//img[@data-title="Running"]')
self.assertIsInstance(element,WebElement)
def avoid_test_B_create_planned_downtime_disabled_agents(self):
u"""
Create and search planned downtime disabled agents
"""
driver = self.driver
planned_name = gen_random_string(6)
create_planned_downtime(driver,planned_name,"Applications","Disabled Agents","Once",description=planned_name)
time.sleep(10)
search_planned_downtime(driver,planned_name)
element = driver.find_element_by_xpath('//img[@data-title="Running"]')
self.assertIsInstance(element,WebElement)
def avoid_test_C_create_planned_downtime_disabled_only_alerts(self):
u"""
Create and search planned downtime disabled only alerts
"""
driver = self.driver
planned_name = gen_random_string(6)
create_planned_downtime(driver,planned_name,"Applications","Disabled only Alerts","Once",description=planned_name)
time.sleep(10)
search_planned_downtime(driver,planned_name)
element = driver.find_element_by_xpath('//img[@data-title="Running"]')
self.assertIsInstance(element,WebElement)
def avoid_test_D_delete_planned_downtime(self):
driver=self.driver
planned_name = gen_random_string(6)
create_planned_downtime(driver,planned_name,"Applications","Quiet","Once",description=planned_name)
delete_planned_downtime(driver,planned_name)
def avoid_test_E_quiet_functionality(self):
driver=self.driver
planned_name = gen_random_string(6)
agent_name_A = gen_random_string(6)
agent_name_B = gen_random_string(6)
module_name_A_A = gen_random_string(6)
module_name_A_B = gen_random_string(6)
module_name_B_A = gen_random_string(6)
module_name_B_B = gen_random_string(6)
create_agent(driver,agent_name_A,ip="127.0.0.1",group="Applications")
create_agent(driver,agent_name_B,ip="127.0.0.1",group="Applications")
create_module('network_server',driver,agent_name=agent_name_A,module_name=module_name_A_A,component_group='Network Management',network_component='Host Alive')
create_module('network_server',driver,agent_name=agent_name_A,module_name=module_name_A_B,component_group='Network Management',network_component='Host Latency')
create_module('network_server',driver,agent_name=agent_name_B,module_name=module_name_B_A,component_group='Network Management',network_component='Host Alive')
create_module('network_server',driver,agent_name=agent_name_B,module_name=module_name_B_B,component_group='Network Management',network_component='Host Alive')
assign_alert_template_to_module(driver,agent_name_A,module_name_A_A,'Critical condition')
assign_alert_template_to_module(driver,agent_name_A,module_name_A_B,'Critical condition')
assign_alert_template_to_module(driver,agent_name_B,module_name_B_A,'Critical condition')
assign_alert_template_to_module(driver,agent_name_B,module_name_B_B,'Critical condition')
#Little hack to allow the planned downtime to be edited
fifteen_seconds_later = datetime.datetime.now() + datetime.timedelta(seconds=15)
fifteen_seconds_later_to_pandora = str(fifteen_seconds_later.hour)+":"+str(fifteen_seconds_later.minute)+":"+str(fifteen_seconds_later.second)
create_planned_downtime(driver,planned_name,"Applications","Quiet","Once",hour_from=fifteen_seconds_later_to_pandora,description=planned_name,agent_module_list=[(agent_name_A,[module_name_A_A]),(agent_name_B,[module_name_B_A])])
#We wait 10 seconds to the planned downtime to start. Since we do not specify a date, default dates are from now to one hour in the future.
time.sleep(40)
#Is the planned downtime running?
search_planned_downtime(driver,planned_name)
element = driver.find_element_by_xpath('//img[@data-title="Running"]')
self.assertIsInstance(element,WebElement)
force_alert_of_module(driver,agent_name_A,module_name_A_A,'Critical condition')
force_alert_of_module(driver,agent_name_A,module_name_A_B,'Critical condition')
force_alert_of_module(driver,agent_name_B,module_name_B_A,'Critical condition')
force_alert_of_module(driver,agent_name_B,module_name_B_B,'Critical condition')
search_events(driver,agent_name=agent_name_A,module_name=module_name_A_A)
event_who_should_not_be_present = driver.find_elements_by_xpath('//tbody/tr[td[3][contains(.,"Alert fired")] and td[4][contains(.,"'+agent_name_A+'")]]')
self.assertEqual(event_who_should_not_be_present,[])
search_events(driver,agent_name=agent_name_A,module_name=module_name_A_B)
event_who_should_be_present = driver.find_elements_by_xpath('//tbody/tr[td[3][contains(.,"Alert fired")] and td[4][contains(.,"'+agent_name_A+'")]]')
self.assertNotEqual(event_who_should_be_present,[])
search_events(driver,agent_name=agent_name_B,module_name=module_name_B_A)
event_who_should_not_be_present_b = driver.find_elements_by_xpath('//tbody/tr[td[3][contains(.,"Alert fired")] and td[4][contains(.,"'+agent_name_B+'")]]')
self.assertEqual(event_who_should_not_be_present_b,[])
search_events(driver,agent_name=agent_name_B,module_name=module_name_B_B)
event_who_should_be_present_b = driver.find_elements_by_xpath('//tbody/tr[td[3][contains(.,"Alert fired")] and td[4][contains(.,"'+agent_name_B+'")]]')
self.assertNotEqual(event_who_should_be_present_b,[])
if __name__ == "__main__":
unittest.main()

View File

@ -8,16 +8,21 @@ from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re
class PAN7(PandoraWebDriverTestCase):
class Users(PandoraWebDriverTestCase):
test_name = u'PAN_7'
test_description = u'Modify home screen, and check that change is correct. Return this change'
test_name = u'Users'
test_description = u'Users tests'
tickets_associated = []
def test_pan7(self):
def test_A_home_screen(self):
u"""
Modify home screen, and check that change is correct. Return this change
"""
driver = self.driver
self.login()
detect_and_pass_all_wizards(driver)
@ -27,17 +32,9 @@ class PAN7(PandoraWebDriverTestCase):
self.logout()
self.login()
element = driver.find_element_by_xpath('//a[contains(.,"Event control filter")]')
self.assertIsInstance(element,WebElement)
try:
element = driver.find_element_by_xpath('//a[contains(.,"Event control filter")]')
self.assertIsInstance(element,WebElement)
except AssertionError as e:
self.verificationErrors.append(str(e))
except NoSuchElementException as e:
self.verificationErrors.append(str(e))
#Return this change
activate_home_screen(driver,"Default")

View File

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
from selenium import selenium
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.support import expected_conditions as EC
from module_functions import search_module
from common_functions_60 import *
import random, time
import string
def assign_alert_template_to_module (driver,agent_name,module_name,template_name):
search_module(driver,agent_name,module_name)
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Alerts"]').click()
Select(driver.find_element_by_id("id_agent_module")).select_by_visible_text(module_name)
Select(driver.find_element_by_id("template")).select_by_visible_text(template_name)
driver.find_element_by_id("submit-add").click()
def force_alert_of_module(driver,agent_name,module_name,template_name):
click_menu_element(driver,"Agent detail")
driver.find_element_by_id("text-search").clear()
driver.find_element_by_id("text-search").send_keys(agent_name)
driver.find_element_by_id("submit-srcbutton").click()
driver.find_element_by_css_selector("b").click()
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Alerts"]').click()
driver.find_element_by_xpath('//tr[td[3][contains(.,"'+module_name+'")] and td[4][contains(.,"'+template_name+'")]]/td[2]/a').click()
time.sleep(10)

View File

@ -62,6 +62,8 @@ class PandoraWebDriverTestCase(TestCase):
self.verificationErrors = []
self.accept_next_alert = True
#self.is_development = self.is_development
#TODO Print test name
print "Starting test"
super(PandoraWebDriverTestCase, self).setUp()
def is_element_present(self, how, what):

View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from selenium import selenium
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.support import expected_conditions as EC
from common_functions_60 import *
import random, time
import string
def search_events(driver,agent_name=None,module_name=None):
click_menu_element(driver,"View events")
driver.find_element_by_xpath('//a[contains(.,"Event control filter")]').click()
driver.find_element_by_xpath('//a[contains(.,"Advanced options")]').click()
if agent_name != None:
driver.find_element_by_id("text-text_agent").clear()
driver.find_element_by_id("text-text_agent").send_keys(agent_name)
time.sleep(3)
driver.find_element_by_xpath('//a[@class="ui-corner-all"][contains(.,"'+agent_name+'")]').click() # In this line you click the drop-down box search
if module_name != None:
driver.find_element_by_id("text-module_search").clear()
driver.find_element_by_id("text-module_search").send_keys(module_name)
time.sleep(3)
driver.find_element_by_xpath('//a[@class="ui-corner-all"][contains(.,"'+module_name+'")]').click() # In this line you click the drop-down box search
driver.find_element_by_id("submit-update").click()

View File

@ -16,18 +16,18 @@ def create_module(module_type,*args,**kwargs):
elif module_type=='data_server':
create_data_server_module(*args,**kwargs)
def create_network_server_module(driver,agent_name=None,module_name=None,component_group=None,type=None,network_component=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,ip=None,tag_name=None,description=None):
def create_network_server_module(driver,agent_name=None,module_name=None,component_group=None,type_of_module=None,network_component=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,ip=None,tag_name=None,description=None):
# component_group -> Example: Remote ICMP network agent (latency)
# network_component -> Example: Host Alive
#The type variable is optional, but required if component_group and network_component variables are specified
#The type_of_module variable is optional, but required if component_group and network_component variables are specified
if agent_name != None:
search_agent(driver,agent_name)
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click()
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click()
Select(driver.find_element_by_id("moduletype")).select_by_visible_text("Create a new network server module")
driver.find_element_by_xpath('//*[@id="main"]/form/table/tbody/tr/td[5]/input').click()
@ -65,7 +65,7 @@ def create_network_server_module(driver,agent_name=None,module_name=None,compone
else:
driver.find_element_by_id("text-name").clear()
driver.find_element_by_id("text-name").send_keys(module_name)
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type)
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type_of_module)
if module_name != None:
time.sleep(3)
@ -85,11 +85,11 @@ def create_network_server_module(driver,agent_name=None,module_name=None,compone
driver.find_element_by_id("submit-crtbutton").click()
def create_data_server_module(driver,module_name,agent_name=None,type=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,tag_name=None,description=None):
def create_data_server_module(driver,module_name,agent_name=None,type_of_module=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,tag_name=None,description=None):
# type -> Example: Generic numeric
# type_of_module -> Example: Generic numeric
# The type variable is Generic numeric by default
# The type_of_module variable is Generic numeric by default
if agent_name != None:
search_agent(driver,agent_name)
@ -104,9 +104,9 @@ def create_data_server_module(driver,module_name,agent_name=None,type=None,min_w
driver.find_element_by_id("text-name").clear()
driver.find_element_by_id("text-name").send_keys(module_name)
if type != None:
if type_of_module != None:
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type)
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type_of_module)
if min_warning != None:
@ -166,4 +166,6 @@ def search_module (driver,agent_name,module_name):
driver.find_element_by_id("text-search_string").send_keys(module_name)
driver.find_element_by_id("submit-filter").click()

View File

@ -9,7 +9,7 @@ import random, time
import string
def create_planned_downtime(driver,name,group,type_planned,description=None,execution=None,date_from=None,date_to=None,hour_from=None,hour_to=None,periodicity_type=None,from_day=None,to_day=None,list_days=None,list_agent=None):
def create_planned_downtime(driver,name,group,type_planned,execution,description=None,date_from=None,date_to=None,hour_from=None,hour_to=None,periodicity_type=None,from_day=None,to_day=None,list_days=None,agent_module_list=None):
#type_planned is: Disabled Agents, Quiet or Disabled only Alerts
@ -22,7 +22,12 @@ def create_planned_downtime(driver,name,group,type_planned,description=None,exec
#Execution by default is Once, date_from and date_to is date it's today's date
#list_agent is a list of agent that aplicate this planned downtime
#agent_module_list is a list of tuples: lista = [('agent_name_1',['module_name_1','module_name_2']),('agent_name_2',[])]
#CAREFUL! [] means 'Any' module
#Self checks
if (date_from is None and date_to is not None) or (date_from is not None and date_to is None):
raise Exception("If one date is provided, the other should be provided too")
click_menu_element(driver,"Scheduled downtime")
driver.find_element_by_id("submit-create").click()
@ -39,17 +44,21 @@ def create_planned_downtime(driver,name,group,type_planned,description=None,exec
driver.find_element_by_xpath('//option[contains(.,"'+type_planned+'")]').click()
if execution == "Once":
driver.find_element_by_id("text-once_date_from").clear()
driver.find_element_by_id("text-once_date_from").send_keys(date_from)
driver.find_element_by_id("text-once_date_to").clear()
driver.find_element_by_id("text-once_date_to").send_keys(date_to)
driver.find_element_by_id("text-once_time_from").clear()
driver.find_element_by_id("text-once_time_from").send_keys(hour_from)
driver.find_element_by_id("text-once_time_to").clear()
driver.find_element_by_id("text-once_time_to").send_keys(hour_to)
if date_from is not None:
driver.find_element_by_id("text-once_date_from").clear()
driver.find_element_by_id("text-once_date_from").send_keys(date_from)
if date_to is not None:
driver.find_element_by_id("text-once_date_to").clear()
driver.find_element_by_id("text-once_date_to").send_keys(date_to)
if hour_from is not None:
driver.find_element_by_id("text-once_time_from").clear()
driver.find_element_by_id("text-once_time_from").send_keys(hour_from)
if hour_to is not None:
driver.find_element_by_id("text-once_time_to").clear()
driver.find_element_by_id("text-once_time_to").send_keys(hour_to)
if execution == "Periodically":
Select(driver.find_element_by_id("type_periodicity")).select_by_visible_text(periodicity_type)
@ -69,19 +78,25 @@ def create_planned_downtime(driver,name,group,type_planned,description=None,exec
driver.find_element_by_id("text-periodically_time_to").clear()
driver.find_element_by_id("text-periodically_time_to").send_keys(hour_to)
driver.find_element_by_id("submit-crtbutton").click()
if list_agent != None:
for agent in list_agent:
Select(driver.find_element_by_id("id_agents")).select_by_visible_text(agent)
alert = driver.switch_to_alert()
alert.accept()
driver.find_element_by_id("submit-add_item").click()
driver.find_element_by_id("submit-add_item").click()
alert = driver.switch_to_alert()
alert.accept()
if agent_module_list is not None:
for agent_name,module_name_list in agent_module_list:
Select(driver.find_element_by_id("id_agents")).select_by_visible_text(agent_name)
if type_planned == "Quiet":
#Quiet types allow to select modules
time.sleep(3)
if module_name_list is not []:
Select(driver.find_element_by_id("module")).deselect_by_visible_text('Any')
for module_name in module_name_list:
Select(driver.find_element_by_id("module")).select_by_visible_text(module_name)
driver.find_element_by_id("submit-add_item").click()
try:
alert = driver.switch_to_alert()
alert.accept()
except:
pass
def search_planned_downtime(driver,name,type_planned=None,date_from=None,date_to=None,show_past_downtimes=False):
@ -118,8 +133,8 @@ def stop_downtime(driver,name):
def delete_planned_downtime(driver,name):
search_planned_downtime(driver,name)
if (u"Running" in driver.page_source):
stop_downtime(driver,name)
if (u"Not running" not in driver.page_source):
stop_downtime(driver,name)
search_planned_downtime(driver,name,show_past_downtimes=True)
driver.find_element_by_xpath('//*[@id="delete_downtime"]/img').click()