Beispiel #1
0
def before_scenario(context, scenario):
    """Launch browser and open application
    :param context: Holds contextual information during the running of tests
    :param scenario: Holds contextual information about scenario during the running of tests
    :return: None
    """
    loggerutils.setup_unformatted_logging(context)

    context.logger.info("\n")
    context.logger.info(
        "---------------------------------------------------------------------------------------------"
    )
    context.logger.info("STARTED EXECUTION OF SCENARIO: " + str(scenario.name))
    context.logger.info("Tags: " + str([str(item) for item in scenario.tags]))
    context.logger.info("Filename: " + str(scenario.filename))
    context.logger.info("Line: " + str(scenario.line))
    context.logger.info(
        "---------------------------------------------------------------------------------------------"
    )

    loggerutils.setup_formatted_logging(context)

    context.logger.info("Opening application url '" + context.application_url +
                        "'")
    context.driver.get(context.application_url)
    context.driver.maximize_window()

    context.elementaction = ElementAction(context)
Beispiel #2
0
def after_all(context):
    """Log test finished
    :param context: Holds contextual information during the running of tests
    :return: None
    """
    loggerutils.setup_unformatted_logging(context)

    context.logger.info("\n")
    context.logger.info(
        "============================================================================================="
    )
    context.logger.info("TESTING FINISHED AT : " +
                        strftime("%Y-%m-%d %H:%M:%S"))
    context.logger.info(
        "============================================================================================="
    )
    context.logger.info("\n")

    loggerutils.setup_formatted_logging(context)
Beispiel #3
0
def before_feature(context, feature):
    """Log starting of execution of feature
   :param context: Holds contextual information during the running of tests
   :param feature: Holds contextual information about the feature during the running of tests
   :return: None
   """
    loggerutils.setup_unformatted_logging(context)

    context.logger.info("\n")
    context.logger.info(
        "---------------------------------------------------------------------------------------------"
    )
    context.logger.info("STARTED EXECUTION OF FEATURE: " + str(feature.name))
    context.logger.info("Tags: " + str([str(item) for item in feature.tags]))
    context.logger.info("Filename: " + str(feature.filename))
    context.logger.info("Line: " + str(feature.line))
    context.logger.info(
        "---------------------------------------------------------------------------------------------"
    )

    loggerutils.setup_formatted_logging(context)
Beispiel #4
0
def after_scenario(context, scenario):
    """Close browser and quit driver
    :param context: Holds contextual information during the running of tests
    :param scenario: Holds contextual information about scenario during the running of tests
    :return: None
    """
    loggerutils.setup_unformatted_logging(context)

    context.logger.info("\n")
    context.logger.info(
        "---------------------------------------------------------------------------------------------"
    )
    context.logger.info("FINISHED EXECUTION OF SCENARIO: " +
                        str(scenario.name))
    context.logger.info("Result: " + scenario.status.upper())
    context.logger.info("Time taken: " +
                        str("{0:.2f}".format(scenario.duration / 60)) +
                        " mins, " +
                        str("{0:.2f}".format(scenario.duration % 60)) +
                        " secs")
    context.logger.info(
        "---------------------------------------------------------------------------------------------"
    )

    loggerutils.setup_formatted_logging(context)

    if context.driver is not None:
        try:
            context.driver.close()
        except Exception as e:
            context.logger.error("Unable to close browser window! Error: %s" %
                                 e,
                                 exc_info=True)

        try:
            context.driver.quit()
        except Exception as e:
            context.logger.error("Unable to quit driver! Error: %s" % e,
                                 exc_info=True)
Beispiel #5
0
def after_feature(context, feature):
    """Log finished execution of feature
    :param context: Holds contextual information during the running of tests
    :param feature: Holds contextual information about feature during the running of tests
    :return: None
    """
    loggerutils.setup_unformatted_logging(context)

    context.logger.info("\n")
    context.logger.info(
        "---------------------------------------------------------------------------------------------"
    )
    context.logger.info("FINISHED EXECUTION OF FEATURE: " + str(feature.name))
    context.logger.info("Result: " + feature.status.upper())
    context.logger.info("Time taken: " +
                        str("{0:.2f}".format(feature.duration / 60)) +
                        " mins, " +
                        str("{0:.2f}".format(feature.duration % 60)) + " secs")
    context.logger.info(
        "---------------------------------------------------------------------------------------------"
    )

    loggerutils.setup_formatted_logging(context)
Beispiel #6
0
def before_all(context):
    """Set up test environment
    Create driver based on the desired capabilities provided.
    Valid desired capabilities can be 'firefox', 'chrome' or 'ie'.
    For adding new drivers add a new static method in DriverFactory class.

    :param context: Holds contextual information during the running of tests
    :return: None
    """
    context.config = None

    with open(os.getcwd() + os.path.sep + "config.yml", 'r') as ymlfile:
        context.config = yaml.load(ymlfile)

    loggerutils.setup_logging()

    loggerutils.setup_formatted_logging(context)

    # Delete log files older than the days specified in config file
    now = time.time()
    number_of_days_to_keep_log_files = int(
        context.config['env']['number_of_days_to_keep_log_files'])

    try:
        for f in os.listdir('logs'):
            if os.stat(
                    os.path.join('logs', f)
            ).st_mtime < now - number_of_days_to_keep_log_files * 86400:
                os.remove(os.path.join('logs', f))
    except Exception as e:
        context.logger.error("Unable to delete old log files! Error: %s" % e)

    # Delete old screenshots directory, junit xml reports before running the tests
    try:
        map(
            os.remove,
            glob.glob(os.getcwd() + os.path.sep + "screenshots" + os.path.sep +
                      "*.png"))
        context.logger.info("Deleted old screenshot files")
    except Exception as e:
        context.logger.error(
            "Unable to delete old screenshot files! Error: %s" % e)

    try:
        map(
            os.remove,
            glob.glob(os.getcwd() + os.path.sep + "reports" + os.path.sep +
                      "*.xml"))
        context.logger.info("Deleted old xml report files")
    except Exception as e:
        context.logger.error("Unable to delete xml report files! Error: %s" %
                             e)

    context.test_started_milli_time = int(round(time.time() * 1000))

    loggerutils.setup_unformatted_logging(context)

    context.logger.info("\n")
    context.logger.info(
        "============================================================================================="
    )
    context.logger.info("TESTING STARTED AT : " +
                        strftime("%Y-%m-%d %H:%M:%S"))
    context.logger.info(
        "============================================================================================="
    )
    context.logger.info("\n")

    loggerutils.setup_formatted_logging(context)

    context.browser = context.config['env']['browser']

    # Get the appropriate driver for the browser specified in config file
    driver_factory = SeleniumDriverFactory(context.browser)

    context.driver = driver_factory.get_driver()

    # Set driver implicit timeout. Webdriver will keep polling for the element for the specified timeout
    # period.
    timeout = context.config['env']['implicit_timeout']

    context.driver.implicitly_wait(timeout)
    context.logger.info("Driver implicit timeout is set to '" + str(timeout) +
                        "' seconds")

    context.application_url = context.config['env']['application_url']
    context.username = context.config['env']['username']
    context.password = context.config['env']['password']

    context.passed_scenarios = []
    context.failed_scenarios = []
    context.skipped_scenarios = []