Skip to content

Commit b77cc5c

Browse files
authored
Merge pull request #791 from seleniumbase/simplified-cli
Add shortcuts for selecting the browser type
2 parents c9fbe4a + 57b7490 commit b77cc5c

File tree

10 files changed

+188
-21
lines changed

10 files changed

+188
-21
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ The code above will leave your browser window open in case there's a failure. (i
361361
362362
```bash
363363
--browser=BROWSER # (The web browser to use. Default: "chrome".)
364+
--chrome # (Shortcut for "--browser=chrome". On by default.)
365+
--edge # (Shortcut for "--browser=edge".)
366+
--firefox # (Shortcut for "--browser=firefox".)
367+
--opera # (Shortcut for "--browser=opera".)
368+
--safari # (Shortcut for "--browser=safari".)
364369
--cap-file=FILE # (The web browser's desired capabilities to use.)
365370
--cap-string=STRING # (The web browser's desired capabilities to use.)
366371
--settings-file=FILE # (Override default SeleniumBase settings.)

examples/pytest.ini

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[pytest]
2+
3+
# Let console output be seen. Don't override the pytest plugin.
4+
addopts = --capture=no --ignore conftest.py -p no:cacheprovider
5+
6+
# Ignore warnings such as DeprecationWarning and PytestUnknownMarkWarning
7+
filterwarnings =
8+
ignore::pytest.PytestWarning
9+
ignore:.*U.*mode is deprecated:DeprecationWarning
10+
11+
# Configure the junit_family option explicitly:
12+
junit_family = legacy
13+
14+
# Set pytest discovery rules:
15+
# (Most of the rules here are similar to the default rules.)
16+
# (unittest.TestCase rules override the rules here for classes and functions.)
17+
python_files = test_*.py *_test.py *_tests.py *_suite.py
18+
python_classes = Test* *Test* *Test *Tests *Suite
19+
python_functions = test_*
20+
21+
# Here are some common pytest markers:
22+
# (Some are used in the example tests.)
23+
# (pytest v4.5.0 and newer requires marker registration to prevent warnings.)
24+
# (Future versions of pytest may turn those marker warnings into errors.)
25+
markers =
26+
marker1: custom marker
27+
marker2: custom marker
28+
marker3: custom marker
29+
marker_test_suite: custom marker
30+
expected_failure: custom marker
31+
local: custom marker
32+
remote: custom marker
33+
offline: custom marker
34+
develop: custom marker
35+
qa: custom marker
36+
ci: custom marker
37+
e2e: custom marker
38+
ready: custom marker
39+
smoke: custom marker
40+
deploy: custom marker
41+
active: custom marker
42+
master: custom marker
43+
release: custom marker
44+
staging: custom marker
45+
production: custom marker

examples/test_hack_search.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ def test_hack_search(self):
1717
self.highlight('[value="Bing Search"]')
1818
self.click('[value="Bing Search"]')
1919
self.highlight("h1.b_logo")
20-
self.js_click('a[href*="github.com/seleniumbase/SeleniumBase"]')
20+
self.highlight_click('a[href*="github.com/seleniumbase/SeleniumBase"]')
2121
self.assert_element('[href="/seleniumbase/SeleniumBase"]')
2222
self.assert_true("seleniumbase/SeleniumBase" in self.get_current_url())
2323
self.click('a[title="examples"]')
24-
self.assert_text('examples', 'strong.final-path')
24+
self.assert_text("examples", "strong.final-path")
25+
self.highlight_click('[title="test_hack_search.py"]')
26+
self.assert_text("test_hack_search.py", "strong.final-path")

help_docs/customizing_test_runs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ SeleniumBase provides additional ``pytest`` command-line options for tests:
9191

9292
```bash
9393
--browser=BROWSER # (The web browser to use. Default: "chrome".)
94+
--chrome # (Shortcut for "--browser=chrome". On by default.)
95+
--edge # (Shortcut for "--browser=edge".)
96+
--firefox # (Shortcut for "--browser=firefox".)
97+
--opera # (Shortcut for "--browser=opera".)
98+
--safari # (Shortcut for "--browser=safari".)
9499
--cap-file=FILE # (The web browser's desired capabilities to use.)
95100
--cap-string=STRING # (The web browser's desired capabilities to use.)
96101
--settings-file=FILE # (Override default SeleniumBase settings.)

