Skip to content

Commit d2caf6d

Browse files
authored
Merge pull request #1939 from seleniumbase/dependencies-docs-and-refactoring
Dependencies, docs, and refactoring
2 parents 9653442 + 88a7792 commit d2caf6d

File tree

13 files changed

+116
-61
lines changed

13 files changed

+116
-61
lines changed

README.md

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<h1>SeleniumBase</h1>
1111

12-
<h3 align="center">Python-powered web automation and testing — with advanced tools.</h3>
12+
<h3 align="center">Automate & test web apps on any platform, with Python.</h3>
1313

1414
<h3 align="center"><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://seleniumbase.github.io/cdn/gif/coffee_pdbp.gif" alt="SeleniumBase test with the pdbp debugger" title="SeleniumBase test with the pdbp debugger" /></a></h3>
1515

@@ -57,7 +57,42 @@
5757

5858
--------
5959

60+
<blockquote>
61+
<p dir="auto"><strong>Jump to:</strong></p>
62+
<ul dir="auto">
63+
<li><a href="#multiple_examples" ><strong>Multiple Examples</strong></a></li>
64+
<li><a href="#python_installation" ><strong>Set up Python & Git</strong></a></li>
65+
<li><a href="#install_seleniumbase" ><strong>Install SeleniumBase</strong></a></li>
66+
<li><a href="#basic_example_and_usage"><strong>Basic Example & Usage</strong></a></li>
67+
<li><a href="#common_methods" ><strong>Common Test Methods</strong></a></li>
68+
<li><a href="#fun_facts" ><strong>Fun Facts / Learn More</strong></a></li>
69+
<li><a href="#demo_mode_and_debugging"><strong>Demo Mode and Debugging</strong></a></li>
70+
<li><a href="#pytest_options" ><strong>Useful pytest Options</strong></a></li>
71+
<li><a href="#new_pytest_options" ><strong>SeleniumBase Options</strong></a></li>
72+
<li><a href="#directory_configuration"><strong>Directory Configuration</strong></a></li>
73+
<li><a href="#seleniumbase_dashboard" ><strong>SeleniumBase Dashboard</strong></a></li>
74+
<li><a href="#creating_visual_reports"><strong>Generating Test Reports</strong></a></li>
75+
</ul>
76+
</blockquote>
77+
78+
--------
79+
6080
<a id="multiple_examples"></a>
81+
<p align="left">Run <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_demo_site.py" target="_blank">test_demo_site.py</a> from <a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples" target="_blank">examples/</a> (<code>--chrome</code> is the default browser):</p>
82+
83+
```bash
84+
cd examples/
85+
pytest test_demo_site.py
86+
```
87+
88+
<p align="left"><a href="https://seleniumbase.io/demo_page" target="_blank"><img src="https://seleniumbase.github.io/cdn/gif/demo_page_5.gif" width="480" alt="SeleniumBase Example" title="SeleniumBase Example" /></a></p>
89+
90+
> Type text, click, select, toggle, drag-and-drop, etc. Even handle iframes.
91+
92+
--------
93+
94+
Looking for overpriced coffee? Try running this test:
95+
6196
<p align="left"><b>Example:</b> <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_coffee_cart.py" target="_blank">test_coffee_cart.py</a> from <a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples" target="_blank">./examples/</a></p>
6297

