Ejemplo n.º 1
0
def hook_store_augmented_step_name(step):
    """
    Get a more meaningful step name that can be used in reporting
    while this step runs.
    """
    config = world.fattoush
    world.absorb("[{0}] {1}".format(config.name, step.sentence), "step_name")
Ejemplo n.º 2
0
def setup_and_launch_browser():
    """
    Use the environment variables to determine the type of
    browser we want, then launch the browser before executing the tests.
    """
    env = BrowserEnv()

    if env.run_on_saucelabs:
        world.browser = make_sauce_browser(env)
        env.session_id = world.browser.driver.session_id

        # As part of the post build activities, the Sauce plugin will parse the test result files.
        # It attempts to identify lines in the stdout or stderr that are in the following format:
        # SauceOnDemandSessionID=<some session id> job-name=<some job name>
        # so we need to output this to the console for jenkins to pick up.
        print 'SauceOnDemandSessionID={} job-name={}'.format(env.session_id, env.job_name)

    elif env.selenium_host and env.selenium_port:
        world.browser = make_remote_browser(env)

    else:
        world.browser = make_local_browser(env)

    world.browser.driver.implicitly_wait(30)

    # Absorb the contents of the env object into world
    # so it can be accessed later in the teardown.
    world.absorb(env, 'env')
Ejemplo n.º 3
0
def initial_setup(server):
    """
    Launch the browser once before executing the tests.
    """
    world.absorb(settings.LETTUCE_SELENIUM_CLIENT, 'LETTUCE_SELENIUM_CLIENT')

    if world.LETTUCE_SELENIUM_CLIENT == 'local':
        browser_driver = getattr(settings, 'LETTUCE_BROWSER', 'chrome')

        # 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:
            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:
                world.browser.quit()
                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 {driver} browser session.".format(driver=browser_driver))

        world.absorb(0, 'IMPLICIT_WAIT')
        world.browser.driver.set_window_size(1280, 1024)

    elif world.LETTUCE_SELENIUM_CLIENT == 'saucelabs':
        config = get_saucelabs_username_and_key()
        world.browser = Browser(
            'remote',
            url="http://{}:{}@ondemand.saucelabs.com:80/wd/hub".format(config['username'], config['access-key']),
            **make_saucelabs_desired_capabilities()
        )
        world.absorb(30, 'IMPLICIT_WAIT')

    elif world.LETTUCE_SELENIUM_CLIENT == 'grid':
        world.browser = Browser(
            'remote',
            url=settings.SELENIUM_GRID.get('URL'),
            browser=settings.SELENIUM_GRID.get('BROWSER'),
        )
        world.absorb(30, 'IMPLICIT_WAIT')

    else:
        raise Exception("Unknown selenium client '{}'".format(world.LETTUCE_SELENIUM_CLIENT))

    world.browser.driver.implicitly_wait(world.IMPLICIT_WAIT)
    world.absorb(world.browser.driver.session_id, 'jobid')
Ejemplo n.º 4
0
def reset_data(scenario):
    """
    Clean out the django test database defined in the
    envs/acceptance.py file: edx-platform/db/test_edx.db
    """
    LOGGER.debug("Flushing the test database...")
    call_command('flush', interactive=False, verbosity=0)
    world.absorb({}, 'scenario_dict')
Ejemplo n.º 5
0
def reset_data(scenario):
    """
    Clean out the django test database defined in the
    envs/acceptance.py file: edx-platform/db/test_edx.db
    """
    LOGGER.debug("Flushing the test database...")
    call_command('flush', interactive=False, verbosity=0)
    world.absorb({}, 'scenario_dict')
Ejemplo n.º 6
0
def hook_store_augmented_step_name(step):
    """
    Get a more meaningful step name that can be used in reporting
    while this step runs.
    """
    config = world.fattoush
    world.absorb("[{0}] {1}".format(config.name, step.sentence),
                 "step_name")
Ejemplo n.º 7
0
def reset_data(scenario):
    """
    Clean out the django test database defined in the
    envs/acceptance.py file: mitx_all/db/test_mitx.db
    """
    LOGGER.debug("Flushing the test database...")
    call_command("flush", interactive=False)
    world.absorb({}, "scenario_dict")
Ejemplo n.º 8
0
def initial_setup(server):
    """
    Launch the browser once before executing the tests.
    """
    world.absorb(settings.SAUCE.get('SAUCE_ENABLED'), 'SAUCE_ENABLED')

    if not world.SAUCE_ENABLED:
        browser_driver = getattr(settings, 'LETTUCE_BROWSER', 'chrome')

        # 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:
            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:
                world.browser.quit()
                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 {driver} browser session.".format(
                    driver=browser_driver))

        world.browser.driver.set_window_size(1280, 1024)

    else:
        config = get_username_and_key()
        world.browser = Browser(
            'remote',
            url="http://{}:{}@ondemand.saucelabs.com:80/wd/hub".format(
                config['username'], config['access-key']),
            **make_desired_capabilities())
        world.browser.driver.implicitly_wait(30)

    world.absorb(world.browser.driver.session_id, 'jobid')
