Merge pull request #1091 from seleniumbase/selenoid-arg-parsing

Improve parsing of Selenoid capabilities from cap files
This commit is contained in:
Michael Mintz 2021-11-30 01:22:59 -05:00 committed by GitHub
commit 91bc000bea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 19 deletions

View File

@ -1,8 +1,12 @@
# Desired capabilities example file for Selenoid Grid
#
# The same result can be achieved on the command-line with:
# --cap-string='{"selenoid": "true"}'
# --cap-string='{"selenoid:options": {"enableVNC": true}}'
capabilities = {
"selenoid": "true",
"screenResolution": "1280x1024x24",
"selenoid:options": {
"enableVNC": True,
"enableVideo": False,
},
}

View File

@ -109,7 +109,7 @@ Pillow==7.2.0;python_version>="3.5" and python_version<"3.6"
Pillow==8.4.0;python_version>="3.6"
typing-extensions==3.10.0.2;python_version<"3.6"
typing-extensions==4.0.0;python_version>="3.6" and python_version<"3.8"
rich==10.15.0;python_version>="3.6" and python_version<"4.0"
rich==10.15.1;python_version>="3.6" and python_version<"4.0"
tornado==5.1.1;python_version<"3.5"
tornado==6.1;python_version>="3.5"
pdfminer.six==20191110;python_version<"3.5"

View File

@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "2.2.2"
__version__ = "2.2.3"

View File

@ -913,11 +913,12 @@ def get_remote_driver(
import json
try:
extra_caps = json.loads(cap_string)
extra_caps = json.loads(str(cap_string))
except Exception as e:
p1 = "Invalid input format for --cap-string:\n %s" % e
p2 = "The --cap-string input was: %s" % cap_string
p3 = "Enclose cap-string in SINGLE quotes; keys in DOUBLE quotes."
p3 = ("Enclose cap-string in SINGLE quotes; "
"keys and values in DOUBLE quotes.")
p4 = (
"""Here's an example of correct cap-string usage:\n """
"""--cap-string='{"browserName":"chrome","name":"test1"}'"""
@ -971,16 +972,23 @@ def get_remote_driver(
capabilities = chrome_options.to_capabilities()
# Set custom desired capabilities
selenoid = False
selenoid_options = None
screen_resolution = None
for key in desired_caps.keys():
capabilities[key] = desired_caps[key]
if key == "selenoid" and desired_caps[key]:
if key == "selenoid:options":
selenoid = True
selenoid_options = desired_caps[key]
elif key == "screenResolution":
screen_resolution = desired_caps[key]
if selenium4:
chrome_options.set_capability("cloud:options", capabilities)
if selenoid:
chrome_options.set_capability(
"selenoid:options", {"enableVNC": True}
)
snops = selenoid_options
chrome_options.set_capability("selenoid:options", snops)
if screen_resolution:
scres = screen_resolution
chrome_options.set_capability("screenResolution", scres)
return webdriver.Remote(
command_executor=address,
options=chrome_options,
@ -1015,16 +1023,23 @@ def get_remote_driver(
capabilities["moz:firefoxOptions"] = {"args": ["-headless"]}
# Set custom desired capabilities
selenoid = False
selenoid_options = None
screen_resolution = None
for key in desired_caps.keys():
capabilities[key] = desired_caps[key]
if key == "selenoid" and desired_caps[key]:
if key == "selenoid:options":
selenoid = True
selenoid_options = desired_caps[key]
elif key == "screenResolution":
screen_resolution = desired_caps[key]
if selenium4:
firefox_options.set_capability("cloud:options", capabilities)
if selenoid:
firefox_options.set_capability(
"selenoid:options", {"enableVNC": True}
)
snops = selenoid_options
firefox_options.set_capability("selenoid:options", snops)
if screen_resolution:
scres = screen_resolution
firefox_options.set_capability("screenResolution", scres)
return webdriver.Remote(
command_executor=address,
options=firefox_options,
@ -1190,16 +1205,23 @@ def get_remote_driver(
)
elif browser_name == constants.Browser.REMOTE:
selenoid = False
selenoid_options = None
screen_resolution = None
for key in desired_caps.keys():
if key == "selenoid" and desired_caps[key]:
if key == "selenoid:options":
selenoid = True
selenoid_options = desired_caps[key]
elif key == "screenResolution":
screen_resolution = desired_caps[key]
if selenium4:
remote_options = ArgOptions()
remote_options.set_capability("cloud:options", desired_caps)
if selenoid:
remote_options.set_capability(
"selenoid:options", {"enableVNC": True}
)
snops = selenoid_options
remote_options.set_capability("selenoid:options", snops)
if screen_resolution:
scres = screen_resolution
remote_options.set_capability("screenResolution", scres)
return webdriver.Remote(
command_executor=address,
options=remote_options,

View File

@ -228,7 +228,7 @@ setup(
'Pillow==8.4.0;python_version>="3.6"',
'typing-extensions==3.10.0.2;python_version<"3.6"', # <3.8 for "rich"
'typing-extensions==4.0.0;python_version>="3.6" and python_version<"3.8"', # noqa: E501
'rich==10.15.0;python_version>="3.6" and python_version<"4.0"',
'rich==10.15.1;python_version>="3.6" and python_version<"4.0"',
'tornado==5.1.1;python_version<"3.5"',
'tornado==6.1;python_version>="3.5"',
'pdfminer.six==20191110;python_version<"3.5"',