Skip to content

Commit a536675

Browse files
committed
Add Opera Browser support
1 parent 2b33a71 commit a536675

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

help_docs/webdriver_installation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Here's where you can go to manually install web drivers from the source:
2121

2222
* For Safari, get [Safari Driver](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/using_safari_driver.md) on your System PATH.
2323

24+
* For Opera, get [Opera Chromium Driver](https://github.com/operasoftware/operachromiumdriver/releases) on your System PATH..
25+
2426
* For PhantomJS headless browser automation, get [PhantomJS](http://phantomjs.org/download.html) on your System PATH. (NOTE: <i>PhantomJS is no longer officially supported by SeleniumHQ</i>)
2527

2628
**Mac**:

seleniumbase/core/browser_launcher.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212
from seleniumbase.fixtures import page_utils
1313
import drivers # webdriver storage folder for SeleniumBase
1414
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
15+
PLATFORM = sys.platform
1516
LOCAL_CHROMEDRIVER = None
1617
LOCAL_GECKODRIVER = None
1718
LOCAL_EDGEDRIVER = None
18-
if "darwin" in sys.platform or "linux" in sys.platform:
19+
LOCAL_OPERADRIVER = None
20+
if "darwin" in PLATFORM or "linux" in PLATFORM:
1921
LOCAL_CHROMEDRIVER = DRIVER_DIR + '/chromedriver'
2022
LOCAL_GECKODRIVER = DRIVER_DIR + '/geckodriver'
21-
elif "win32" in sys.platform or "win64" in sys.platform:
23+
LOCAL_OPERADRIVER = DRIVER_DIR + '/operadriver'
24+
elif "win32" in PLATFORM or "win64" in PLATFORM or "x64" in PLATFORM:
2225
LOCAL_EDGEDRIVER = DRIVER_DIR + '/MicrosoftWebDriver.exe'
2326
LOCAL_CHROMEDRIVER = DRIVER_DIR + '/chromedriver.exe'
2427
LOCAL_GECKODRIVER = DRIVER_DIR + '/geckodriver.exe'
28+
LOCAL_OPERADRIVER = DRIVER_DIR + '/operadriver.exe'
2529
else:
2630
# Cannot determine system
2731
pass # SeleniumBase will use web drivers from the System PATH by default
@@ -217,6 +221,11 @@ def get_remote_driver(browser_name, headless, servername, port, proxy_string):
217221
command_executor=address,
218222
desired_capabilities=(
219223
webdriver.DesiredCapabilities.SAFARI))
224+
elif browser_name == constants.Browser.OPERA:
225+
return webdriver.Remote(
226+
command_executor=address,
227+
desired_capabilities=(
228+
webdriver.DesiredCapabilities.OPERA))
220229
elif browser_name == constants.Browser.PHANTOM_JS:
221230
with warnings.catch_warnings():
222231
# Ignore "PhantomJS has been deprecated" UserWarning
@@ -282,6 +291,12 @@ def get_local_driver(browser_name, headless, proxy_string):
282291
return webdriver.Edge(capabilities=edge_capabilities)
283292
elif browser_name == constants.Browser.SAFARI:
284293
return webdriver.Safari()
294+
elif browser_name == constants.Browser.OPERA:
295+
if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
296+
make_driver_executable_if_not(LOCAL_OPERADRIVER)
297+
return webdriver.Opera(executable_path=LOCAL_OPERADRIVER)
298+
else:
299+
return webdriver.Opera()
285300
elif browser_name == constants.Browser.PHANTOM_JS:
286301
with warnings.catch_warnings():
287302
# Ignore "PhantomJS has been deprecated" UserWarning

seleniumbase/fixtures/constants.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,37 @@ class Files:
1818

1919

2020
class ValidBrowsers:
21-
valid_browsers = ["firefox", "ie", "edge", "safari", "chrome", "phantomjs"]
21+
valid_browsers = (
22+
["chrome", "edge", "firefox", "ie", "opera", "phantomjs", "safari"])
2223

2324

2425
class Browser:
26+
GOOGLE_CHROME = "chrome"
27+
EDGE = "edge"
2528
FIREFOX = "firefox"
2629
INTERNET_EXPLORER = "ie"
27-
EDGE = "edge"
28-
SAFARI = "safari"
29-
GOOGLE_CHROME = "chrome"
30+
OPERA = "opera"
3031
PHANTOM_JS = "phantomjs"
32+
SAFARI = "safari"
3133

3234
VERSION = {
35+
"chrome": None,
36+
"edge": None,
3337
"firefox": None,
3438
"ie": None,
35-
"edge": None,
36-
"safari": None,
37-
"chrome": None,
38-
"phantomjs": None
39+
"opera": None,
40+
"phantomjs": None,
41+
"safari": None
3942
}
4043

4144
LATEST = {
45+
"chrome": None,
46+
"edge": None,
4247
"firefox": None,
4348
"ie": None,
44-
"edge": None,
45-
"safari": None,
46-
"chrome": None,
47-
"phantomjs": None
49+
"opera": None,
50+
"phantomjs": None,
51+
"safari": None
4852
}
4953

5054

0 commit comments

Comments
 (0)