6398
```bash
@@ -97,7 +132,7 @@ class CoffeeCartTest(BaseCase):
97132
<summary> ▶️ How is <b>SeleniumBase</b> different from raw Selenium? (<b>click to expand</b>)</summary>
98133
<div>
99134

100-
<p>💡 SeleniumBase is a Python framework for browser automation and testing. SeleniumBase uses <a href="https://www.w3.org/TR/webdriver2/#endpoints" target="_blank">Selenium/WebDriver</a> APIs, and incorporates test-runners such as <code>pytest</code>, <code>nosetests</code>, and <code>behave</code> to provide organized structure, test discovery, test execution, test state (<i>eg. passed, failed, or skipped</i>), and command-line options for changing default settings (<i>such as choosing the browser to use</i>). With raw Selenium, you would need to set up your own options-parser for configuring tests from the command-line.</p>
135+
<p>💡 SeleniumBase is a Python framework for browser automation and testing. SeleniumBase uses <a href="https://www.w3.org/TR/webdriver2/#endpoints" target="_blank">Selenium/WebDriver</a> APIs, and incorporates test-runners such as <code>pytest</code>, <code>pynose</code>, and <code>behave</code> to provide organized structure, test discovery, test execution, test state (<i>eg. passed, failed, or skipped</i>), and command-line options for changing default settings (<i>such as choosing the browser to use</i>). With raw Selenium, you would need to set up your own options-parser for configuring tests from the command-line.</p>
101136

102137
<p>💡 With raw Selenium, commands that use selectors need to specify the type of selector (eg. <code>"css selector", "button#myButton"</code>). With SeleniumBase, there's auto-detection between CSS Selectors and XPath, which means you don't need to specify the type of selector in your commands (<i>but optionally you could</i>).</p>
103138

@@ -132,7 +167,7 @@ With raw Selenium, that requires more code:<br />
132167
<summary> ▶️ Learn about different ways of writing tests (<b>click to expand</b>)</summary>
133168
<div>
134169

135-
<p align="left">📘📝 An example test with the <b>BaseCase</b> class. Runs with <b><a href="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a></b> or <b>nosetests</b>. (<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">Learn more</a>)</p>
170+
<p align="left">📘📝 An example test with the <b>BaseCase</b> class. Runs with <b><a href="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a></b> or <b>pynose</b>. (<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">Learn more</a>)</p>
136171

137172
```python
138173
from seleniumbase import BaseCase
@@ -206,6 +241,8 @@ Feature: SeleniumBase scenarios for the RealWorld App
206241
<a id="python_installation"></a>
207242
<h2><img src="https://seleniumbase.github.io/cdn/img/python_logo.png" title="SeleniumBase" width="42" /> Set up Python & Git:</h2>
208243

244+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/pypi/pyversions/seleniumbase.svg?color=FACE42" title="Supported Python Versions" /></a>
245+
209246
🔵 Add <b><a href="https://www.python.org/downloads/">Python</a></b> and <b><a href="https://git-scm.com/">Git</a></b> to your System PATH.
210247