Ejemplo n.º 9
0
def initial_setup(server):
    """
    Launch the browser once before executing the tests.
    """
    world.absorb(settings.SAUCE.get("SAUCE_ENABLED"), "SAUCE_ENABLED")

    if not world.SAUCE_ENABLED:
        browser_driver = getattr(settings, "LETTUCE_BROWSER", "chrome")

        # 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:
            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:
                world.browser.quit()
                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 {driver} browser session.".format(driver=browser_driver))

        world.browser.driver.set_window_size(1280, 1024)

    else:
        config = get_username_and_key()
        world.browser = Browser(
            "remote",
            url="http://{}:{}@ondemand.saucelabs.com:80/wd/hub".format(config["username"], config["access-key"]),
            **make_desired_capabilities()
        )
        world.browser.driver.implicitly_wait(30)

    world.absorb(world.browser.driver.session_id, "jobid")
Ejemplo n.º 10
0
def run_single(index, browser, server, lettuce):
    """
    :param index: int
    :param browser: dict
    :param server: dict
    :param lettuce: dict
    """

    fattoush_config = FattoushConfig(index=index,
                                     browser=browser,
                                     server=server,
                                     lettuce=lettuce)
    world.absorb(fattoush_config, 'fattoush')
    try:
        result = fattoush_config.run()
        return result
    finally:
        world.spew('fattoush')
Ejemplo n.º 11
0
def initial_setup(server):
    """
    Launch the browser once before executing the tests.
    """
    world.absorb(settings.LETTUCE_SELENIUM_CLIENT, 'LETTUCE_SELENIUM_CLIENT')

    if world.LETTUCE_SELENIUM_CLIENT == 'local':
        browser_driver = getattr(settings, 'LETTUCE_BROWSER', 'chrome')

        if browser_driver == 'chrome':
            desired_capabilities = DesiredCapabilities.CHROME
            desired_capabilities['loggingPrefs'] = {
                'browser': 'ALL',
            }
        elif browser_driver == 'firefox':
            desired_capabilities = DesiredCapabilities.FIREFOX
        else:
            desired_capabilities = {}

        # 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:

            # Load the browser and try to visit the main page
            # If the browser couldn't be reached or
            # the browser session is invalid, this will
            # raise a WebDriverException
            try:
                world.browser = Browser(
                    browser_driver, desired_capabilities=desired_capabilities)
                world.browser.driver.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)
                world.visit('/')

            except WebDriverException:
                if hasattr(world, 'browser'):
                    world.browser.quit()
                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 {driver} browser session.".format(
                    driver=browser_driver))

        world.absorb(0, 'IMPLICIT_WAIT')
        world.browser.driver.set_window_size(1280, 1024)

    elif world.LETTUCE_SELENIUM_CLIENT == 'saucelabs':
        config = get_saucelabs_username_and_key()
        world.browser = Browser(
            'remote',
            url="http://{}:{}@ondemand.saucelabs.com:80/wd/hub".format(
                config['username'], config['access-key']),
            **make_saucelabs_desired_capabilities())
        world.absorb(30, 'IMPLICIT_WAIT')
        world.browser.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)

    elif world.LETTUCE_SELENIUM_CLIENT == 'grid':
        world.browser = Browser(
            'remote',
            url=settings.SELENIUM_GRID.get('URL'),
            browser=settings.SELENIUM_GRID.get('BROWSER'),
        )
        world.absorb(30, 'IMPLICIT_WAIT')
        world.browser.driver.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)

    else:
        raise Exception("Unknown selenium client '{}'".format(
            world.LETTUCE_SELENIUM_CLIENT))

    world.browser.driver.implicitly_wait(world.IMPLICIT_WAIT)
    world.absorb(world.browser.driver.session_id, 'jobid')
Ejemplo n.º 12
0
'''
Factories are defined in other modules and absorbed here into the
lettuce world so that they can be used by both unit tests
and integration / BDD tests.
'''
import student.tests.factories as sf
import xmodule.modulestore.tests.factories as xf
import course_modes.tests.factories as cmf
from lettuce import world

# Unlock XBlock factories, because we're randomizing the collection
# name above to prevent collisions
xf.XMODULE_FACTORY_LOCK.enable()

