|
3 | 3 | import pytest
|
4 | 4 | import py.builtin
|
5 | 5 |
|
| 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 | + |
6 | 33 |
|
7 | 34 | def pytest_funcarg__webdriver(request):
|
8 | 35 | """ Connects to a remote selenium webdriver and returns the browser handle.
|
@@ -41,8 +68,14 @@ def test_mywebpage(webdriver):
|
41 | 68 | pass
|
42 | 69 |
|
43 | 70 | 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 | + ) |
46 | 79 | if root_uri:
|
47 | 80 | res.__dict__['root_uri'] = root_uri[0]
|
48 | 81 | return res
|
|
0 commit comments