Added Travis CI tests
This commit is contained in:
parent
e04ed75994
commit
935e33675b
28
.travis.yml
28
.travis.yml
|
@ -1,7 +1,33 @@
|
|||
sudo: required
|
||||
|
||||
language: python
|
||||
python:
|
||||
- 2.7
|
||||
|
||||
env:
|
||||
global:
|
||||
- secure: "MEfyEpYEBkPmgPYX3CDKhaoiOltH5lDcUOYZ/19Yflg6ee20IBZOywCmrKH7VouKlOHUrGTUQqHBou0npm93qBju3MrPCE2R62PiDV2EHCGl3AFpLkgt0m1/DceWCWKlL+gI8uvnEFzVUuaPm6cEcRn1ikzg5b084bTxJ2B1Bvs="
|
||||
- SAUCE_USERNAME="artica_pandorafms"
|
||||
|
||||
addons:
|
||||
firefox: "latest"
|
||||
sauce_connect: true
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_install:
|
||||
- sudo apt-get install xvfb
|
||||
|
||||
install:
|
||||
- pip install selenium PyVirtualDisplay sauceclient
|
||||
|
||||
#before_script:
|
||||
# - "export DISPLAY=:99.0"
|
||||
# - "sh -e /etc/init.d/xvfb start"
|
||||
# - sleep 4 # give xvfb some time to start
|
||||
|
||||
script:
|
||||
- docker run --rm -t -v "$TRAVIS_BUILD_DIR:/tmp/pandorafms" pandorafms/pandorafms-base /tmp/pandorafms/tests/test.sh
|
||||
- docker run --name pandorafms -h pandorafms -dt -v "$TRAVIS_BUILD_DIR:/tmp/pandorafms" -p 127.0.0.1:80:80 pandorafms/pandorafms-base tail -f /var/log/messages
|
||||
- docker exec -t pandorafms /tmp/pandorafms/tests/test.sh
|
||||
- python $TRAVIS_BUILD_DIR/tests/run_console_tests.py
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
*.pyc
|
|
@ -21,9 +21,9 @@ RUN yum -y update; yum clean all;
|
|||
|
||||
# Generic dependencies
|
||||
RUN yum install -y \
|
||||
firefox
|
||||
python-pip
|
||||
xorg-x11-server-Xvfb
|
||||
firefox \
|
||||
python-pip \
|
||||
xorg-x11-server-Xvfb; yum clean all;
|
||||
RUN pip install pyvirtualdisplay
|
||||
RUN pip install selenium
|
||||
|
||||
|
@ -57,7 +57,7 @@ RUN yum install -y \
|
|||
nmap \
|
||||
xprobe2 \
|
||||
mysql-server \
|
||||
mysql
|
||||
mysql; yum clean all;
|
||||
|
||||
# Pandora FMS Server dependencies
|
||||
RUN yum install -y \
|
||||
|
@ -91,5 +91,8 @@ RUN yum install -y \
|
|||
perl-XML-Twig \
|
||||
perl-Encode-Locale \
|
||||
net-snmp \
|
||||
net-snmp-utils
|
||||
net-snmp-utils \
|
||||
perl-Test-Simple; yum clean all;
|
||||
|
||||
#Exposing ports for: HTTP, SNMP Traps, Anytermd (SSH), Anytermd (Telnet), Tentacle protocol
|
||||
EXPOSE 80 162/udp 8022 8023 41121
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from include.common_classes_60 import PandoraWebDriverTestCase
|
||||
from include.common_functions_60 import login
|
||||
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
|
||||
import unittest, time, re
|
||||
|
||||
class PAN1(PandoraWebDriverTestCase):
|
||||
test_name = u'PAN_1'
|
||||
test_description = u'Tests that an Administrator user can access the Setup'
|
||||
tickets_associated = []
|
||||
|
||||
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)
|
||||
self.assertEqual("IP list with API access", driver.find_element_by_id("table2-15-0").text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from unittest import TestResult, TestCase
|
||||
from common_functions_60 import *
|
||||
from datetime import datetime
|
||||
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 os import environ
|
||||
|
||||
|
||||
class ArticaTestResult(TestResult):
|
||||
success = []
|
||||
def addSuccess(self, test):
|
||||
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
|
||||
time_started = None
|
||||
time_elapsed = None #Total time of the test
|
||||
tickets_associated = []
|
||||
sauce_username = environ["SAUCE_USERNAME"]
|
||||
sauce_access_key = environ["SAUCE_ACCESS_KEY"]
|
||||
|
||||
desired_cap = {
|
||||
'tunnel-identifier': environ["TRAVIS_JOB_NUMBER"],
|
||||
'platform': "Windows 10",
|
||||
'browserName': "firefox",
|
||||
'version': "46",
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.time_started = datetime.now()
|
||||
#self.driver = webdriver.Firefox()
|
||||
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.driver.implicitly_wait(30)
|
||||
self.base_url = "http://localhost/"
|
||||
self.verificationErrors = []
|
||||
self.accept_next_alert = True
|
||||
super(PandoraWebDriverTestCase, self).setUp()
|
||||
|
||||
def is_element_present(self, how, what):
|
||||
try: self.driver.find_element(by=how, value=what)
|
||||
except NoSuchElementException, e: return False
|
||||
return True
|
||||
|
||||
def is_alert_present(self):
|
||||
try: self.driver.switch_to_alert()
|
||||
except NoAlertPresentException, e: return False
|
||||
return True
|
||||
|
||||
def close_alert_and_get_its_text(self):
|
||||
try:
|
||||
alert = self.driver.switch_to_alert()
|
||||
alert_text = alert.text
|
||||
if self.accept_next_alert:
|
||||
alert.accept()
|
||||
else:
|
||||
alert.dismiss()
|
||||
return alert_text
|
||||
finally: self.accept_next_alert = True
|
||||
|
||||
def tearDown(self):
|
||||
tack = datetime.now()
|
||||
diff = tack - self.time_started
|
||||
self.time_elapsed = diff.seconds
|
||||
self.driver.quit()
|
||||
self.assertEqual([], self.verificationErrors)
|
||||
super(PandoraWebDriverTestCase, self).tearDown()
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from selenium import selenium
|
||||
|
||||
def login(driver,user="admin",passwd="pandora",pandora_url="http://127.0.0.1/"):
|
||||
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()
|
|
@ -29,6 +29,7 @@ browser.implicitly_wait(300) # The installation is going to take a long time.
|
|||
browser.find_element_by_xpath("//*[@id='step5']/img").click()
|
||||
browser.implicitly_wait(5)
|
||||
assert("Installation complete" in browser.page_source)
|
||||
browser.find_element_by_name("rn_file").click()
|
||||
|
||||
# Clean-up
|
||||
browser.quit()
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
from unittest import *
|
||||
from console.include.common_functions_60 import *
|
||||
from console.include.common_classes_60 import *
|
||||
import subprocess, os, time
|
||||
|
||||
def get_test_file(test_list):
|
||||
#return [test[0].split(' ')[0].split('.')[0].split('<')[1] for test in test_list]
|
||||
return [test[0].test_name for test in test_list]
|
||||
|
||||
a = TestLoader()
|
||||
tests = a.discover(start_dir='console',pattern='PAN*.py')
|
||||
c = ArticaTestResult()
|
||||
tests.run(c)
|
||||
|
||||
print "Tests failed: %s" % (get_test_file(c.failures))
|
||||
print "Tests succeeded: %s" % (get_test_file(c.success))
|
||||
print "Tests skipped: %s" % (get_test_file(c.skipped))
|
||||
print "Tests with errors: %s" % (get_test_file(c.errors))
|
||||
|
||||
if (len(c.failures)+len(c.errors)+len(c.skipped)) != 0:
|
||||
exit(1)
|
||||
|
||||
else:
|
||||
exit(0)
|
Loading…
Reference in New Issue