requirements.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
pip>=20.3.3
1+
pip>=20.3.4;python_version<"3.6"
2+
pip>=21.0;python_version>="3.6"
23
packaging>=20.8
34
setuptools>=44.1.1;python_version<"3.5"
45
setuptools>=50.3.2;python_version>="3.5" and python_version<"3.6"
5-
setuptools>=51.3.3;python_version>="3.6"
6+
setuptools>=52.0.0;python_version>="3.6"
67
setuptools-scm>=5.0.1
78
wheel>=0.36.2
89
attrs>=20.3.0
@@ -57,7 +58,7 @@ pygments==2.7.4;python_version>="3.5"
5758
traitlets==4.3.3;python_version<"3.7"
5859
traitlets==5.0.5;python_version>="3.7"
5960
prompt-toolkit==1.0.18;python_version<"3.6"
60-
prompt-toolkit==3.0.11;python_version>="3.6"
61+
prompt-toolkit==3.0.13;python_version>="3.6"
6162
ipython==5.10.0;python_version<"3.5"
6263
ipython==6.5.0;python_version>="3.5" and python_version<"3.6"
6364
ipython==7.16.1;python_version>="3.6" and python_version<"3.7"
@@ -77,7 +78,7 @@ toml==0.10.2
7778
Pillow==6.2.2;python_version<"3.5"
7879
Pillow==7.2.0;python_version>="3.5" and python_version<"3.6"
7980
Pillow==8.1.0;python_version>="3.6"
80-
rich==9.8.2;python_version>="3.6" and python_version<"4.0"
81+
rich==9.9.0;python_version>="3.6" and python_version<"4.0"
8182
zipp==1.2.0;python_version<"3.6"
8283
zipp==3.4.0;python_version>="3.6"
8384
flake8==3.7.9;python_version<"3.5"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "1.52.6"
2+
__version__ = "1.53.0"

seleniumbase/console_scripts/run.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ def show_basic_usage():
6565
sc += ("\n")
6666
sc += ("COMMANDS:\n")
6767
sc += (" install [DRIVER] [OPTIONS]\n")
68-
sc += (" mkdir [DIRECTORY]\n")
69-
sc += (" mkfile [FILE.py]\n")
68+
sc += (" mkdir [DIRECTORY] [OPTIONS]\n")
69+
sc += (" mkfile [FILE.py] [OPTIONS]\n")
7070
sc += (" options (List common pytest options)\n")
7171
sc += (" print [FILE] [OPTIONS]\n")
7272
sc += (" translate [SB_FILE.py] [LANG] [ACTION]\n")
7373
sc += (" convert [WEBDRIVER_UNITTEST_FILE.py]\n")
7474
sc += (" extract-objects [SB_FILE.py]\n")
7575
sc += (" inject-objects [SB_FILE.py] [OPTIONS]\n")
7676
sc += (" objectify [SB_FILE.py] [OPTIONS]\n")
77-
sc += (" revert-objects [SB_FILE.py]\n")
77+
sc += (" revert-objects [SB_FILE.py] [OPTIONS]\n")
7878
sc += (" encrypt (OR: obfuscate)\n")
7979
sc += (" decrypt (OR: unobfuscate)\n")
8080
sc += (" download server (Selenium Server JAR file)\n")
@@ -159,8 +159,8 @@ def show_mkfile_usage():
159159
print(sc)
160160
print("")
161161
print(" Usage:")
162-
print(" seleniumbase mkfile [FILE.py]")
163-
print(" OR: sbase mkfile [FILE.py]")
162+
print(" seleniumbase mkfile [FILE.py] [OPTIONS]")
163+
print(" OR: sbase mkfile [FILE.py] [OPTIONS]")
164164
print(" Example:")
165165
print(" sbase mkfile new_test.py")
166166
print(" Options:")

seleniumbase/fixtures/base_case.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5969,7 +5969,13 @@ def __jquery_slow_scroll_to(self, selector, by=By.CSS_SELECTOR):
59695969
"""jQuery([document.documentElement, document.body]).animate({
59705970
scrollTop: jQuery('%s').offset().top - 130}, %s);
59715971
""" % (selector, scroll_time_ms))
5972-
self.safe_execute_script(scroll_script)
5972+
if js_utils.is_jquery_activated(self.driver):
5973+
self.execute_script(scroll_script)
5974+
else:
5975+
try:
5976+
self.safe_execute_script(scroll_script)
5977+
except Exception:
5978+
self.__slow_scroll_to_element(element)
59735979
self.sleep(sleep_time)
59745980

59755981
def __jquery_click(self, selector, by=By.CSS_SELECTOR):

