Total Complexity | 9 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 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 |
||
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 | context.get_browser = get_browser |
||
25 | |||
26 | # Remote URL for smoke testing |
||
27 | context.remote_url = os.environ.get('REMOTE_URL', 'http://localhost:5000') |
||
28 | |||
29 | |||
30 | def _debug(): |
||
31 | """Returns a bool indicating whether debug mode is on.""" |
||
32 | return os.environ.get('BEHAVE_PDB') |
||
33 | |||
34 | |||
35 | def after_step(context, step): |
||
36 | if _debug() and step.status == 'failed': |
||
37 | pdb.post_mortem(step.exc_traceback) |
||
38 | |||
39 | |||
40 | def after_scenario(context, scenario): |
||
41 | try: |
||
42 | context.browser.quit() |
||
43 | del context.browser |
||
44 | except AttributeError: |
||
45 | pass |
||
46 |