Beispiel #1
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))
Beispiel #2
0
def run_the_javascript(step, script):
    try:
        world.browser.execute_script(script)
    except NotImplementedError:
        logger.info(
            "Attempted to run javascript in a javascript-disabled browser. Moving along."
        )
Beispiel #3
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
Beispiel #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))
Beispiel #5
0
def evaluate_the_javascript(step, negate, script, value):
    try:
        assert_equals_with_negate("%s" % world.browser.evaluate_script(script),
                                  value, negate)
    except NotImplementedError:
        logger.info(
            "Attempted to run javascript in a javascript-disabled browser. Moving along."
        )
Beispiel #6
0
    def assert_javascript_returns_value(negate, script, value):
        try:
            assert_equals_with_negate(
                "%s" % world.browser.evaluate_script(script), value, negate)
        except NotImplementedError:
            logger.info("Attempted to run javascript in a javascript-disabled"
                        "browser. Moving along.")

        return True
Beispiel #7
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
Beispiel #8
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
Beispiel #9
0
def _get_alert_or_none():
    if "phantomjs" == world.browser.driver.name:
        logger.info("Attempted to use alerts in a browser that does not " "support alerts. Moving along.")
        raise NotImplementedError("phantomjs does not support alerts")

    try:
        alert = world.browser.driver.switch_to_alert()
        # switch_to_alert() always returns an object, but if there is no
        # alert, the following line will raise an exception
        alert.text
    except:
        alert = None
    return alert
Beispiel #10
0
def _get_alert_or_none():
    if 'phantomjs' == world.browser.driver.name:
        logger.info("Attempted to use alerts in a browser that does not "
                    "support alerts. Moving along.")
        raise NotImplementedError("phantomjs does not support alerts")

    try:
        alert = world.browser.driver.switch_to_alert()
        # switch_to_alert() always returns an object, but if there is no
        # alert, the following line will raise an exception
        alert.text
    except:
        alert = None
    return alert
Beispiel #11
0
    def setup_database():
        logger.info("Setting up a test database ...\n")

        if settings.DATABASES["default"]["ENGINE"] != "django.db.backends.sqlite3":
            from django.db import connection
            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)
Beispiel #12
0
 def empty_outbox(scenario):
     logger.info("Emptying outbox...")
     mail.outbox = []
Beispiel #13
0
 def reset_data(scenario):
     # Clean up django.
     logger.info("Flushing the test database...")
     call_command('flush', interactive=False, verbosity=0)
     call_command('loaddata', 'all', verbosity=0)
Beispiel #14
0
 def reset_data(scenario):
     logger.info("Flushing...")
     call_command('flush', interactive=False, verbosity=0)
Beispiel #15
0
from lettuce import before
from salad.logger import logger

logger.info("Loading the terrain file...")
try:
    from django.core import mail
    from django.core.management import call_command

    @before.each_scenario
    def reset_data(scenario):
        # Clean up django.
        logger.info("Flushing the test database...")
        call_command('flush', interactive=False, verbosity=0)
        call_command('loaddata', 'all', verbosity=0)

    @before.each_feature
    def empty_outbox(scenario):
        logger.info("Emptying outbox...")
        mail.outbox = []

except:
    try:
        # Only complain if it seems likely that using django was intended.
        import django
        logger.info("Django terrains not imported.")
    except:
        pass
Beispiel #16
0
def setup_browser():
    logger.info("Setting up firefox...")
    try:
        world.firefox = Browser("firefox")
    except:
        logger.warn("Error starting up firefox")
Beispiel #17
0
def run_the_javascript(step, script):
    try:
        world.browser.execute_script(script)
    except NotImplementedError:
        logger.info("Attempted to run javascript in a javascript-disabled browser. Moving along.")
Beispiel #18
0
def setup_browser():
    logger.info("Setting up zope...")
    try:
        world.zope = Browser("zope.testbrowser")
    except:
        logger.warn("Error starting up zope")
Beispiel #19
0
def teardown_browser(total):
    logger.info("Tearing down browser...")
    try:
        world.zope.quit()
    except:
        logger.warn("Error tearing down zope")
Beispiel #20
0
def scroll_to(step, selector):
    try:
        world.browser.execute_script('frappe.ui.scroll("{}");'.format(selector))
    except NotImplementedError:
        logger.info("Attemped to run javascript in javascript-disabled browser. Movin along.")
Beispiel #21
0
def ensure_that_setup_scenario_run_in_setup_wizard(scenario):
    if "Setup" in scenario.name and not "#setup-wizard" in world.browser.url:
        scenario.steps = []
        logger.info("Attemped to do the setup in a instance with the setup already done. Movin along.")
Beispiel #22
0
 def reset_data(scenario):
     # Clean up django.
     logger.info("Flushing the test database...")
     call_command('flush', interactive=False, verbosity=0)
     call_command('loaddata', 'all', verbosity=0)
Beispiel #23
0
def teardown_browser(total):
    logger.info("Tearing down firefox...")
    try:
        world.firefox.quit()
    except:
        logger.warn("Error tearing down firefox")
Beispiel #24
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)
Beispiel #25
0
 def empty_outbox(scenario):
     logger.info("Emptying outbox...")
     mail.outbox = []
Beispiel #26
0
def ensure_that_setup_scenario_run_in_setup_wizard(scenario):
    if 'Setup' in scenario.name and not '#setup-wizard' in world.browser.url:
        scenario.steps = []
        logger.info("Attemped to do the setup in a instance with the setup already done. Movin along.")
Beispiel #27
0
    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))

########NEW FILE########
__FILENAME__ = common

########NEW FILE########
__FILENAME__ = djangoify
from lettuce import before
from salad.logger import logger

logger.info("Loading the terrain file...")
try:
    from django.core import mail
    from django.core.management import call_command

    @before.each_scenario
    def reset_data(scenario):
        # Clean up django.
        logger.info("Flushing the test database...")
        call_command('flush', interactive=False, verbosity=0)
        call_command('loaddata', 'all', verbosity=0)

    @before.each_feature
    def empty_outbox(scenario):
        logger.info("Emptying outbox...")
        mail.outbox = []
Beispiel #28
0
 def teardown_database(total):
     logger.info("Destroying test database ...\n")
     world.test_runner.teardown_test_environment()
Beispiel #29
0
def scroll_to(step, selector):
    try:
        world.browser.execute_script('frappe.ui.scroll("{}");'.format(selector));
    except NotImplementedError:
        logger.info("Attemped to run javascript in javascript-disabled browser. Movin along.")
Beispiel #30
0
def teardown_browser(total):
    logger.info("Tearing down chrome...")
    try:
        world.chrome.quit()
    except:
        logger.warn("Error tearing down chrome.")