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))
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." )
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
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." )
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
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
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
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
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)
def empty_outbox(scenario): logger.info("Emptying outbox...") mail.outbox = []
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)
def reset_data(scenario): logger.info("Flushing...") call_command('flush', interactive=False, verbosity=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
def setup_browser(): logger.info("Setting up firefox...") try: world.firefox = Browser("firefox") except: logger.warn("Error starting up firefox")
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.")
def setup_browser(): logger.info("Setting up zope...") try: world.zope = Browser("zope.testbrowser") except: logger.warn("Error starting up zope")
def teardown_browser(total): logger.info("Tearing down browser...") try: world.zope.quit() except: logger.warn("Error tearing down zope")
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.")
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.")
def teardown_browser(total): logger.info("Tearing down firefox...") try: world.firefox.quit() except: logger.warn("Error tearing down firefox")
def setup_browser(): logger.info("Setting up chrome...") try: world.chrome = Browser("chrome") except Exception, e: logger.warn("Error starting up chrome: %s" % e)
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.")
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 = []
def teardown_database(total): logger.info("Destroying test database ...\n") world.test_runner.teardown_test_environment()
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.")
def teardown_browser(total): logger.info("Tearing down chrome...") try: world.chrome.quit() except: logger.warn("Error tearing down chrome.")