seleniumbase/plugins/pytest_plugin.py

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def pytest_addoption(parser):
1818
"""
1919
This plugin adds the following command-line options to pytest:
2020
--browser=BROWSER (The web browser to use. Default: "chrome".)
21+
--chrome (Shortcut for "--browser=chrome". On by default.)
22+
--edge (Shortcut for "--browser=edge".)
23+
--firefox (Shortcut for "--browser=firefox".)
24+
--opera (Shortcut for "--browser=opera".)
25+
--safari (Shortcut for "--browser=safari".)
2126
--settings-file=FILE (Override default SeleniumBase settings.)
2227
--env=ENV (Set the test env. Access with "self.env" in tests.)
2328
--data=DATA (Extra test data. Access with "self.data" in tests.)
@@ -93,6 +98,31 @@ def pytest_addoption(parser):
9398
help="""Specifies the web browser to use. Default: Chrome.
9499
If you want to use Firefox, explicitly indicate that.
95100
Example: (--browser=firefox)""")
101+
parser.addoption('--chrome',
102+
action="store_true",
103+
dest='use_chrome',
104+
default=False,
105+
help="""Shortcut for --browser=chrome. On by default.)""")
106+
parser.addoption('--edge',
107+
action="store_true",
108+
dest='use_edge',
109+
default=False,
110+
help="""Shortcut for --browser=edge.)""")
111+
parser.addoption('--firefox',
112+
action="store_true",
113+
dest='use_firefox',
114+
default=False,
115+
help="""Shortcut for --browser=firefox.)""")
116+
parser.addoption('--opera',
117+
action="store_true",
118+
dest='use_opera',
119+
default=False,
120+
help="""Shortcut for --browser=opera.)""")
121+
parser.addoption('--safari',
122+
action="store_true",
123+
dest='use_safari',
124+
default=False,
125+
help="""Shortcut for --browser=safari.)""")
96126
parser.addoption('--with-selenium',
97127
action="store_true",
98128
dest='with_selenium',
@@ -503,20 +533,90 @@ def pytest_addoption(parser):
503533
help="""Setting this overrides the default timeout
504534
by the multiplier when waiting for page elements.
505535
Unused when tests override the default value.""")
506-
for arg in sys.argv:
536+
537+
sys_argv = sys.argv
538+
sb_config._browser_shortcut = None
539+
540+
# SeleniumBase does not support pytest-timeout due to hanging browsers.
541+
for arg in sys_argv:
507542
if "--timeout=" in arg:
508543
raise Exception(
509544
"\n\n Don't use --timeout=s from pytest-timeout! "
510545
"\n It's not thread-safe for WebDriver processes! "
511546
"\n Use --time-limit=s from SeleniumBase instead!\n")
512547

513-
if "--dashboard" in sys.argv:
514-
arg_join = " ".join(sys.argv)
515-
if ("-n" in sys.argv) or ("-n=" in arg_join):
548+
# The SeleniumBase Dashboard does not yet support multi-threadeded tests.
549+
if "--dashboard" in sys_argv:
550+
arg_join = " ".join(sys_argv)
551+
if ("-n" in sys_argv) or ("-n=" in arg_join):
516552
raise Exception(
517553
"\n\n Multi-threading is not yet supported using --dashboard"
518554
"\n (You can speed up tests using --reuse-session / --rs)\n")
519555

556+
# As a shortcut, you can use "--edge" instead of "--browser=edge", etc,
557+
# but you can only specify one default browser for tests. (Default: chrome)
558+
browser_changes = 0
559+
browser_set = None
560+
browser_list = []
561+
if "--browser=chrome" in sys_argv or "--browser chrome" in sys_argv:
562+
browser_changes += 1
563+
browser_set = "chrome"
564+
browser_list.append("--browser=chrome")
565+
if "--browser=edge" in sys_argv or "--browser edge" in sys_argv:
566+
browser_changes += 1
567+
browser_set = "edge"
568+
browser_list.append("--browser=edge")
569+
if "--browser=firefox" in sys_argv or "--browser firefox" in sys_argv:
570+
browser_changes += 1
571+
browser_set = "firefox"
572+
browser_list.append("--browser=firefox")
573+
if "--browser=opera" in sys_argv or "--browser opera" in sys_argv:
574+
browser_changes += 1
575+
browser_set = "opera"
576+
browser_list.append("--browser=opera")
577+
if "--browser=safari" in sys_argv or "--browser safari" in sys_argv:
578+
browser_changes += 1
579+
browser_set = "safari"
580+
browser_list.append("--browser=safari")
581+
if "--browser=ie" in sys_argv or "--browser ie" in sys_argv:
582+
browser_changes += 1
583+
browser_set = "ie"
584+
browser_list.append("--browser=ie")
585+
if "--browser=phantomjs" in sys_argv or "--browser phantomjs" in sys_argv:
586+
browser_changes += 1
587+
browser_set = "phantomjs"
588+
browser_list.append("--browser=phantomjs")
589+
if "--browser=remote" in sys_argv or "--browser remote" in sys_argv:
590+
browser_changes += 1
591+
browser_set = "remote"
592+
browser_list.append("--browser=remote")
593+
if "--chrome" in sys_argv and not browser_set == "chrome":
594+
browser_changes += 1
595+
sb_config._browser_shortcut = "chrome"
596+
browser_list.append("--chrome")
597+
if "--edge" in sys_argv and not browser_set == "edge":
598+
browser_changes += 1
599+
sb_config._browser_shortcut = "edge"
600+
browser_list.append("--edge")
601+
if "--firefox" in sys_argv and not browser_set == "firefox":
602+
browser_changes += 1
603+
sb_config._browser_shortcut = "firefox"
604+
browser_list.append("--firefox")
605+
if "--opera" in sys_argv and not browser_set == "opera":
606+
browser_changes += 1
607+
sb_config._browser_shortcut = "opera"
608+
browser_list.append("--opera")
609+
if "--safari" in sys_argv and not browser_set == "safari":
610+
browser_changes += 1
611+
sb_config._browser_shortcut = "safari"
612+
browser_list.append("--safari")
613+
if browser_changes > 1:
614+
message = "\n\n Too many browser types were entered!"
615+
message += "\n There were %s found: %s" % (
616+
browser_changes, ", ".join(browser_list))
617+
message += "\n Please enter ONLY ONE and try again!\n"
618+
raise Exception(message)
619+
520620

521621
def pytest_configure(config):
522622
""" This runs after command-line options have been parsed. """
@@ -527,6 +627,8 @@ def pytest_configure(config):
527627
sb_config.item_count_untested = 0
528628
sb_config.is_pytest = True
529629
sb_config.browser = config.getoption('browser')
630+
if sb_config._browser_shortcut:
631+
sb_config.browser = sb_config._browser_shortcut
530632
sb_config.data = config.getoption('data')
531633
sb_config.var1 = config.getoption('var1')
532634
sb_config.var2 = config.getoption('var2')

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@
102102
],
103103
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
104104
install_requires=[
105-
'pip>=20.3.3',
105+
'pip>=20.3.4;python_version<"3.6"',
106+
'pip>=21.0;python_version>="3.6"',
106107
'packaging>=20.8',
107108
'setuptools>=44.1.1;python_version<"3.5"',
108109
'setuptools>=50.3.2;python_version>="3.5" and python_version<"3.6"',
109-
'setuptools>=51.3.3;python_version>="3.6"',
110+
'setuptools>=52.0.0;python_version>="3.6"',
110111
'setuptools-scm>=5.0.1',
111112
'wheel>=0.36.2',
112113
'attrs>=20.3.0',
@@ -162,7 +163,7 @@
162163
'traitlets==5.0.5;python_version>="3.7"',
163164
'ipython==5.10.0;python_version<"3.5"',
164165
'prompt-toolkit==1.0.18;python_version<"3.6"',
165-
'prompt-toolkit==3.0.11;python_version>="3.6"',
166+
'prompt-toolkit==3.0.13;python_version>="3.6"',
166167
'ipython==6.5.0;python_version>="3.5" and python_version<"3.6"',
167168
'ipython==7.16.1;python_version>="3.6" and python_version<"3.7"',
168169
'ipython==7.19.0;python_version>="3.7"',
@@ -181,7 +182,7 @@
181182
'Pillow==6.2.2;python_version<"3.5"',
182183
'Pillow==7.2.0;python_version>="3.5" and python_version<"3.6"',
183184
'Pillow==8.1.0;python_version>="3.6"',
184-
'rich==9.8.2;python_version>="3.6" and python_version<"4.0"',
185+
'rich==9.9.0;python_version>="3.6" and python_version<"4.0"',
185186
'zipp==1.2.0;python_version<"3.6"',
186187
'zipp==3.4.0;python_version>="3.6"',
187188
'flake8==3.7.9;python_version<"3.5"',

0 commit comments

Comments
 (0)