Exemplo n.º 1
0
def setup_browser(browser, url=None, **capabilities):
    browser = os.environ.get('LETTUCE_BROWSER', browser)
    logger.info("Setting up browser %s..." % browser)

    try:
        if url:
            logger.warn(capabilities)
        # support sauce config via SELENIUM_DRIVER
        # to support use via Jenkins Sauce plugin
        is_sauce = 'SELENIUM_DRIVER' in os.environ
        if is_sauce:
            driver_info = dict(
                [v.split('=', 2)
                for v in os.environ['SELENIUM_DRIVER'].split('?')[1].split('&')
            ])
            logger.info('Sauce configuration detected')
            desired_capabilities = {}
            desired_capabilities['browserName'] = driver_info['browser']
            desired_capabilities['version'] = driver_info['browser-version']
            desired_capabilities['platform'] = driver_info['os']
            url = "http://%s:%s@%s:%s/wd/hub" % (
                driver_info['username'], driver_info['access-key'],
                os.environ.get('SELENIUM_HOST', 'ondemand.saucelabs.com'),
                os.environ.get('SELENIUM_PORT', 80))
            browser = Browser('remote', url=url, **desired_capabilities)
        elif url:
            browser = Browser('remote', url=url,
                    browser=browser, **capabilities)
        else:
            browser = Browser(browser)
    except Exception as e:
        logger.warn("Error starting up %s: %s" % (browser, e))
        raise
    return browser
Exemplo n.º 2
0
def teardown_browser(browser):
    name = browser.driver_name
    logger.info("Tearing down browser %s..." % name)
    try:
        browser.quit()
    except Exception as e:
        logger.warn("Error tearing down %s: %s" % (name, e))
Exemplo n.º 3
0
def _get_element(finder_function,
                 first,
                 last,
                 pattern,
                 expect_not_to_find=False,
                 leave_in_list=False):

    ele = world.browser.__getattribute__(finder_function)(pattern)

    try:
        if first:
            ele = ele.first
        if last:
            ele = ele.last

        if not "WebDriverElement" in "%s" % type(ele):
            if len(ele) > 1:
                logger.warn(
                    "More than one element found when looking for %s for %s.  Using the first one. "
                    % (finder_function, pattern))

            if not leave_in_list:
                ele = ele.first

    except ElementDoesNotExist:
        if not expect_not_to_find:
            logger.error("Element not found: %s for %s" %
                         (finder_function, pattern))
        raise ElementDoesNotExist

    world.current_element = ele
    return ele
Exemplo n.º 4
0
def teardown_browser(browser):
    name = browser.driver_name
    logger.info("Tearing down browser %s..." % name)
    try:
        browser.quit()
    except Exception as e:
        logger.warn("Error tearing down %s: %s" % (name, e))
Exemplo n.º 5
0
def setup_browser(browser, url=None):
    logger.info("Setting up browser %s..." % browser)
    try:
        if url:
            browser = Browser('remote', url=url, browser=browser)
        else:
            browser = Browser(browser)
    except Exception as e:
        logger.warn("Error starting up %s: %s" % (browser, e))
        raise
    return browser
Exemplo n.º 6
0
def setup_browser(browser, url=None):
    logger.info("Setting up browser %s..." % browser)
    try:
        if url:
            browser = Browser('remote', url=url,
                    browser=browser)
        else:
            browser = Browser(browser)
    except Exception as e:
        logger.warn("Error starting up %s: %s" % (browser, e))
        raise
    return browser
Exemplo n.º 7
0
def _get_element(finder_function, pick, pattern):
    ele = world.browser.__getattribute__(finder_function)(pattern)

    index = pick_to_index(pick)
    ele = ele[index]

    if not "WebDriverElement" in "%s" % type(ele):
        if len(ele) > 1:
            logger.warn("More than one element found when looking with %s "
                        "for %s.  Using the first one. " %
                        (finder_function, pattern))
        ele = ele.first

    world.current_element = ele
    return ele
Exemplo n.º 8
0
def _get_element(finder_function, pick, pattern):
    ele = world.browser.__getattribute__(finder_function)(pattern)

    index = pick_to_index(pick)
    ele = ele[index]

    if not "WebDriverElement" in "%s" % type(ele):
        if len(ele) > 1:
            logger.warn("More than one element found when looking with %s "
                        "for %s.  Using the first one. " %
                        (finder_function, pattern))
        ele = ele.first

    world.current_element = ele
    return ele
