Skip to content

Commit 13f60c0

Browse files
committed
Generate the desired capabilities "name" if "*" is passed
1 parent fe096b3 commit 13f60c0

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

examples/capabilities/ReadMe.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,17 @@ pytest test_swag_labs.py --cap-string='{"browserName":"chrome","name":"test1"}'
5959
```
6060
(Enclose cap-string in single quotes. Enclose parameter keys in double quotes.)
6161

62-
If using a local Selenium Grid with SeleniumBase, make sure to start up the Grid Hub and nodes first:
62+
If you pass ``"*"`` into the ``"name"`` field of ``--cap-string``, the name will become the test identifier. Example:
63+
```bash
64+
pytest test_swag_labs.py --cap-string='{"browserName":"chrome","name":"*"}' --server="127.0.0.1" --browser=chrome
65+
```
66+
Example name: ``"my_first_test.MyTestClass.test_basic"``
67+
68+
### Using a local Selenium Grid
69+
70+
If using a local Selenium Grid with SeleniumBase, start up the Grid Hub and nodes first:
6371
```bash
6472
seleniumbase grid-hub start
6573
seleniumbase grid-node start
6674
```
75+
(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.)

seleniumbase/core/browser_launcher.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def get_driver(browser_name, headless=False, use_grid=False,
352352
no_sandbox=None, disable_gpu=None,
353353
incognito=None, guest_mode=None, devtools=None,
354354
user_data_dir=None, extension_zip=None, extension_dir=None,
355-
mobile_emulator=False, device_width=None,
355+
test_id=None, mobile_emulator=False, device_width=None,
356356
device_height=None, device_pixel_ratio=None):
357357
proxy_auth = False
358358
proxy_user = None
@@ -389,7 +389,7 @@ def get_driver(browser_name, headless=False, use_grid=False,
389389
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
390390
cap_file, cap_string, disable_csp, enable_sync, use_auto_ext,
391391
no_sandbox, disable_gpu, incognito, guest_mode, devtools,
392-
user_data_dir, extension_zip, extension_dir,
392+
user_data_dir, extension_zip, extension_dir, test_id,
393393
mobile_emulator, device_width, device_height, device_pixel_ratio)
394394
else:
395395
return get_local_driver(
@@ -406,7 +406,7 @@ def get_remote_driver(
406406
proxy_user, proxy_pass, user_agent, cap_file, cap_string,
407407
disable_csp, enable_sync, use_auto_ext, no_sandbox, disable_gpu,
408408
incognito, guest_mode, devtools,
409-
user_data_dir, extension_zip, extension_dir,
409+
user_data_dir, extension_zip, extension_dir, test_id,
410410
mobile_emulator, device_width, device_height, device_pixel_ratio):
411411
downloads_path = download_helper.get_downloads_folder()
412412
download_helper.reset_downloads_folder()
@@ -421,12 +421,16 @@ def get_remote_driver(
421421
except Exception as e:
422422
p1 = "Invalid input format for --cap-string:\n %s" % e
423423
p2 = "The --cap-string input was: %s" % cap_string
424-
p3 = "Enclose cap-string in single quotes; keys in double quotes."
424+
p3 = "Enclose cap-string in SINGLE quotes; keys in DOUBLE quotes."
425425
p4 = ("""Here's an example of correct cap-string usage:\n """
426426
"""--cap-string='{"browserName":"chrome","name":"test1"}'""")
427427
raise Exception("%s\n%s\n%s\n%s" % (p1, p2, p3, p4))
428428
for cap_key in extra_caps.keys():
429429
desired_caps[cap_key] = extra_caps[cap_key]
430+
if cap_file or cap_string:
431+
if "name" in desired_caps.keys():
432+
if desired_caps["name"] == "*":
433+
desired_caps["name"] = test_id
430434
if browser_name == constants.Browser.GOOGLE_CHROME:
431435
chrome_options = _set_chrome_options(
432436
downloads_path, headless,

seleniumbase/fixtures/base_case.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ def get_new_driver(self, browser=None, headless=None,
16221622
# Due to https://stackoverflow.com/questions/23055651/ , skip extension
16231623
# if self.demo_mode or self.masterqa_mode:
16241624
# disable_csp = True
1625+
test_id = self.__get_test_id()
16251626
if cap_file is None:
16261627
cap_file = self.cap_file
16271628
if cap_string is None:
@@ -1660,6 +1661,7 @@ def get_new_driver(self, browser=None, headless=None,
16601661
user_data_dir=user_data_dir,
16611662
extension_zip=extension_zip,
16621663
extension_dir=extension_dir,
1664+
test_id=test_id,
16631665
mobile_emulator=is_mobile,
16641666
device_width=d_width,
16651667
device_height=d_height,

0 commit comments

Comments
 (0)