Skip to content

Commit 0577713

Browse files
Jacob SchlatherAutomatedTester
authored andcommitted
Setup server constructor to look on path for location of browsermob-proxy executable. As well as looking for a file. Also added example code for using browsermob-proxy with chrome
1 parent 5ee9900 commit 0577713

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

browsermobproxy/server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class Server(object):
1111

12-
def __init__(self, path, options={}):
12+
def __init__(self, path = 'browsermob-proxy', options={}):
1313
"""
1414
Initialises a Server object
1515
@@ -19,11 +19,19 @@ def __init__(self, path, options={}):
1919
More items will be added in the future.
2020
This defaults to an empty dictionary
2121
"""
22+
path_var_sep = ':'
2223
if platform.system() == 'Windows':
24+
path_var_sep = ';'
2325
if not path.endswith('.bat'):
2426
path += '.bat'
2527

26-
if not os.path.isfile(path):
28+
exec_not_on_path = True
29+
for directory in os.environ['PATH'].split(path_var_sep):
30+
if(os.path.isfile(os.path.join(directory, path))):
31+
exec_not_on_path = False
32+
break
33+
34+
if not os.path.isfile(path) and exec_not_on_path:
2735
raise Exception("Browsermob-Proxy binary couldn't be found in path"
2836
" provided: %s" % path)
2937

readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ driver.quit()
3131

3232
```
3333

34+
for Chrome use
35+
36+
```
37+
chrome_options = webdriver.ChromeOptions()
38+
chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy))
39+
browser = webdriver.Chrome(chrome_options = chrome_options)
40+
```
41+
3442
Running Tests
3543
-------------
3644
To run the tests in a CI environment, disable the ones that require human

0 commit comments

Comments
 (0)