Skip to content

Make improvements to Opera Chromium automation #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ Tests are run with "pytest". Browsers are controlled by WebDriver.
* [<img src="https://img.shields.io/pypi/pyversions/seleniumbase.svg?color=22AAEE" alt="Python:2.7|3.5|3.6|3.7|3.8" />](https://www.python.org/downloads/)
* A [Python virtual env](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) is recommended. <i><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/virtualenv_instructions.md">See shortcut</a>.</i>
* Upgrade **[pip](https://pypi.org/project/pip/)** to prevent warnings:

```bash
python -m pip install -U pip
```
-- macOS/Linux: ``python3 -m pip install -U pip``
-- Windows(Cmd): ``py -m pip install -U pip``

<a id="install_seleniumbase"></a>
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Install SeleniumBase:</h2>
Expand Down Expand Up @@ -315,7 +313,7 @@ SeleniumBase provides additional ``pytest`` command-line options for tests:
--agent=STRING # (Modify the web browser's User-Agent string.)
--mobile # (Use the mobile device emulator while running tests.)
--metrics=STRING # (Set mobile "CSSWidth,CSSHeight,PixelRatio".)
--extension-zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
--extension-zip=ZIP # (Load a Chrome Extension .zip|.crx, comma-separated.)
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
--headless # (Run tests headlessly. Default mode on Linux OS.)
--headed # (Run tests with a GUI on Linux OS.)
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
livereload==2.6.2;python_version>="3.6"
pymdown-extensions==8.0
mkdocs==1.1.2
mkdocs-material==5.5.6
mkdocs-material==5.5.7
mkdocs-simple-hooks==0.1.1
mkdocs-material-extensions==1.0
mkdocs-minify-plugin==0.3.0
1 change: 1 addition & 0 deletions examples/offline_examples/demo_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
</style>
</head>
<body>
<!-- Tested with SeleniumBase - https://seleniumbase.io -->
<form id="myForm">
<table id="myTable" style="width: 780px; padding: 10px;">
<tbody id="tbodyId">
Expand Down
2 changes: 1 addition & 1 deletion help_docs/customizing_test_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ SeleniumBase provides additional ``pytest`` command-line options for tests:
--proxy=USERNAME:PASSWORD@SERVER:PORT # (Use authenticated proxy server.)
--mobile # (Use the mobile device emulator while running tests.)
--metrics=STRING # (Set mobile "CSSWidth,CSSHeight,PixelRatio".)
--extension-zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
--extension-zip=ZIP # (Load a Chrome Extension .zip|.crx, comma-separated.)
--extension-dir=DIR # (Load a Chrome Extension directory, comma-separated.)
--headless # (Run tests headlessly. Default mode on Linux OS.)
--headed # (Run tests with a GUI on Linux OS.)
Expand Down
63 changes: 46 additions & 17 deletions help_docs/virtualenv_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
(*Shortcut*: Run "``source virtualenv_install.sh``" from the top-level SeleniumBase folder to perform the following steps.)

```bash
python -m pip install --upgrade virtualenv
python -m pip install --upgrade virtualenvwrapper
python3 -m pip install pip wheel --force-reinstall
python3 -m pip install virtualenvwrapper --force-reinstall
export WORKON_HOME=$HOME/.virtualenvs
source `which virtualenvwrapper.sh`
```
Expand All @@ -20,52 +20,81 @@ If you add ``source `which virtualenvwrapper.sh` `` to your local bash file (``~
(*Shortcut*: Run "``virtualenv_install.bat``" from the top-level SeleniumBase folder to perform the following steps.)

```bash
python -m pip install --upgrade virtualenvwrapper-win
py -m pip install pip wheel --force-reinstall --user
py -m pip install virtualenvwrapper-win --force-reinstall --user
```

### Step 2: Create a virtual environment:

### macOS / Linux / Windows:
### macOS / Linux:

* Using ``mkvirtualenv`` (any version of Python):
```bash
mkvirtualenv sbase_env
```
(If you have multiple versions of Python installed on your machine, and you want your virtual environment to use a specific Python version, add ``--python=PATH_TO_PYTHON_EXE`` with the Python executable to use.)

* (Python 2) Using ``virtualenv``:
```bash
virtualenv sbase_env
source sbase_env/bin/activate
```

* (Python 3) Using ``python3 -m venv``:
```bash
python3 -m venv sbase_env
source sbase_env/bin/activate
```

* Using ``mkvirtualenv``:
### Windows:

* Using ``mkvirtualenv`` (any version of Python):
```bash
mkvirtualenv seleniumbase_venv
mkvirtualenv sbase_env
```
(If you have multiple versions of Python installed on your machine, and you want your virtual environment to use a specific Python version, add ``--python=PATH_TO_PYTHON_EXE`` with the Python executable to use.)

* Using ``virtualenv``:
* (Python 2) Using ``virtualenv``:
```bash
virtualenv seleniumbase_venv
source seleniumbase_venv/bin/activate
virtualenv sbase_env
call sbase_env\\Scripts\\activate
```

* (Python 3) Using ``mvenv``:
* (Python 3) Using ``py -m venv``:
```bash
python3 -mvenv seleniumbase_venv
source seleniumbase_venv/bin/activate
py -m venv sbase_env
call sbase_env\\Scripts\\activate
```

---

If you ever need to leave your virtual environment, use the following command:
### mkvirtualenv Commands

Creating a virtual environment:

```bash
mkvirtualenv sbase_env
```

Leaving your virtual environment:

```bash
deactivate
```

You can always jump back into your virtual environment later:
Returning to a virtual environment:

```bash
workon seleniumbase_venv
workon sbase_env
```

To list all existing virtual environments:
Listing all virtual environments:

```bash
lsvirtualenv
```

To delete a virtual environment:
Deleting a virtual environment:

```bash
rmvirtualenv VIRTUAL_ENV_NAME
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ markdown_extensions:
# Configuration
theme:
name: material
logo: https://seleniumbase.io/cdn/img/sb_logo_dh.png
logo: img/logo3a.png
favicon: img/logo3a.png
include_homepage_in_sidebar: true
sticky_navigation: true
Expand Down
1 change: 0 additions & 1 deletion seleniumbase/console_scripts/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ See: http://www.katalon.com/automation-recorder

* Options:
``-n`` (Add line Numbers to the rows)
``-w`` (Use word-Wrap for long lines)

* Output:
Prints the code/text of any file
Expand Down
1 change: 0 additions & 1 deletion seleniumbase/console_scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def show_print_usage():
print(" OR: sbase print [FILE] [OPTIONS]")
print(" Options:")
print(" -n (Add line Numbers to the rows)")
print(" -w (Use word-Wrap for long lines)")
print(" Output:")
print(" Prints the code/text of any file")
print(" with syntax-highlighting.")
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/console_scripts/sb_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
DEFAULT_CHROMEDRIVER_VERSION = "2.44"
DEFAULT_GECKODRIVER_VERSION = "v0.26.0"
DEFAULT_EDGEDRIVER_VERSION = "84.0.522.59"
DEFAULT_OPERADRIVER_VERSION = "v.81.0.4044.113"
DEFAULT_OPERADRIVER_VERSION = "v.84.0.4147.89"


def invalid_run_command():
Expand Down
4 changes: 1 addition & 3 deletions seleniumbase/console_scripts/sb_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
OR: sbase print [FILE] [OPTIONS]
Options:
-n (Add line Numbers to the rows)
-w (Use word-Wrap for long lines)
Output:
Prints the code/text of any file
with syntax-highlighting.
Expand All @@ -24,7 +23,6 @@ def invalid_run_command(msg=None):
exp += " OR: sbase print [FILE] [OPTIONS]\n"
exp += " Options:\n"
exp += " -n (Add line Numbers to the rows)\n"
exp += " -w (Use word-Wrap for long lines)\n"
exp += " Output:\n"
exp += " Prints the code/text of any file\n"
exp += ' with syntax-highlighting.\n'
Expand Down Expand Up @@ -67,7 +65,7 @@ def main():
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA
cr = colorama.Style.RESET_ALL
line_numbers = False
word_wrap = False
word_wrap = True # Always use word wrap now
help_me = False
invalid_cmd = None
is_python_file = False
Expand Down
66 changes: 49 additions & 17 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _add_chrome_disable_csp_extension(chrome_options):


def _set_chrome_options(
downloads_path, headless,
browser_name, downloads_path, headless,
proxy_string, proxy_auth, proxy_user, proxy_pass,
user_agent, disable_csp, enable_sync, use_auto_ext,
no_sandbox, disable_gpu, incognito, guest_mode, devtools, swiftshader,
Expand All @@ -156,7 +156,20 @@ def _set_chrome_options(
else:
chrome_options.add_experimental_option(
"excludeSwitches",
["enable-automation", "enable-logging"])
["enable-automation", "enable-logging", "enable-blink-features"])
if browser_name == constants.Browser.OPERA:
# Disable the Blink features
if enable_sync:
chrome_options.add_experimental_option(
"excludeSwitches",
(["enable-automation", "enable-logging", "disable-sync",
"enable-blink-features"]))
chrome_options.add_argument("--enable-sync")
else:
chrome_options.add_experimental_option(
"excludeSwitches",
(["enable-automation", "enable-logging",
"enable-blink-features"]))
if mobile_emulator:
emulator_settings = {}
device_metrics = {}
Expand Down Expand Up @@ -207,7 +220,6 @@ def _set_chrome_options(
chrome_options.add_argument("--test-type")
chrome_options.add_argument("--log-level=3")
chrome_options.add_argument("--no-first-run")
chrome_options.add_argument("--ignore-certificate-errors")
if devtools and not headless:
chrome_options.add_argument("--auto-open-devtools-for-tabs")
chrome_options.add_argument("--allow-file-access-from-files")
Expand All @@ -219,7 +231,6 @@ def _set_chrome_options(
chrome_options.add_argument("--disable-save-password-bubble")
chrome_options.add_argument("--disable-single-click-autofill")
chrome_options.add_argument("--disable-translate")
chrome_options.add_argument("--disable-web-security")
chrome_options.add_argument("--homepage=about:blank")
chrome_options.add_argument("--dns-prefetch-disable")
chrome_options.add_argument("--dom-automation")
Expand All @@ -231,21 +242,30 @@ def _set_chrome_options(
# Headless Chrome doesn't support extensions, which are required
# for disabling the Content Security Policy on Chrome
chrome_options = _add_chrome_disable_csp_extension(chrome_options)
chrome_options.add_argument("--enable-sync")
if proxy_string:
if proxy_auth:
chrome_options = _add_chrome_proxy_extension(
chrome_options, proxy_string, proxy_user, proxy_pass)
chrome_options.add_argument('--proxy-server=%s' % proxy_string)
if headless:
if not proxy_auth:
if not proxy_auth and not browser_name == constants.Browser.OPERA:
# Headless Chrome doesn't support extensions, which are
# required when using a proxy server that has authentication.
# Instead, base_case.py will use PyVirtualDisplay when not
# using Chrome's built-in headless mode. See link for details:
# https://bugs.chromium.org/p/chromium/issues/detail?id=706008
# Also, Opera Chromium doesn't support headless mode:
# https://github.com/operasoftware/operachromiumdriver/issues/62
chrome_options.add_argument("--headless")
# if (headless and "linux" in PLATFORM) or no_sandbox:
chrome_options.add_argument("--no-sandbox") # (Now always on)
if browser_name != constants.Browser.OPERA:
# Opera Chromium doesn't support these switches
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--disable-web-security")
chrome_options.add_argument("--no-sandbox")
else:
# Opera Chromium only!
chrome_options.add_argument("--allow-elevated-browser")
if swiftshader:
chrome_options.add_argument("--use-gl=swiftshader")
else:
Expand Down Expand Up @@ -460,7 +480,7 @@ def get_remote_driver(
desired_caps["name"] = test_id
if browser_name == constants.Browser.GOOGLE_CHROME:
chrome_options = _set_chrome_options(
downloads_path, headless,
browser_name, downloads_path, headless,
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
disable_csp, enable_sync, use_auto_ext, no_sandbox, disable_gpu,
incognito, guest_mode, devtools, swiftshader, block_images,
Expand Down Expand Up @@ -674,7 +694,7 @@ def get_local_driver(
elif browser_name == constants.Browser.EDGE:
try:
chrome_options = _set_chrome_options(
downloads_path, headless,
browser_name, downloads_path, headless,
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
disable_csp, enable_sync, use_auto_ext,
no_sandbox, disable_gpu, incognito, guest_mode, devtools,
Expand Down Expand Up @@ -792,13 +812,25 @@ def get_local_driver(
safari_capabilities = _set_safari_capabilities()
return webdriver.Safari(desired_capabilities=safari_capabilities)
elif browser_name == constants.Browser.OPERA:
if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
try:
make_driver_executable_if_not(LOCAL_OPERADRIVER)
except Exception as e:
logging.debug("\nWarning: Could not make operadriver"
" executable: %s" % e)
return webdriver.Opera()
try:
if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
try:
make_driver_executable_if_not(LOCAL_OPERADRIVER)
except Exception as e:
logging.debug("\nWarning: Could not make operadriver"
" executable: %s" % e)
opera_options = _set_chrome_options(
browser_name, downloads_path, headless,
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
disable_csp, enable_sync, use_auto_ext,
no_sandbox, disable_gpu, incognito, guest_mode, devtools,
swiftshader, block_images, user_data_dir, extension_zip,
extension_dir, servername, mobile_emulator,
device_width, device_height, device_pixel_ratio)
opera_options.headless = False # No support for headless Opera
return webdriver.Opera(options=opera_options)
except Exception:
return webdriver.Opera()
elif browser_name == constants.Browser.PHANTOM_JS:
with warnings.catch_warnings():
# Ignore "PhantomJS has been deprecated" UserWarning
Expand All @@ -807,7 +839,7 @@ def get_local_driver(
elif browser_name == constants.Browser.GOOGLE_CHROME:
try:
chrome_options = _set_chrome_options(
downloads_path, headless,
browser_name, downloads_path, headless,
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
disable_csp, enable_sync, use_auto_ext,
no_sandbox, disable_gpu, incognito, guest_mode, devtools,
Expand Down
13 changes: 13 additions & 0 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,18 @@ def get_new_driver(self, browser=None, headless=None,
self.driver.set_window_rect(10, 30, 945, 630)
except Exception:
pass
elif self.browser == 'opera':
if self.maximize_option:
try:
self.driver.maximize_window()
self.wait_for_ready_state_complete()
except Exception:
pass # Keep existing browser resolution
else:
try:
self.driver.set_window_rect(10, 30, 1150, 700)
except Exception:
pass
if self.start_page and len(self.start_page) >= 4:
if page_utils.is_valid_url(self.start_page):
self.open(self.start_page)
Expand Down Expand Up @@ -3333,6 +3345,7 @@ def create_presentation(
'</style>\n'
'</head>\n\n'
'<body>\n'
'<!-- Generated by SeleniumBase - https://seleniumbase.io -->'
'<div class="reveal">\n'
'<div class="slides">\n'
'' % (constants.Reveal.MIN_CSS, reveal_theme_css))
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/plugins/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def pytest_addoption(parser):
--agent=STRING (Modify the web browser's User-Agent string.)
--mobile (Use the mobile device emulator while running tests.)
--metrics=STRING (Set mobile "CSSWidth,CSSHeight,PixelRatio".)
--extension-zip=ZIP (Load a Chrome Extension .zip file, comma-separated.)
--extension-zip=ZIP (Load a Chrome Extension .zip|.crx, comma-separated.)
--extension-dir=DIR (Load a Chrome Extension directory, comma-separated.)
--headless (Run tests headlessly. Default mode on Linux OS.)
--headed (Run tests with a GUI on Linux OS.)
Expand Down
Loading