world.absorb(sf.UserFactory)
world.absorb(sf.UserProfileFactory)
world.absorb(sf.RegistrationFactory)
world.absorb(sf.GroupFactory)
world.absorb(sf.CourseEnrollmentAllowedFactory)
world.absorb(cmf.CourseModeFactory)
world.absorb(xf.CourseFactory)
world.absorb(xf.ItemFactory)
Ejemplo n.º 13
0
def absorb_factories():
    """
    Absorb the factories and return the resulting ``world`` object.
    """
    import course_modes.tests.factories as cmf
    import student.tests.factories as sf
    import xmodule.modulestore.tests.factories as xf

    # Unlock XBlock factories, because we're randomizing the collection
    # name above to prevent collisions
    xf.XMODULE_FACTORY_LOCK.enable()

    world.absorb(sf.UserFactory)
    world.absorb(sf.UserProfileFactory)
    world.absorb(sf.RegistrationFactory)
    world.absorb(sf.GroupFactory)
    world.absorb(sf.CourseEnrollmentAllowedFactory)
    world.absorb(cmf.CourseModeFactory)
    world.absorb(xf.CourseFactory)
    world.absorb(xf.ItemFactory)

    return world
Ejemplo n.º 14
0
def initial_setup(server):
    """
    Launch the browser once before executing the tests.
    """
    world.absorb(settings.LETTUCE_SELENIUM_CLIENT, 'LETTUCE_SELENIUM_CLIENT')

    if world.LETTUCE_SELENIUM_CLIENT == 'local':
        browser_driver = getattr(settings, 'LETTUCE_BROWSER', 'chrome')

        if browser_driver == 'chrome':
            desired_capabilities = DesiredCapabilities.CHROME
            desired_capabilities['loggingPrefs'] = {
                'browser': 'ALL',
            }
        else:
            desired_capabilities = {}

        # 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:

            # Load the browser and try to visit the main page
            # If the browser couldn't be reached or
            # the browser session is invalid, this will
            # raise a WebDriverException
            try:
                if browser_driver == 'firefox':
                    # Lettuce initializes differently for firefox, and sending
                    # desired_capabilities will not work. So initialize without
                    # sending desired_capabilities.
                    world.browser = Browser(browser_driver)
                else:
                    world.browser = Browser(browser_driver, desired_capabilities=desired_capabilities)
                world.browser.driver.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)
                world.visit('/')

            except WebDriverException:
                LOGGER.warn("Error acquiring %s browser, retrying", browser_driver, exc_info=True)
                if hasattr(world, 'browser'):
                    world.browser.quit()
                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 {driver} browser session.".format(driver=browser_driver))

        world.absorb(0, 'IMPLICIT_WAIT')
        world.browser.driver.set_window_size(1280, 1024)

    elif world.LETTUCE_SELENIUM_CLIENT == 'saucelabs':
        config = get_saucelabs_username_and_key()
        world.browser = Browser(
            'remote',
            url="http://{}:{}@ondemand.saucelabs.com:80/wd/hub".format(config['username'], config['access-key']),
            **make_saucelabs_desired_capabilities()
        )
        world.absorb(30, 'IMPLICIT_WAIT')
        world.browser.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)

    elif world.LETTUCE_SELENIUM_CLIENT == 'grid':
        world.browser = Browser(
            'remote',
            url=settings.SELENIUM_GRID.get('URL'),
            browser=settings.SELENIUM_GRID.get('BROWSER'),
        )
        world.absorb(30, 'IMPLICIT_WAIT')
        world.browser.driver.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)

    else:
        raise Exception("Unknown selenium client '{}'".format(world.LETTUCE_SELENIUM_CLIENT))

    world.browser.driver.implicitly_wait(world.IMPLICIT_WAIT)
    world.absorb(world.browser.driver.session_id, 'jobid')
Ejemplo n.º 15
0
            def setup(scenario):
                    ...

            Please use 'this_feature_only' name for readability.

    Can be used with:
            @before.each_scenario
            @after.each_scenario
            @before.each_feature
            @after.each_feature
    """

    def __init__(self, feature):
        self.feature = feature

    def __call__(self, f):
        def wrapper(arg):
            if isinstance(arg, Scenario):
                feature_name = arg.feature.name
            elif isinstance(arg, Feature):
                feature_name = arg.name
            else:
                raise Exception("this_feature_only is supposed to decorate only "
                                                "before/after each feature/scenario functions that"
                                                " accept one argument of type Feature or Scenario")
            if feature_name == self.feature:
                return f(arg)
        return wrapper

world.absorb(ThisFeatureOnly)
Ejemplo n.º 16
0
def reset_data(scenario):
    """
    Initialize the dict of scenario variables
    """
    world.absorb({}, 'scenario_dict')