2016-05-23 19:50:08 +02:00
|
|
|
# -*- 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
|
2016-05-25 15:39:51 +02:00
|
|
|
from sauceclient import SauceClient
|
2016-05-24 13:36:15 +02:00
|
|
|
from os import environ
|
2016-05-23 19:50:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
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 = []
|
2016-05-24 13:36:15 +02:00
|
|
|
sauce_username = environ["SAUCE_USERNAME"]
|
|
|
|
sauce_access_key = environ["SAUCE_ACCESS_KEY"]
|
2016-05-25 15:39:51 +02:00
|
|
|
sauce_client = None
|
2016-05-24 13:36:15 +02:00
|
|
|
|
|
|
|
desired_cap = {
|
|
|
|
'tunnel-identifier': environ["TRAVIS_JOB_NUMBER"],
|
|
|
|
'platform': "Windows 10",
|
|
|
|
'browserName': "firefox",
|
|
|
|
'version': "46",
|
|
|
|
}
|
2016-05-23 19:50:08 +02:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.time_started = datetime.now()
|
2016-05-25 15:39:51 +02:00
|
|
|
#Start VM in Sauce Labs
|
2016-05-24 13:36:15 +02:00
|
|
|
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)
|
2016-05-25 15:39:51 +02:00
|
|
|
|
|
|
|
self.sauce_client = SauceClient(self.sauce_username, self.sauce_access_key)
|
2016-05-23 19:50:08 +02:00
|
|
|
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()
|
2016-05-25 15:39:51 +02:00
|
|
|
#Update Sauce Labs job
|
|
|
|
is_test_successful = self.verificationErrors == []
|
2016-05-25 16:38:10 +02:00
|
|
|
self.sauce_client.jobs.update_job(self.driver.session_id, passed=is_test_successful,tags=[environ["TRAVIS_BRANCH"],self.id()],build_num=environ["TRAVIS_JOB_NUMBER"],name=str(environ["TRAVIS_COMMIT"])+"_"+str(self.id().split('.')[1]))
|
2016-05-25 15:39:51 +02:00
|
|
|
|
2016-05-23 19:50:08 +02:00
|
|
|
self.assertEqual([], self.verificationErrors)
|
|
|
|
super(PandoraWebDriverTestCase, self).tearDown()
|
|
|
|
|