Exemplo n.º 9
0
    def get_element(self, element_name):
        func_name = 'get_' + element_name
        try:
            func = getattr(self, func_name)
        # check if function exists
        except AttributeError:
            return None

        # TODO: make sure function doesn't throw an error
        element = func()

        # make sure element is not null
        if element is None:
            logger.warn(' %s element could not be found in page %s' % (element_name, self.__class__.__name__))

        return element
Exemplo n.º 10
0
def _get_element(finder_function, first, last, pattern, expect_not_to_find=False, leave_in_list=False):

    ele = world.browser.__getattribute__(finder_function)(pattern)

    try:
        if first:
            ele = ele.first
        if last:
            ele = ele.last

        if not "WebDriverElement" in "%s" % type(ele):
            if len(ele) > 1:
                logger.warn("More than one element found when looking for %s for %s.  Using the first one. " % (finder_function, pattern))

            if not leave_in_list:
                ele = ele.first

    except ElementDoesNotExist:
            if not expect_not_to_find:
                logger.error("Element not found: %s for %s" % (finder_function, pattern))
            raise ElementDoesNotExist

    world.current_element = ele
    return ele
Exemplo n.º 11
0
def teardown_browser(total):
    logger.info("Tearing down chrome...")
    try:
        world.chrome.quit()
    except:
        logger.warn("Error tearing down chrome.")
Exemplo n.º 12
0
def teardown_browser(total):
    logger.info("Tearing down browser...")
    try:
        world.zope.quit()
    except:
        logger.warn("Error tearing down zope")
Exemplo n.º 13
0
def setup_browser():
    logger.info("Setting up zope...")
    try:
        world.zope = Browser("zope.testbrowser")
    except:
        logger.warn("Error starting up zope")
Exemplo n.º 14
0
from lettuce import step, world
from salad.logger import logger

try:
    from lettuce.django import django_url

    @step(r'(?:visit|access|open) the django url "(.*)"')
    def go_to_the_url(step, url):
        world.response = world.browser.visit(django_url(url))
except:
    logger.warn("Django steps not imported.")
Exemplo n.º 15
0
def setup_browser():
    logger.info("Setting up firefox...")
    try:
        world.firefox = Browser("firefox")
    except:
        logger.warn("Error starting up firefox")
Exemplo n.º 16
0
def teardown_browser(total):
    logger.info("Tearing down firefox...")
    try:
        world.firefox.quit()
    except:
        logger.warn("Error tearing down firefox")
Exemplo n.º 17
0
from lettuce import step, world
from salad.logger import logger

try:
    from lettuce.django import django_url

    @step(r'(?:visit|access|open) the django url "(.*)"')
    def go_to_the_url(step, url):
        world.response = world.browser.visit(django_url(url))
except:
    try:
        # Only complain if it seems likely that using django was intended.
        import django
        logger.warn("Django steps not imported.")
    except:
        pass
Exemplo n.º 18
0
            database_name = settings.DATABASES["default"]["NAME"]
            cursor = connection.cursor()
            cursor.execute("DROP DATABASE %s" % database_name)
            cursor.execute("CREATE DATABASE %s" % database_name)
            connection.close()
        else:
            # connection.settings_dict["NAME"] = ":memory:"
            pass

        if USE_SOUTH:
            patch_for_test_db_setup()

        world.test_runner = DjangoTestSuiteRunner(interactive=False)
        world.test_runner.setup_test_environment()

        call_command('syncdb', interactive=False, verbosity=0)
        call_command('flush', interactive=False, verbosity=0)

    @after.all
    def teardown_database(total):
        logger.info("Destroying test database ...\n")
        world.test_runner.teardown_test_environment()

    @after.each_feature
    def reset_data(scenario):
        logger.info("Flushing...")
        call_command('flush', interactive=False, verbosity=0)

except:
    logger.warn("Django terrains not imported.")
Exemplo n.º 19
0
def setup_browser():
    logger.info("Setting up chrome...")
    try:
        world.chrome = Browser("chrome")
    except Exception, e:
        logger.warn("Error starting up chrome: %s" % e)