Add test alert and new functions in alert_functions.py

(cherry picked from commit 00519707ba42a44ed768ca724b09fa627fde76e3)
This commit is contained in:
cesar991 2016-09-28 12:53:30 +02:00
parent ce90d552bc
commit b4079041a4
2 changed files with 99 additions and 0 deletions

43
tests/console/Alerts.py Normal file
View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import login, click_menu_element, refresh_N_times_until_find_element, detect_and_pass_all_wizards, is_element_present, logout
from include.alert_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 StaleElementReferenceException, NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest2, time, re
class Alerts (PandoraWebDriverTestCase):
test_name = u'Alerts tests'
tickets_associated = []
def test_create_new_email_action(self):
u"""
Create a new alert action using eMail command and check that create ok
"""
action_name = gen_random_string(6)
driver = self.driver
self.login()
detect_and_pass_all_wizards(driver)
create_new_action_to_alert(driver,action_name,"Applications","eMail",field1="prueba@prueba.com",field2="Test",field3="This is a test")
element = driver.find_element_by_xpath('//td[contains(.,"Successfully created")]')
self.assertIsInstance(element,WebElement)
click_menu_element(driver,"Actions")
element = driver.find_element_by_xpath('//a[contains(.,"'+action_name+'")]')
self.assertIsInstance(element,WebElement)
if __name__ == "__main__":
unittest2.main()

View File

@ -31,6 +31,62 @@ def force_alert_of_module(driver,agent_name,module_name,template_name):
time.sleep(10)
def create_new_action_to_alert(driver,action_name,action_group,command,threshold=None,field1=None,field2=None,field3=None):
click_menu_element(driver,"Actions")
driver.find_element_by_id("submit-create").click()
driver.find_element_by_id("text-name").clear()
driver.find_element_by_id("text-name").send_keys(action_name)
driver.find_element_by_xpath('//option[contains(.,"'+action_group+'")]').click()
driver.find_element_by_xpath('//option[contains(.,"'+command+'")]').click()
if threshold != None:
driver.find_element_by_id("text-action_threshold").clear()
driver.find_element_by_id("text-action_threshold").send_keys(threshold)
if command == "eMail" and field1 != None and field2 != None and field3 != None:
driver.find_element_by_id("textarea_field1_value").clear()
driver.find_element_by_id("textarea_field1_value").send_keys(field1)
driver.find_element_by_id("textarea_field2_value").clear()
driver.find_element_by_id("textarea_field2_value").send_keys(field2)
driver.find_element_by_id("textarea_field3_value").clear()
driver.find_element_by_id("textarea_field3_value").send_keys(field3)
driver.find_element_by_id("submit-create").click()
def create_new_command_to_alert(driver,command_name,command,list_field_description,list_field_values,description=None):
click_menu_element(driver,"Commands")
driver.find_element_by_id("submit-create").click()
driver.find_element_by_id("text-name").clear()
Select(driver.find_element_by_id("text-name")).send_keys(command_name)
driver.find_element_by_id("textarea_command").clear()
Select(driver.find_element_by_id("textarea_command")).send_keys(command)
if description != None:
driver.find_element_by_id("textarea_description").clear()
Select(driver.find_element_by_id("textarea_description")).send_keys(description)
i=1
for field_description in list_field_description:
driver.find_element_by_id("text-field"+i+"_description").clear()
Select(driver.find_element_by_id("text-field"+i+"_description")).send_keys(field_description)
i=1
for field_value in list_field_values:
driver.find_element_by_id("text-field"+i+"_description").clear()
Select(driver.find_element_by_id("text-field"+i+"_description")).send_keys(field_value)
driver.find_element_by_id("submit-create").click()