Generate the desired capabilities "name" if "*" is passed

This commit is contained in:
Michael Mintz 2020-04-21 15:37:37 -04:00
parent fe096b3007
commit 13f60c059a
3 changed files with 20 additions and 5 deletions

View File

@ -59,8 +59,17 @@ pytest test_swag_labs.py --cap-string='{"browserName":"chrome","name":"test1"}'
```
(Enclose cap-string in single quotes. Enclose parameter keys in double quotes.)
If using a local Selenium Grid with SeleniumBase, make sure to start up the Grid Hub and nodes first:
If you pass ``"*"`` into the ``"name"`` field of ``--cap-string``, the name will become the test identifier. Example:
```bash
pytest test_swag_labs.py --cap-string='{"browserName":"chrome","name":"*"}' --server="127.0.0.1" --browser=chrome
```
Example name: ``"my_first_test.MyTestClass.test_basic"``
### Using a local Selenium Grid
If using a local Selenium Grid with SeleniumBase, start up the Grid Hub and nodes first:
```bash
seleniumbase grid-hub start
seleniumbase grid-node start
```
(The Selenium Server JAR file will be automatically downloaded for first-time Grid users. You'll also need Java installed to start up the Grid.)

View File

@ -352,7 +352,7 @@ def get_driver(browser_name, headless=False, use_grid=False,
no_sandbox=None, disable_gpu=None,
incognito=None, guest_mode=None, devtools=None,
user_data_dir=None, extension_zip=None, extension_dir=None,
mobile_emulator=False, device_width=None,
test_id=None, mobile_emulator=False, device_width=None,
device_height=None, device_pixel_ratio=None):
proxy_auth = False
proxy_user = None
@ -389,7 +389,7 @@ def get_driver(browser_name, headless=False, use_grid=False,
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
cap_file, cap_string, disable_csp, enable_sync, use_auto_ext,
no_sandbox, disable_gpu, incognito, guest_mode, devtools,
user_data_dir, extension_zip, extension_dir,
user_data_dir, extension_zip, extension_dir, test_id,
mobile_emulator, device_width, device_height, device_pixel_ratio)
else:
return get_local_driver(
@ -406,7 +406,7 @@ def get_remote_driver(
proxy_user, proxy_pass, user_agent, cap_file, cap_string,
disable_csp, enable_sync, use_auto_ext, no_sandbox, disable_gpu,
incognito, guest_mode, devtools,
user_data_dir, extension_zip, extension_dir,
user_data_dir, extension_zip, extension_dir, test_id,
mobile_emulator, device_width, device_height, device_pixel_ratio):
downloads_path = download_helper.get_downloads_folder()
download_helper.reset_downloads_folder()
@ -421,12 +421,16 @@ def get_remote_driver(
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 in DOUBLE quotes."
p4 = ("""Here's an example of correct cap-string usage:\n """
"""--cap-string='{"browserName":"chrome","name":"test1"}'""")
raise Exception("%s\n%s\n%s\n%s" % (p1, p2, p3, p4))
for cap_key in extra_caps.keys():
desired_caps[cap_key] = extra_caps[cap_key]
if cap_file or cap_string:
if "name" in desired_caps.keys():
if desired_caps["name"] == "*":
desired_caps["name"] = test_id
if browser_name == constants.Browser.GOOGLE_CHROME:
chrome_options = _set_chrome_options(
downloads_path, headless,

View File

@ -1622,6 +1622,7 @@ class BaseCase(unittest.TestCase):
# Due to https://stackoverflow.com/questions/23055651/ , skip extension
# if self.demo_mode or self.masterqa_mode:
# disable_csp = True
test_id = self.__get_test_id()
if cap_file is None:
cap_file = self.cap_file
if cap_string is None:
@ -1660,6 +1661,7 @@ class BaseCase(unittest.TestCase):
user_data_dir=user_data_dir,
extension_zip=extension_zip,
extension_dir=extension_dir,
test_id=test_id,
mobile_emulator=is_mobile,
device_width=d_width,
device_height=d_height,