from __future__ import print_function

import os
from contextlib import contextmanager

from selenium import webdriver

from aloe import around, world

here = os.path.dirname(__file__)
html_pages = os.path.join(here, 'html_pages')


@around.each_feature
@contextmanager
def with_browser(feature):
    world.browser = webdriver.Firefox()
    world.browser.get('')
    yield
    world.browser.quit()
    delattr(world, 'browser')


@around.each_step
@contextmanager
def print_source(step):
    try:
        yield
    except:
        print(world.browser.page_source)
        print(world.browser.get_screenshot_as_base64())
        raise

from __future__ import print_function

import os
from contextlib import contextmanager

from selenium import webdriver

from aloe import around, world

here = os.path.dirname(__file__)
html_pages = os.path.join(here, 'html_pages')


@around.each_feature
@contextmanager
def with_browser(feature):
    world.browser = webdriver.Firefox()
    world.browser.get('')
    yield
    world.browser.quit()
    delattr(world, 'browser')


@around.each_step
@contextmanager
def print_source(step):
    try:
        yield
    except:
        try:
            step_container = step.scenario
        except AttributeError:
            step_container = step.background

        print(step_container.feature.name)
        print(step_container.name)
        print(step.sentence)
        print(world.browser.page_source)
        print(world.browser.get_screenshot_as_base64())
        raise

Print scenario/step names on failure
Print scenario/step names on failure
