Passed
Push — master ( 19142d...b8daaf )
by Joe
01:31
created

environment.after_scenario()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
import os
2
import pdb
3
4
from selenium import webdriver
5
from splinter import Browser
6
7
8
def before_all(context):
9
    def get_browser():
10
        """Only create a browser if we need it."""
11
        try:
12
            browser = context.browser
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable context does not seem to be defined.
Loading history...
13
        except AttributeError:
14
            options = webdriver.ChromeOptions()
15
16
            # Disable the sandbox and run in headless mode when running in CI
17
            if os.environ.get('CI'):
18
                options.add_argument('--headless')
19
                options.add_argument('--no-sandbox')
20
21
            browser = context.browser = Browser('chrome', options=options)
22
23
        return browser
24
25
    context.remote_url = os.environ.get('REMOTE_URL', 'http://localhost:5000')
26
    context.get_browser = get_browser
27
28
29
def _debug():
30
    """Returns a bool indicating whether debug mode is on."""
31
    return os.environ.get('BEHAVE_PDB')
32
33
34
def after_step(context, step):
35
    if _debug() and step.status == 'failed':
36
        pdb.post_mortem(step.exc_traceback)
37
38
39
def after_scenario(context, scenario):
40
    try:
41
        context.browser.quit()
42
        del context.browser
43
    except AttributeError:
44
        pass
45