From ee5f0ac0cef7606a9fd4929434e65eecd179796c Mon Sep 17 00:00:00 2001 From: Will Daly Date: Wed, 15 May 2013 08:24:27 -0400 Subject: [PATCH] Workaround for Ubuntu ChromeDriver issue. Now retries until it acquires a valid session. --- common/djangoapps/terrain/browser.py | 30 ++++++++++++++++++++- common/djangoapps/terrain/course_helpers.py | 10 +++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/common/djangoapps/terrain/browser.py b/common/djangoapps/terrain/browser.py index 7ae0a7bc46..10136dfe78 100644 --- a/common/djangoapps/terrain/browser.py +++ b/common/djangoapps/terrain/browser.py @@ -11,6 +11,7 @@ from splinter.browser import Browser from logging import getLogger from django.core.management import call_command from django.conf import settings +from selenium.common.exceptions import WebDriverException # Let the LMS and CMS do their one-time setup # For example, setting up mongo caches @@ -35,14 +36,41 @@ else: LOGGER = getLogger(__name__) LOGGER.info("Loading the lettuce acceptance testing terrain file...") +MAX_VALID_BROWSER_ATTEMPTS = 20 + @before.harvest def initial_setup(server): """ Launch the browser once before executing the tests. """ browser_driver = getattr(settings, 'LETTUCE_BROWSER', 'chrome') - world.browser = Browser(browser_driver) + # There is an issue with ChromeDriver2 r195627 on Ubuntu + # in which we sometimes get an invalid browser session. + # This is a work-around to ensure that we get a valid session. + success = False + num_attempts = 0 + while (not success) and num_attempts < MAX_VALID_BROWSER_ATTEMPTS: + + # Get a browser session + world.browser = Browser(browser_driver) + + # Try to visit the main page + # If the browser session is invalid, this will + # raise a WebDriverException + try: + world.visit('/') + + except WebDriverException: + num_attempts += 1 + + else: + success = True + + # If we were unable to get a valid session within the limit of attempts, + # then we cannot run the tests. + if not success: + raise IOError("Could not acquire valid ChromeDriver browser session.") @before.each_scenario def reset_data(scenario): diff --git a/common/djangoapps/terrain/course_helpers.py b/common/djangoapps/terrain/course_helpers.py index 72ea62a1e0..cc1f770217 100644 --- a/common/djangoapps/terrain/course_helpers.py +++ b/common/djangoapps/terrain/course_helpers.py @@ -38,11 +38,11 @@ def create_user(uname): @world.absorb def log_in(username, password): - ''' - Log the user in programatically - ''' - - world.browser.visit(django_url('/')) + """ + Log the user in programatically. + This will delete any existing cookies to ensure that the user + logs in to the correct session. + """ # Authenticate the user user = authenticate(username=username, password=password)