From 9de246554dad018b917d340cf6b1bfd2aa72253d Mon Sep 17 00:00:00 2001 From: axl89 Date: Thu, 26 May 2016 22:31:00 +0200 Subject: [PATCH] Added several functions and refactorized all console CI tests --- tests/console/PAN1.py | 5 ++-- tests/console/PAN2.py | 11 ++++----- tests/console/include/common_functions_60.py | 24 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/tests/console/PAN1.py b/tests/console/PAN1.py index a4ea29a4c1..e8a7424926 100644 --- a/tests/console/PAN1.py +++ b/tests/console/PAN1.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from include.common_classes_60 import PandoraWebDriverTestCase -from include.common_functions_60 import login +from include.common_functions_60 import login, click_menu_element from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys @@ -17,8 +17,7 @@ class PAN1(PandoraWebDriverTestCase): def test_pan1(self): driver = self.driver login(driver,"admin","pandora",self.base_url) - 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) + click_menu_element(driver,"General Setup") self.assertEqual("IP list with API access", driver.find_element_by_id("table2-15-0").text) if __name__ == "__main__": diff --git a/tests/console/PAN2.py b/tests/console/PAN2.py index 4408c837a0..14b4fe08b0 100644 --- a/tests/console/PAN2.py +++ b/tests/console/PAN2.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from include.common_classes_60 import PandoraWebDriverTestCase -from include.common_functions_60 import login +from include.common_functions_60 import login, click_menu_element from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys @@ -17,16 +17,14 @@ class PAN2(PandoraWebDriverTestCase): def test_pan2(self): driver = self.driver login(driver,"admin","pandora",self.base_url) - element = driver.find_element_by_xpath("//ul[@id='subViews']/li[4]/a/div") - driver.execute_script("arguments[0].click();", element) + click_menu_element(driver,"Agent detail") driver.find_element_by_id("submit-crt").click() driver.find_element_by_id("text-agente").click() driver.find_element_by_id("text-agente").clear() driver.find_element_by_id("text-agente").send_keys("prueba masivas 1") driver.find_element_by_id("submit-crtbutton").click() driver.find_element_by_css_selector("b").click() - element = driver.find_element_by_xpath("//ul[@id='subViews']/li[4]/a/div") - driver.execute_script("arguments[0].click();", element) + click_menu_element(driver,"Agent detail") driver.find_element_by_id("submit-crt").click() driver.find_element_by_id("text-agente").click() driver.find_element_by_id("text-agente").clear() @@ -34,8 +32,7 @@ class PAN2(PandoraWebDriverTestCase): driver.find_element_by_id("submit-crtbutton").click() driver.find_element_by_css_selector("b").click() driver.find_element_by_css_selector("b").click() - element = driver.find_element_by_css_selector('#subBulk_operations > li.sub_subMenu > a > div.submenu_text.submenu2_text_middle') - driver.execute_script("arguments[0].click();", element) + click_menu_element(driver,"Agents operations") driver.find_element_by_id("option").click() Select(driver.find_element_by_id("option")).select_by_visible_text("Bulk agent delete") Select(driver.find_element_by_id("id_agents")).select_by_visible_text("prueba masivas 1") diff --git a/tests/console/include/common_functions_60.py b/tests/console/include/common_functions_60.py index 9c924860af..a76524ff78 100644 --- a/tests/console/include/common_functions_60.py +++ b/tests/console/include/common_functions_60.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- from selenium import selenium +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC def login(driver,user="admin",passwd="pandora",pandora_url="http://127.0.0.1/"): driver.get(pandora_url+"/pandora_console/index.php") @@ -8,3 +11,24 @@ def login(driver,user="admin",passwd="pandora",pandora_url="http://127.0.0.1/"): 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() + +def get_menu_element(driver,menu_item_text): + return driver.find_element_by_xpath('//div[@class="menu"]//a[contains(.,"'+menu_item_text+'")]') + +def click_menu_element(driver,menu_item_text): + return driver.execute_script("arguments[0].click();", get_menu_element(driver,menu_item_text)) + +def refresh_N_times_until_find_element(driver,n,element_text,how=By.ID,refresh_time=10): + from selenium.common.exceptions import TimeoutException + + i = 1 + while (1<=n): + try: + element = WebDriverWait(driver, refresh_time).until(EC.presence_of_element_located((how, element_text))) + return element + except: + driver.get(driver.current_url) + i = i+1 + + raise TimeoutException("Element %s not found" % (element_text)) +