211248
🔵 Using a <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/virtualenv_instructions.md">Python virtual env</a> is recommended.
@@ -311,6 +348,8 @@ pytest my_first_test.py
311348
312349
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py"><img src="https://seleniumbase.github.io/cdn/gif/swag_labs_4.gif" alt="SeleniumBase Test" title="SeleniumBase Test" width="480" /></a>
313350
351+
> SeleniumBase easily handles login, shopping, and checkout.
352+
314353
<p align="left"><b>Here's the code for <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py">my_first_test.py</a>:</b></p>
315354
316355
```python
@@ -402,12 +441,21 @@ self.assert_no_js_errors() # Verify there are no JS errors.
402441
self.type("input", "dogs\n")
403442
```
404443
405-
SeleniumBase tests can be run with <code>pytest</code> or <code>nosetests</code>. (There's also a <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">behave BDD</a> format.)
444+
Most SeleniumBase scripts can be run with <code>pytest</code>, <code>pynose</code>, or pure <code>python</code>. Not all test runners can run all test formats. For example, tests that use the ``sb`` pytest fixture can only be run with ``pytest``. (See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a>) There's also a <a href="https://behave.readthedocs.io/en/stable/gherkin.html" target="_blank">Gherkin</a> test format that runs with <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">behave</a>.
406445
407446
```bash
408-
pytest my_first_test.py --chrome
447+
pytest test_sb_fixture.py
448+
pytest coffee_cart_tests.py --rs
449+
pytest test_suite.py --rs --html=report.html --dashboard
450+
451+
pynose basic_test.py --mobile
452+
pynose test_suite.py --headless --report --show-report
409453
410-
nosetests test_suite.py --firefox
454+
python raw_sb.py
455+
python raw_test_scripts.py
456+
457+
behave realworld.feature
458+
behave calculator.feature -D rs -D dashboard
411459
```
412460
413461
<p><code>pytest</code> includes automatic test discovery. If you don't specify a specific file or folder to run, <code>pytest</code> will automatically search through all subdirectories for tests to run based on the following criteria:</p>
@@ -423,12 +471,12 @@ With a SeleniumBase [pytest.ini](https://github.com/seleniumbase/SeleniumBase/bl
423471
pytest --collect-only -q
424472
```
425473
426-
<p>✅ You can be more specific when calling <code>pytest</code> on a file:</p>
474+
<p>✅ You can be more specific when calling <code>pytest</code> or <code>pynose</code> on a file:</p>
427475
428476
```bash
429477
pytest [FILE_NAME.py]::[CLASS_NAME]::[METHOD_NAME]
430478
431-
nosetests [FILE_NAME.py]:[CLASS_NAME].[METHOD_NAME]
479+
pynose [FILE_NAME.py]:[CLASS_NAME].[METHOD_NAME]
432480
```
433481
434482
<p>✅ No More Flaky Tests! SeleniumBase methods automatically wait for page elements to finish loading before interacting with them (<i>up to a timeout limit</i>). This means <b>you no longer need random <span><code>time.sleep()</code></span> statements</b> in your scripts.</p>
@@ -449,6 +497,7 @@ nosetests [FILE_NAME.py]:[CLASS_NAME].[METHOD_NAME]
449497
<a id="detailed_instructions"></a>
450498
<h2><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Detailed Instructions:</h2>
451499
500+
<a id="demo_mode_and_debugging"></a>
452501
<a id="seleniumbase_demo_mode"></a>
453502
🔵 <b>Demo Mode</b> helps you see what a test is doing. If a test is moving too fast for your eyes, run it in <b>Demo Mode</b>, which pauses the browser briefly between actions, highlights page elements being acted on, and displays assertions:
454503
@@ -605,10 +654,10 @@ Here's the command-line option to add to tests: (See [examples/custom_settings.p
605654
🔵 To pass additional data from the command-line to tests, add ``--data="ANY STRING"``.
606655
Inside your tests, you can use ``self.data`` to access that.
607656
657+
<a id="directory_configuration"></a>
658+
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Directory Configuration:</h3>
608659
609-
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Test Directory Configuration:</h3>
610-
611-
🔵 When running tests with **pytest**, you'll want a copy of **[pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini)** in your root folders. When running tests with **nosetests**, you'll want a copy of **[setup.cfg](https://github.com/seleniumbase/SeleniumBase/blob/master/setup.cfg)** in your root folders. These files specify default configuration details for tests. Folders should also include a blank ``__init__.py`` file, which allows your tests to import files from that folder.
660+
🔵 When running tests with **pytest**, you'll want a copy of **[pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini)** in your root folders. When running tests with **pynose**, you'll want a copy of **[setup.cfg](https://github.com/seleniumbase/SeleniumBase/blob/master/setup.cfg)** in your root folders. These files specify default configuration details for tests. Folders should also include a blank ``__init__.py`` file, which allows your tests to import files from that folder.
612661
613662
🔵 ``sbase mkdir DIR`` creates a folder with config files and sample tests:
614663
@@ -658,7 +707,7 @@ ui_tests/
658707
└── setup.cfg
659708
```
660709
661-
Of those files, the ``pytest.ini`` config file is the most important, followed by a blank ``__init__.py`` file. There's also a ``setup.cfg`` file (only needed for nosetests). Finally, the ``requirements.txt`` file can be used to help you install seleniumbase into your environments (if it's not already installed).
710+
Of those files, the ``pytest.ini`` config file is the most important, followed by a blank ``__init__.py`` file. There's also a ``setup.cfg`` file (for pynose). Finally, the ``requirements.txt`` file can be used to help you install seleniumbase into your environments (if it's not already installed).
662711
663712
--------
664713
@@ -688,7 +737,8 @@ pytest test_fail.py
688737
689738
--------
690739
691-
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> The SeleniumBase Dashboard:</h3>
740+
<a id="seleniumbase_dashboard"></a>
741+
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> SeleniumBase Dashboard:</h3>
692742
693743
🔵 The ``--dashboard`` option for pytest generates a SeleniumBase Dashboard located at ``dashboard.html``, which updates automatically as tests run and produce results. Example:
694744
@@ -747,17 +797,17 @@ You can also use ``--junit-xml=report.xml`` to get an xml report instead. Jenkin
747797
pytest test_suite.py --junit-xml=report.xml
748798
```
749799
750-
<h4><b>Nosetest Reports:</b></h4>
800+
<h4><b>pynose Reports:</b></h4>
751801
752802
The ``--report`` option gives you a fancy report after your test suite completes.
753803
754804
```bash
755-
nosetests test_suite.py --report
805+
pynose test_suite.py --report
756806
```
757807
758-
<img src="https://seleniumbase.github.io/cdn/img/nose_report.png" alt="Example Nosetest Report" title="Example Nosetest Report" width="320" />
808+
<img src="https://seleniumbase.github.io/cdn/img/nose_report.png" alt="Example pynose Report" title="Example pynose Report" width="320" />
759809
760-
(NOTE: You can add ``--show-report`` to immediately display Nosetest reports after the test suite completes. Only use ``--show-report`` when running tests locally because it pauses the test run.)
810+
(NOTE: You can add ``--show-report`` to immediately display pynose reports after the test suite completes. Only use ``--show-report`` when running tests locally because it pauses the test run.)
761811
762812
<h4><b>Behave Dashboard & Reports:</b></h4>
763813
@@ -1209,6 +1259,7 @@ pytest --reruns=1 --reruns-delay=1
12091259
<span><a href="https://www.youtube.com/playlist?list=PLp9uKicxkBc5UIlGi2BuE3aWC7JyXpD3m"><img src="https://seleniumbase.github.io/cdn/img/youtube.png" title="SeleniumBase Playlist on YouTube" alt="SeleniumBase Playlist on YouTube" width="54" /></a></span>
12101260
<span><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://seleniumbase.github.io/img/social/share_github.svg" title="SeleniumBase on GitHub" alt="SeleniumBase on GitHub" width="50" /></a></span>
12111261
<span><a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://seleniumbase.github.io/img/social/share_gitter.svg" title="SeleniumBase on Gitter" alt="SeleniumBase on Gitter" width="38" /></a></span>
1262+
<span><a href="https://twitter.com/seleniumbase" target="_blank"><img src="https://seleniumbase.io/img/social/share_twitter.svg" title="SeleniumBase on Twitter" alt="SeleniumBase on Twitter" width="50" /></a></span>
12121263
</div></p>
12131264
12141265
--------

examples/ReadMe.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,28 +193,28 @@ sbase gui
193193

194194
--------
195195

196-
<b>SeleniumBase tests can also be run with ``nosetests``:</b>
196+
<b>SeleniumBase tests can also be run with ``pynose``:</b>
197197

198-
Run an example test with nosetests:
198+
Run an example test with pynose:
199199

200200
```bash
201-
nosetests my_first_test.py
201+
pynose my_first_test.py
202202
```
203203

204204
--------
205205

206-
Run an example test suite and generate a nosetest report:
206+
Run an example test suite and generate a pynose test report:
207207

208208
```bash
209-
nosetests test_suite.py --report --show-report
209+
pynose test_suite.py --report --show-report
210210
```
211211

212212
--------
213213

214-
Run an example test using a nosetest configuration file:
214+
Run an example test using a pynose configuration file:
215215

216216
```bash
217-
nosetests my_first_test.py --config=example_config.cfg
217+
pynose my_first_test.py --config=example_config.cfg
218218
```
219219

220220
--------

examples/example_logs/ReadMe.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ pytest test_suite.py --junit-xml=report.xml
9090

9191
--------
9292

93-
<h3><img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32" /> Nosetest Reports:</h3>
93+
<h3><img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32" /> pynose Test Reports:</h3>
9494

95-
The ``nosetests`` ``--report`` option gives you a fancy report after your tests complete.
95+
The ``pynose`` ``--report`` option gives you a fancy report after your tests complete.
9696

9797
```bash
98-
nosetests test_suite.py --report
98+
pynose test_suite.py --report
9999
```
100100

101-
<img src="https://seleniumbase.github.io/cdn/img/nose_report.png" alt="Example Nosetest Report" title="Example Nosetest Report" width="320" />
101+
<img src="https://seleniumbase.github.io/cdn/img/nose_report.png" alt="Example pynose Test Report" title="Example pynose Test Report" width="320" />
102102

103-
(NOTE: You can add ``--show-report`` to immediately display Nosetest reports after the test suite completes. Only use ``--show-report`` when running tests locally because it pauses the test run.)
103+
(NOTE: You can add ``--show-report`` to immediately display pynose reports after the test suite completes. Only use ``--show-report`` when running tests locally because it pauses the test run.)
104104

105105
--------
106106

examples/github_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ def test_github(self):
1717
self.assert_element("div.repository-content")
1818
self.assert_text("SeleniumBase", "strong a")
1919
self.click('a[title="seleniumbase"]')
20-
self.slow_click('a[title="fixtures"]')
21-
self.assert_element('a[title="base_case.py"]')
20+
self.slow_click('a:contains("fixtures")')
21+
self.assert_element('a:contains("base_case.py")')

examples/hack_the_planet.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ def test_all_your_base_are_belong_to_us(self):
8787
self.set_text_content("h1 span:nth-of-type(3)", "BELONG")
8888
self.set_text_content("h1 span:nth-of-type(4)", "TO")
8989
self.set_text_content("h1 span:nth-of-type(5)", "US")
90-
self.type('input[name="q"]', aybabtu.lower())
91-
self.click("h1", scroll=False)
92-
self.highlight('a[href="/pricing"]', loops=5, scroll=False)
93-
self.highlight('input[name="q"]', loops=5, scroll=False)
94-
self.highlight("h1", loops=8, scroll=False)
90+
self.highlight('a[href="/pricing"]', loops=6, scroll=False)
91+
self.highlight("h1.h2-mktg", loops=7, scroll=False)
9592

9693
self.open("https://dev.to/top/infinity")
9794
self.click_if_visible('button[aria-label="Close campaign banner"]')

examples/migration/protractor/ReadMe.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88

99
```bash
1010
$ pytest --rs -v --guest
11-
========================== test session starts ==========================
12-
platform darwin -- Python 3.9.2, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
13-
metadata: {'Python': '3.9.2', 'Platform': 'macOS-10.14.6-x86_64-i386-64bit', 'Packages': {'pytest': '6.2.4', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.0.1', 'rerunfailures': '10.0', 'xdist': '2.2.1', 'metadata': '1.11.0', 'ordering': '0.6', 'forked': '1.3.0', 'seleniumbase': '1.63.10'}}
14-
rootdir: /Users/michael/github/SeleniumBase/examples, configfile: pytest.ini
15-
plugins: html-2.0.1, rerunfailures-10.0, xdist-2.2.1, metadata-1.11.0, ordering-0.6, forked-1.3.0, seleniumbase-1.63.10
16-
collected 4 items
11+
=========================== test session starts ============================
12+
platform darwin -- Python 3.11.2, pytest-7.4.0, pluggy-1.2.0 -- /Users/michael/.virtualenvs/sb_venv/bin/python
13+
metadata: {'Python': '3.11.2', 'Platform': 'macOS-13.2.1-arm64-arm-64bit', 'Packages': {'pytest': '7.4.0', 'pluggy': '1.2.0'}, 'Plugins': {'html': '2.0.1', 'rerunfailures': '12.0', 'metadata': '3.0.0', 'ordering': '0.6', 'xdist': '3.3.1', 'seleniumbase': '4.15.10'}}
14+
rootdir: /Users/michael/github/SeleniumBase/examples
15+
configfile: pytest.ini
16+
plugins: html-2.0.1, rerunfailures-12.0, metadata-3.0.0, ordering-0.6, xdist-3.3.1, seleniumbase-4.15.10
17+
collected 4 items
1718

1819
example_test.py::AngularJSHomePageTests::test_greet_user PASSED
1920
example_test.py::AngularJSHomePageTests::test_todo_list PASSED
2021
input_test.py::AngularMaterialInputTests::test_invalid_input PASSED
2122
mat_paginator_test.py::AngularMaterialPaginatorTests::test_pagination PASSED
2223

23-
========================== 4 passed in 10.34s ==========================
24+
============================ 4 passed in 4.24s =============================
2425
```

0 commit comments

Comments
 (0)