Added more testing utilities

This commit is contained in:
axl89 2016-06-03 16:37:03 +02:00
parent 94ed066b31
commit 17cc54aa9c
3 changed files with 104 additions and 3 deletions

71
tests/PAN3_testing.py Normal file
View File

@ -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()

View File

@ -41,10 +41,12 @@ class PandoraWebDriverTestCase(TestCase):
def setUp(self):
self.time_started = datetime.now()
#Start VM in Sauce Labs
if environ["DEVELOPMENT"] == "1":
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.sauce_client = SauceClient(self.sauce_username, self.sauce_access_key)
self.driver.implicitly_wait(30)
self.base_url = "http://localhost/"
self.verificationErrors = []

28
tests/testpan3.py Executable file
View File

@ -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)