From c85d12f26479458ba78c55432505b3e00e782623 Mon Sep 17 00:00:00 2001 From: axl89 Date: Fri, 3 Jun 2016 16:40:58 +0200 Subject: [PATCH] Created a utils directory with some arrangements --- .../utils/selenium_ci_tester/PAN3_testing.py | 71 +++++++++++++++++++ tests/utils/selenium_ci_tester/README.txt | 1 + tests/utils/selenium_ci_tester/testpan3.py | 28 ++++++++ 3 files changed, 100 insertions(+) create mode 100644 tests/utils/selenium_ci_tester/PAN3_testing.py create mode 100644 tests/utils/selenium_ci_tester/README.txt create mode 100755 tests/utils/selenium_ci_tester/testpan3.py diff --git a/tests/utils/selenium_ci_tester/PAN3_testing.py b/tests/utils/selenium_ci_tester/PAN3_testing.py new file mode 100644 index 0000000000..429d695c64 --- /dev/null +++ b/tests/utils/selenium_ci_tester/PAN3_testing.py @@ -0,0 +1,71 @@ +# -*- 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, gen_random_string +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 +import unittest, time, re + + +class PAN3(PandoraWebDriverTestCase): + + test_name = u'PAN_3' + test_description = u'Creates a simple ICMP check against localhost and checks the result is 1' + tickets_associated = [] + + def test_pan3(self): + driver = self.driver + login(driver,"admin","pandora",self.base_url) + 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(gen_random_string(10,preffix="PAN3_")) + driver.find_element_by_id("text-direccion").click() + driver.find_element_by_id("text-direccion").clear() + driver.find_element_by_id("text-direccion").send_keys("127.0.0.1") + driver.find_element_by_id("submit-crtbutton").click() + driver.find_element_by_css_selector("li.nomn.tab_godmode > a > img.forced_title").click() + driver.find_element_by_id("moduletype").click() + Select(driver.find_element_by_id("moduletype")).select_by_visible_text("Create a new network server module") + driver.find_element_by_name("updbutton").click() #Alternative XPATH: //*[@class="datos"]/input + driver.find_element_by_name("updbutton").click() #IMPORTANT! It's needed to click TWICE! One for leave the combo, and other for clicking the button + driver.find_element_by_id("id_module_type").click() + combo = driver.find_element_by_id("id_module_type") + Select(combo).select_by_visible_text("Remote ICMP network agent, boolean data") + combo.click() + driver.find_element_by_id("text-name").clear() + driver.find_element_by_id("text-name").send_keys("ping test") + driver.find_element_by_id("submit-crtbutton").click() + driver.find_element_by_xpath('//*[@id="menu_tab"]//a[contains(@href,"ver_agente")]').click() + + max_retries = 3 + i = 1 + element_text = "" + + while (i <= max_retries): # Temporary workaround to weird StaleElementReferenceException exceptions due Javascript altering the DOM + try: + element_text = refresh_N_times_until_find_element(driver,5,"table1-1-7",how=By.ID).text + self.assertEqual("1", element_text.lstrip().rstrip()) # The lstrip.rstrip is done because if not, this error is raised: "'1' != u'1 '" + print "found it" + break + except StaleElementReferenceException as e_stale: + i = i+1 + print "found stale" + if i > max_retries: + print "giving up" + self.verificationErrors.append(str(e_stale)) + break + else: + print "retrying" + next + except AssertionError as e: + print "assertion error" + self.verificationErrors.append(str(e)) + break + +if __name__ == "__main__": + unittest.main() + diff --git a/tests/utils/selenium_ci_tester/README.txt b/tests/utils/selenium_ci_tester/README.txt new file mode 100644 index 0000000000..b32b06dc83 --- /dev/null +++ b/tests/utils/selenium_ci_tester/README.txt @@ -0,0 +1 @@ +The testpan3.py is an example on how to do a test of the PAN3_testing TestCase. It should be placed on the pandorafms/tests folder, and the PAN3_testing in the console folder diff --git a/tests/utils/selenium_ci_tester/testpan3.py b/tests/utils/selenium_ci_tester/testpan3.py new file mode 100755 index 0000000000..0bb3c696f8 --- /dev/null +++ b/tests/utils/selenium_ci_tester/testpan3.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +from unittest import * +from console import * +from console.include.common_functions_60 import * +from console.include.common_classes_60 import * +from os import environ +import subprocess, time, sys +from console.PAN3 import * + + +suite = TestSuite() +for i in range(0,10): + suite.addTest(PAN3('test_pan3')) + +result = ArticaTestResult() +suite.run(result) + +print "Tests failed: %s" % result.failures +print "Tests succeeded: %s" % result.success +print "Tests skipped: %s" % result.skipped +print "Tests with errors: %s" % result.errors + +if (len(result.failures)+len(result.errors)+len(result.skipped)) != 0: + sys.exit(1) + +else: + sys.exit(0) +