Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Fix bug 1134276 - Fix selenium tests on Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
lcamacho committed Feb 19, 2015
1 parent 356c7eb commit 3307c26
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -17,6 +17,8 @@ python:
#- 2.7

before_install:
- export DISPLAY=:99.0
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16
- git submodule update --init --recursive
install: bin/travis/install.sh
before_script:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -366,8 +366,7 @@ Included is a set of comprehensive tests, which you can run by:
``./manage.py test``

If you want to run selenium tests don't forget to add
`RUN_SELENIUM_TESTS = True` in your `airmozilla/settings/local.py` file
also you need to install [PhantomJS](http://phantomjs.org/).
`RUN_SELENIUM_TESTS = True` in your `airmozilla/settings/local.py` file.

To see the tests' code coverage, use:
``./manage.py test --with-coverage --cover-erase --cover-html --cover-package=airmozilla``
Expand Down
38 changes: 25 additions & 13 deletions airmozilla/base/tests/testbase.py
@@ -1,26 +1,15 @@
import os
import shutil
import functools

from nose.plugins.skip import SkipTest
from selenium import webdriver

from django.test import TestCase
from django.test import TestCase, LiveServerTestCase
from django.conf import settings
from django.contrib.auth.models import User
from django.core.files import File


def optional_selenium(test):

@functools.wraps(test)
def inner(*a, **k):
if not settings.RUN_SELENIUM_TESTS:
raise SkipTest("Test %s is skipped" % test.__name__)
return test(*a, **k)

return inner


class DjangoTestCase(TestCase):

def shortDescription(self):
Expand Down Expand Up @@ -54,3 +43,26 @@ def _upload_media(self, image_path):
image_path,
settings.MEDIA_ROOT
)


class DjangoLiveServerTestCase(LiveServerTestCase):

@classmethod
def setUpClass(cls):
if settings.RUN_SELENIUM_TESTS:
cls.driver = webdriver.Firefox()
cls.driver.implicitly_wait(30)
cls.base_url = cls.live_server_url
cls.driver.set_window_size(1120, 550)
super(DjangoLiveServerTestCase, cls).setUpClass()

@classmethod
def tearDownClass(cls):
if settings.RUN_SELENIUM_TESTS:
cls.driver.quit()
super(DjangoLiveServerTestCase, cls).tearDownClass()

def setUp(self):
if not settings.RUN_SELENIUM_TESTS:
raise SkipTest("settings.RUN_SELENIUM_TESTS is set to False")
super(DjangoLiveServerTestCase, self).setUp()
22 changes: 2 additions & 20 deletions airmozilla/main/tests/selenium/test_calendar.py
@@ -1,31 +1,13 @@
import re

from nose.tools import eq_, ok_
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException

from django.test import LiveServerTestCase
from airmozilla.base.tests.testbase import DjangoLiveServerTestCase

from airmozilla.base.tests.testbase import optional_selenium


class CalendarLiveServerTestCase(LiveServerTestCase):

@optional_selenium
def setUp(self):
super(CalendarLiveServerTestCase, self).setUp()
self.driver = webdriver.PhantomJS()
self.driver.implicitly_wait(30)
self.base_url = self.live_server_url
self.driver.set_window_size(1120, 550)
# ugly hack necessary to clear localStorage
self.driver.get(self.base_url)
self.driver.execute_script('localStorage.clear()')

def tearDown(self):
self.driver.quit()
super(CalendarLiveServerTestCase, self).tearDown()
class CalendarLiveServerTestCase(DjangoLiveServerTestCase):

def is_element_present(self, how, what):
try:
Expand Down
9 changes: 1 addition & 8 deletions bin/travis/setup.sh
Expand Up @@ -24,12 +24,5 @@ CACHES = {
}
}
# RUN_SELENIUM_TESTS = True
RUN_SELENIUM_TESTS = True
SETTINGS

# The reason the `RUN_SELENIUM_TESTS=True` piece is commented out is because
# the selenium tests have become unpredictably broken in Travis and causing
# many test builds to stall or error out due to the addition of running
# the selenium tests.
# But we don't want to entirely abandon this effort. We just need to figure
# out how to make it more stable.

0 comments on commit 3307c26

Please sign in to comment.