Skip to content

Commit c93ec22

Browse files
committed
Merge pull request pytest-dev#19 from oisinmulvihill/master
selecting the browser to use from SELENIUM_BROWSER env var.
2 parents c090592 + 9e36b7d commit c93ec22

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

pkglib/testing/pytest/webdriver.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@
33
import pytest
44
import py.builtin
55

6+
from pkglib import CONFIG
7+
8+
9+
def browser_to_use(webdriver, browser):
10+
"""Recover the browser to use with the given webdriver instance.
11+
12+
The browser string is case insensitive and needs to be one of the values
13+
from BROWSERS_CFG.
14+
15+
"""
16+
browser = browser.strip().upper()
17+
18+
# Have a look the following to see list of supported browsers:
19+
#
20+
# http://selenium.googlecode.com/git/docs/api/
21+
# py/_modules/selenium/webdriver/common/desired_capabilities.html
22+
#
23+
b = getattr(webdriver.DesiredCapabilities(), browser, None)
24+
if not b:
25+
raise ValueError(
26+
"Unknown browser requested '{}'.".format(browser)
27+
)
28+
29+
#print "{}\n\nbrowser: {}\n\n{}".format('-'*80, browser, '-'*80)
30+
31+
return b
32+
633

734
def pytest_funcarg__webdriver(request):
835
""" Connects to a remote selenium webdriver and returns the browser handle.
@@ -41,8 +68,14 @@ def test_mywebpage(webdriver):
4168
pass
4269

4370
def setup():
44-
res = webdriver.Remote('http://%s:%s' % (os.environ["SELENIUM_HOST"], os.environ['SELENIUM_PORT']),
45-
webdriver.DesiredCapabilities().CHROME)
71+
browser = os.environ.get('SELENIUM_BROWSER', 'chrome')
72+
res = webdriver.Remote(
73+
'http://%s:%s' % (
74+
os.environ["SELENIUM_HOST"],
75+
os.environ['SELENIUM_PORT']
76+
),
77+
browser_to_use(webdriver, browser)
78+
)
4679
if root_uri:
4780
res.__dict__['root_uri'] = root_uri[0]
4881
return res

pkglib/testing/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,4 @@ def check_server_up(self):
258258
return True
259259
except URLError, e:
260260
print "Server not up yet (%s).." % e
261-
return False
261+
return False

0 commit comments

Comments
 (0)