diff --git a/tests/console/Collections.py b/tests/console/Collections.py new file mode 100644 index 0000000000..59cef56ab0 --- /dev/null +++ b/tests/console/Collections.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +from include.common_classes_60 import PandoraWebDriverTestCase +from include.common_functions_60 import click_menu_element, detect_and_pass_all_wizards, gen_random_string +from include.module_functions import create_module +from include.agent_functions import create_agent_group +from include.policy_functions import * +from include.collection_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 + + +class Collections(PandoraWebDriverTestCase): + + test_name = u'Collections' + test_description = u'Collection tests' + tickets_associated = [] + + collection_name = gen_random_string(6) + new_collection_name = gen_random_string(6) + + def test_A_create_collection(self): + + driver = self.driver + self.login() + detect_and_pass_all_wizards(driver) + + create_collection(driver,self.collection_name,"PAN11",group="All",description="Collection with PAN11") + + search_collection(driver,self.collection_name,go_to_collection=False) + + element = driver.find_element_by_xpath('//a[contains(.,self.collection_name)]') + self.assertIsInstance(element,WebElement) + + def test_B_edit_collection(self): + + driver = self.driver + #login(driver,pandora_url="http://192.168.50.50:84/") + #detect_and_pass_all_wizards(driver) + + edit_collection(driver,self.collection_name,new_name=self.new_collection_name,group="Applications",description="Edit collectionPAN11") + + search_collection(driver,self.new_collection_name,go_to_collection=False) + + element = driver.find_element_by_xpath('//a[contains(.,self.new_collection_name)]') + self.assertIsInstance(element,WebElement) + + def test_C_create_text_collection(self): + + driver = self.driver + #login(driver,pandora_url="http://192.168.50.50:84/") + #detect_and_pass_all_wizards(driver) + + create_text_in_collection(driver,self.new_collection_name,"file_collectionPAN11",text_file="test file") + + element = driver.find_element_by_xpath('//a[contains(.,"file_collectionPAN11")]') + self.assertIsInstance(element,WebElement) + + def test_D_directory_collection(self): + + driver = self.driver + #login(driver,pandora_url="http://192.168.50.50:84/") + #detect_and_pass_all_wizards(driver) + + create_directory_in_collection(driver,self.new_collection_name,"directory_collectionPAN11") + + element = driver.find_element_by_xpath('//a[contains(.,"directory_collectionPAN11")]') + self.assertIsInstance(element,WebElement) + + + def test_E_delete_collection(self): + + driver = self.driver + #login(driver,pandora_url="http://192.168.50.50:84/") + #detect_and_pass_all_wizards(driver) + + delete_collection(driver,self.new_collection_name) + + #Check that New_collectionPAN11 is delete + element = driver.find_elements_by_xpath('//a[contains(.,"'+self.new_collection_name+'")]') + self.assertEqual(element,[]) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/console/ENT_PAN11.py b/tests/console/ENT_PAN11.py deleted file mode 100644 index 741a2786d4..0000000000 --- a/tests/console/ENT_PAN11.py +++ /dev/null @@ -1,127 +0,0 @@ -""" -# -*- 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 -from include.module_functions import create_module -from include.agent_functions import create_agent_group -from include.policy_functions import * -from include.collection_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 - - -class PAN11(PandoraWebDriverTestCase): - - test_name = u'PAN_11' - test_description = u'Collection tests' - tickets_associated = [] - - def test_A_create_collection(self): - - driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) - - create_collection(driver,"collectionPAN11","PAN11",group="All",description="Collection with PAN11") - - search_collection(driver,"collectionPAN11",go_to_collection=False) - - time.sleep(6) - - try: - element = driver.find_element_by_xpath('//a[contains(.,"collectionPAN11")]') - self.assertIsInstance(element,WebElement) - - except AssertionError as e: - self.verificationErrors.append(str(e)) - - except NoSuchElementException as e: - self.verificationErrors.append(str(e)) - - def test_B_edit_collection(self): - - driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) - - edit_collection(driver,"collectionPAN11",new_name="New_collectionPAN11",group="Applications",description="Edit collectionPAN11") - - search_collection(driver,"New_collectionPAN11",go_to_collection=False) - - time.sleep(6) - - try: - element = driver.find_element_by_xpath('//a[contains(.,"New_collectionPAN11")]') - self.assertIsInstance(element,WebElement) - - except AssertionError as e: - self.verificationErrors.append(str(e)) - - except NoSuchElementException as e: - self.verificationErrors.append(str(e)) - - def test_C_create_text_collection(self): - - driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) - - create_text_in_collection(driver,"New_collectionPAN11","file_collectionPAN11",text_file="test file") - time.sleep(6) - - try: - element = driver.find_element_by_xpath('//a[contains(.,"file_collectionPAN11")]') - self.assertIsInstance(element,WebElement) - - except AssertionError as e: - self.verificationErrors.append(str(e)) - - except NoSuchElementException as e: - self.verificationErrors.append(str(e)) - - def test_D_directory_collection(self): - - driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) - - create_directory_in_collection(driver,"New_collectionPAN11","directory_collectionPAN11") - - time.sleep(6) - - try: - element = driver.find_element_by_xpath('//a[contains(.,"directory_collectionPAN11")]') - self.assertIsInstance(element,WebElement) - - except AssertionError as e: - self.verificationErrors.append(str(e)) - - except NoSuchElementException as e: - self.verificationErrors.append(str(e)) - - def test_E_delete_collection(self): - - driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) - - delete_collection(driver,"New_collectionPAN11") - - time.sleep(6) - - try: - #Check that New_collectionPAN11 is delete - element = driver.find_elements_by_xpath('//a[contains(.,"New_collectionPAN11")]') - self.assertEqual(element,[]) - - except AssertionError as e: - self.verificationErrors.append(str(e)) -if __name__ == "__main__": - unittest.main() -""" diff --git a/tests/console/PAN1.py b/tests/console/PAN1.py index 9cc8c7023c..dd5146b844 100644 --- a/tests/console/PAN1.py +++ b/tests/console/PAN1.py @@ -16,7 +16,7 @@ class PAN1(PandoraWebDriverTestCase): def test_pan1(self): driver = self.driver - login(driver) + self.login() detect_and_pass_all_wizards(driver) click_menu_element(driver,"General Setup") self.assertEqual("IP list with API access", driver.find_element_by_id("table2-15-0").text) diff --git a/tests/console/PAN2.py b/tests/console/PAN2.py index bb04c69f5a..e60eb73644 100644 --- a/tests/console/PAN2.py +++ b/tests/console/PAN2.py @@ -17,8 +17,7 @@ class PAN2(PandoraWebDriverTestCase): def test_pan2(self): driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) + self.login() create_agent(driver,"prueba masivas 1") diff --git a/tests/console/PAN3.py b/tests/console/PAN3.py index f7ec190309..298270bd27 100644 --- a/tests/console/PAN3.py +++ b/tests/console/PAN3.py @@ -19,8 +19,7 @@ class PAN3(PandoraWebDriverTestCase): def test_pan3(self): driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) + self.login() create_agent(driver,"PAN3_agent",ip="127.0.0.1") create_module("network_server",driver,agent_name="PAN3_agent",module_name="PAN3_module",component_group="Network Management",network_component="Host Alive",ip="127.0.0.1") diff --git a/tests/console/PAN4.py b/tests/console/PAN4.py index 93d14f1992..4d762b457b 100644 --- a/tests/console/PAN4.py +++ b/tests/console/PAN4.py @@ -22,8 +22,7 @@ class PAN4(PandoraWebDriverTestCase): def test_pan4(self): driver = self.driver - login(driver,user="admin",passwd="pandora") - detect_and_pass_all_wizards(driver) + self.login() #Creates a user with Chief Operator - Applications profile profile_list = [] @@ -35,11 +34,10 @@ class PAN4(PandoraWebDriverTestCase): create_report(driver,"PAN_4_Servers","Servers") #Logout - logout(driver,self.base_url) + self.logout() #Login - login(driver,user='PAN_4',passwd='PAN_4') - detect_and_pass_all_wizards(driver) + self.login(user='PAN_4',passwd='PAN_4') #Check that the report is visible click_menu_element(driver,"Custom reporting") @@ -69,8 +67,8 @@ class PAN4(PandoraWebDriverTestCase): #Delete reports - logout(driver,self.base_url) - login(driver,user="admin",passwd="pandora") + self.logout() + self.login(user="admin",passwd="pandora") delete_report(driver,"PAN_4_Servers") delete_report(driver,"PAN_4_Applications") diff --git a/tests/console/PAN5.py b/tests/console/PAN5.py index 1c36d7bc6d..72aef2918d 100644 --- a/tests/console/PAN5.py +++ b/tests/console/PAN5.py @@ -23,7 +23,7 @@ class PAN5(PandoraWebDriverTestCase): def test_pan5(self): driver = self.driver - login(driver) + self.login() detect_and_pass_all_wizards(driver) create_agent(driver,u"次のライセンスに基づいていま") diff --git a/tests/console/PAN7.py b/tests/console/PAN7.py index 53888a8767..fd6f095d5f 100644 --- a/tests/console/PAN7.py +++ b/tests/console/PAN7.py @@ -19,13 +19,13 @@ class PAN7(PandoraWebDriverTestCase): def test_pan7(self): driver = self.driver - login(driver) + self.login() detect_and_pass_all_wizards(driver) activate_home_screen(driver,"Event list") - logout(driver,self.base_url) - login(driver) + self.logout() + self.login() try: diff --git a/tests/console/PAN8.py b/tests/console/PAN8.py index 32c851a73b..76ddae9bde 100644 --- a/tests/console/PAN8.py +++ b/tests/console/PAN8.py @@ -21,7 +21,7 @@ class PAN8(PandoraWebDriverTestCase): def test_pan8(self): driver = self.driver - login(driver) + self.login() detect_and_pass_all_wizards(driver) create_agent(driver,"PAN_8",group="Applications",ip="192.168.50.50") @@ -39,9 +39,9 @@ class PAN8(PandoraWebDriverTestCase): create_user(driver,"PAN8_user","pandora",profile_list=l) - logout(driver,self.base_url) + self.logout() - login(driver,user="PAN8_user") + self.login(user="PAN8_user") detect_and_pass_all_wizards(driver) diff --git a/tests/console/PAN9.py b/tests/console/PAN9.py index 765e280db3..4c10dc19dd 100644 --- a/tests/console/PAN9.py +++ b/tests/console/PAN9.py @@ -22,7 +22,7 @@ class PAN9(PandoraWebDriverTestCase): def test_pan9(self): driver = self.driver - login(driver) + self.login() detect_and_pass_all_wizards(driver) create_agent_group(driver,"PAN9_A",propagate_acl=True,description="Group A, with propagate ACL, son of ALL") @@ -37,9 +37,9 @@ class PAN9(PandoraWebDriverTestCase): create_user(driver,"PAN9_user","pandora",profile_list=l) - logout(driver,self.base_url) + self.logout() - login(driver,user="PAN9_user") + self.login(user="PAN9_user") detect_and_pass_all_wizards(driver) diff --git a/tests/console/Policies.py b/tests/console/Policies.py index 1879abfae9..749abab5b8 100644 --- a/tests/console/Policies.py +++ b/tests/console/Policies.py @@ -23,8 +23,7 @@ class Policies(PandoraWebDriverTestCase): def test_1_create_policy(self): driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) + self.login() create_policy(driver,self.policy_name,"Applications",description="Policy for test") @@ -36,8 +35,6 @@ class Policies(PandoraWebDriverTestCase): def test_2_add_network_server_module_to_policy(self): driver = self.driver - login(driver) - detect_and_pass_all_wizards(driver) add_module_policy(driver,self.policy_name,"network_server",driver,module_name=self.network_server_module_name,component_group="Network Management",network_component="Host Alive") diff --git a/tests/console/include/common_classes_60.py b/tests/console/include/common_classes_60.py index e66aa5ca44..0700df6cf7 100644 --- a/tests/console/include/common_classes_60.py +++ b/tests/console/include/common_classes_60.py @@ -19,8 +19,6 @@ class ArticaTestResult(TestResult): 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 @@ -39,18 +37,27 @@ class PandoraWebDriverTestCase(TestCase): 'version': "46", } + @classmethod + def setUpClass(cls): + cls.is_development = os.getenv('DEVELOPMENT', False) + if cls.is_development != False: + cls.driver = webdriver.Firefox() + cls.base_url = os.getenv('DEVELOPMENT_URL') + else: + #Start VM in Sauce Labs + cls.driver = webdriver.Remote(command_executor='http://'+cls.sauce_username+':'+cls.sauce_access_key+'@ondemand.saucelabs.com:80/wd/hub',desired_capabilities=cls.desired_cap) + cls.sauce_labs_job_id = cls.driver.session_id + cls.base_url = "http://127.0.0.1/" + + + + @classmethod + def tearDownClass(cls): + cls.driver.quit() + def setUp(self): self.time_started = datetime.now() - #Start VM in Sauce Labs - is_development = os.getenv('DEVELOPMENT', False) - if is_development != False: - self.driver = webdriver.Firefox() - else: - self.driver = webdriver.Remote(command_executor='http://'+self.sauce_username+':'+self.sauce_access_key+'@ondemand.saucelabs.com:80/wd/hub',desired_capabilities=self.desired_cap) - self.sauce_labs_job_id = self.driver.session_id # We store this information to update the job info when the tests are done - self.driver.implicitly_wait(30) - self.base_url = "http://127.0.0.1/" self.verificationErrors = [] self.accept_next_alert = True super(PandoraWebDriverTestCase, self).setUp() @@ -80,8 +87,39 @@ class PandoraWebDriverTestCase(TestCase): tack = datetime.now() diff = tack - self.time_started self.time_elapsed = diff.seconds - self.driver.quit() self.assertEqual([], self.verificationErrors) super(PandoraWebDriverTestCase, self).tearDown() + + def login(self,user="admin",passwd="pandora",pandora_url=None): + print u"Logging in" + + driver = self.driver + + if pandora_url is None: + pandora_url = self.base_url + + 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() + + def logout(self,pandora_url=None): + print u"Logging out" + + driver = self.driver + + if pandora_url is None: + pandora_url = self.base_url + + if pandora_url[-1] != '/': + driver.find_element_by_xpath('//div[@id="container"]//a[@href="'+pandora_url+'/pandora_console/index.php?bye=bye"]').click() + else: + driver.find_element_by_xpath('//div[@id="container"]//a[@href="'+pandora_url+'pandora_console/index.php?bye=bye"]').click() + + driver.get(pandora_url+"/pandora_console/index.php") + refresh_N_times_until_find_element(driver,2,"nick") + diff --git a/tests/console/include/common_functions_60.py b/tests/console/include/common_functions_60.py index a0c55d98f4..a168a5e92a 100644 --- a/tests/console/include/common_functions_60.py +++ b/tests/console/include/common_functions_60.py @@ -15,8 +15,19 @@ def gen_random_string(size,preffix=None): return random_string -def login(driver,user="admin",passwd="pandora",pandora_url="http://127.0.0.1/"): +def login(driver,user="admin",passwd="pandora",pandora_url=None): print u"Logging in" + try: + print driver.base_url + except Exception as e: + print "se casco" + print e + print u"yep" + if pandora_url is None: + pandora_url = driver.base_url + + print "Pandora url is "+pandora_url + driver.get(pandora_url+"/pandora_console/index.php") driver.find_element_by_id("nick").clear() driver.find_element_by_id("nick").send_keys(user)