-
Notifications
You must be signed in to change notification settings - Fork 75
Selenium tests #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selenium tests #441
Changes from all commits
7a4ea70
8f3f229
3e0de0f
ba23c60
9ec9d4d
026ed3c
a1a7f17
dda19a5
e7ad2df
b0faf9a
03f4957
57f1c15
6fac22a
07f174a
7840a0d
849e4e3
ea3a855
0db0d20
82f6b82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,9 +26,13 @@ | |
| import adagios.settings | ||
| import os | ||
| import pynag.Utils.misc | ||
| from django.test import LiveServerTestCase | ||
| from django.utils import unittest | ||
| import atexit | ||
|
|
||
| from django.utils.translation import ugettext as _ | ||
|
|
||
| SELENIUM_DRIVER = None | ||
|
|
||
| def wait(object_type, WaitObject, WaitCondition, WaitTrigger, **kwargs): | ||
| livestatus = adagios.status.utils.livestatus(None) | ||
|
|
@@ -170,3 +174,54 @@ def terminate(self): | |
| self.restore_adagios_global_variables() | ||
| super(FakeAdagiosEnvironment, self).terminate() | ||
|
|
||
|
|
||
| class SeleniumTestCase(LiveServerTestCase): | ||
| driver = None | ||
| environment = None | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| global SELENIUM_DRIVER | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do this without having a global variable ? |
||
| try: | ||
| from selenium import webdriver | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove all imports to the top of file |
||
| except ImportError: | ||
| raise unittest.SkipTest("No selenium installed") | ||
|
|
||
| super(SeleniumTestCase, cls).setUpClass() | ||
|
|
||
| cls.nagios_config = adagios.settings.nagios_config | ||
| cls.environment = adagios.utils.FakeAdagiosEnvironment() | ||
| cls.environment.create_minimal_environment() | ||
| cls.environment.configure_livestatus() | ||
| cls.environment.update_adagios_global_variables() | ||
| cls.environment.start() | ||
| cls.livestatus = cls.environment.get_livestatus() | ||
|
|
||
| if not SELENIUM_DRIVER: | ||
| if 'TRAVIS' in os.environ: | ||
| capabilities = webdriver.DesiredCapabilities.CHROME | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little off. Why specifically run a different rendering engine inside travis than on workstation ? |
||
| capabilities["build"] = os.environ["TRAVIS_BUILD_NUMBER"] | ||
| capabilities["tags"] = [os.environ["TRAVIS_PYTHON_VERSION"], "CI"] | ||
| capabilities["tunnel-identifier"] = os.environ["TRAVIS_JOB_NUMBER"] | ||
| capabilities['platform'] = "Windows 8.1" | ||
| capabilities['version'] = "31" | ||
|
|
||
| username = os.environ["SAUCE_USERNAME"] | ||
| access_key = os.environ["SAUCE_ACCESS_KEY"] | ||
|
|
||
| hub_url = "%s:%s@ondemand.saucelabs.com/wd/hub" % (username, access_key) | ||
| SELENIUM_DRIVER = webdriver.Remote(desired_capabilities=capabilities, command_executor="http://%s" % hub_url) | ||
| else: | ||
| SELENIUM_DRIVER = webdriver.Firefox() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. webdriver.Firefox() does not run on my machine, maybe there are some undocumented dependencies. Additionally, consider wrapping this initialization code in a try/catch so that a meaningful message can be send to whomever is running the unit tests. |
||
| # Exit browser when all tests are done | ||
| atexit.register(SELENIUM_DRIVER.quit) | ||
|
|
||
|
|
||
|
|
||
| cls.driver = SELENIUM_DRIVER | ||
|
|
||
| @classmethod | ||
| def tearDownClass(cls): | ||
| cls.environment.terminate() | ||
| super(SeleniumTestCase, cls).tearDownClass() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class really belongs somewhere else. The modules imported here, like unittest and atexit, should not imported on a production instance of adagios (they belong to the tests only).
Please move this somewhere else, adagios/selenium_tests.py if nothing else seems to fit.