From 0d2a645611168965a22d1e273066e94592d118ba Mon Sep 17 00:00:00 2001
From: Michael Mintz SeleniumBase - Table of Contents: Run test_demo_site.py from examples/ ( Example: test_coffee_cart.py from SeleniumBase/examples/ ( Run test_swag_labs.py from examples/ using Demo Mode: 💡 SeleniumBase includes desktop GUI apps for running tests, such as SeleniumBase Commander for 💡 SeleniumBase has its own Recorder & Test Generator that can create tests from manual browser actions. SeleniumBase also has many other useful tools and console scripts for getting things done quickly. (See the documentation for more details!) 📘📝 An example test with the BaseCase class. Runs with pytest or nosetests. (Learn more) Here's the code for my_first_test.py: ✅ SeleniumBase automatically handles common WebDriver actions such as launching web browsers before tests, saving screenshots during failures, and closing web browsers after tests.
-
+SeleniumBase
- Python Web-UI Testing Made EasySeleniumBase: Enterprise Python Web Testing
@@ -53,41 +53,18 @@
--------
-
-
-
---------
---chrome
is the default browser):--demo
slows the test with highlighting for better visibility.)pytest
, and SeleniumBase Behave GUI.Here are a few scripts to test that app with SeleniumBase:
+ ▶️ Learn about different ways of writing tests (click to expand)
+ Set up Python & Git:
@@ -192,7 +177,7 @@ Feature: SeleniumBase scenarios for the RealWorld App
🔵 Using a Python virtual env is recommended.
- Install SeleniumBase:
+ Install SeleniumBase:
**You can install ``seleniumbase`` from [GitHub](https://github.com/seleniumbase/SeleniumBase) or [PyPI](https://pypi.org/project/seleniumbase/):**
@@ -275,7 +260,7 @@ COMMANDS:
```
- Downloading web drivers:
+ Downloading web drivers:
✅ SeleniumBase automatically downloads web drivers as needed, such as ``chromedriver``, ``edgedriver``, and ``geckodriver``.
@@ -283,7 +268,7 @@ COMMANDS:
- Basic Example & Usage:
+ Basic Example & Usage:
🔵 If you've cloned SeleniumBase, you can run tests from the [examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder.
@@ -296,7 +281,7 @@ pytest my_first_test.py
> (Uses ``--chrome`` by default.)
-
+
Here are some common SeleniumBase methods that you might find in tests:
+ Here are some common SeleniumBase methods that you might find in tests:
```python
self.open(url) # Navigate the browser window to the URL.
@@ -375,7 +360,7 @@ self.assert_no_js_errors() # Verify there are no JS errors.
- Fun Facts / Learn More:
+ Fun Facts / Learn More:
Detailed Instructions:
+ Detailed Instructions:
🔵 Demo Mode helps you see what a test is doing. If a test is moving too fast for your eyes, run it in Demo Mode, which pauses the browser briefly between actions, highlights page elements being acted on, and displays assertions:
@@ -586,7 +571,7 @@ Here's the command-line option to add to tests: (See [examples/custom_settings.p
Inside your tests, you can use ``self.data`` to access that.
- Test Directory Configuration:
+ Test Directory Configuration:
🔵 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.
@@ -642,7 +627,7 @@ Of those files, the ``pytest.ini`` config file is the most important, followed b
--------
- Log files from failed tests:
+ Log files from failed tests:
Let's try an example of a test that fails:
@@ -667,7 +652,7 @@ pytest test_fail.py
--------
- The SeleniumBase Dashboard:
+ The SeleniumBase Dashboard:
🔵 The ``--dashboard`` option for pytest generates a SeleniumBase Dashboard located at ``dashboard.html``, which updates automatically as tests run and produce results. Example:
@@ -696,7 +681,7 @@ pytest test_suite.py --dashboard --rs --headless
--------
- Generating Test Reports:
+ Generating Test Reports:
Pytest Reports:
@@ -771,7 +756,7 @@ pytest test_suite.py --alluredir=allure_results
```
- Using a Proxy Server:
+ Using a Proxy Server:
If you wish to use a proxy server for your browser tests (Chromium or Firefox), you can add ``--proxy=IP_ADDRESS:PORT`` as an argument on the command line.
@@ -800,7 +785,7 @@ pytest proxy_test.py --proxy=proxy1
```
- Changing the User-Agent:
+ Changing the User-Agent:
🔵 If you wish to change the User-Agent for your browser tests (Chromium and Firefox only), you can add ``--agent="USER AGENT STRING"`` as an argument on the command-line.
@@ -809,12 +794,12 @@ pytest user_agent_test.py --agent="Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1
```
- Handling Pop-Up / Pop Up Alerts:
+ Handling Pop-Up / Pop Up Alerts:
🔵 self.accept_alert()
automatically waits for and accepts alert pop-ups. self.dismiss_alert()
automatically waits for and dismisses alert pop-ups. On occasion, some methods like self.click(SELECTOR)
might dismiss a pop-up on its own because they call JavaScript to make sure that the readyState
of the page is complete
before advancing. If you're trying to accept a pop-up that got dismissed this way, use this workaround: Call self.find_element(SELECTOR).click()
instead, (which will let the pop-up remain on the screen), and then use self.accept_alert()
to accept the pop-up (more on that here). If pop-ups are intermittent, wrap code in a try/except block.
- Building Guided Tours for Websites:
+ Building Guided Tours for Websites:
🔵 Learn about SeleniumBase Interactive Walkthroughs (in the ``examples/tour_examples/`` folder). It's great for prototyping a website onboarding experience.
@@ -824,7 +809,7 @@ pytest user_agent_test.py --agent="Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1
--------
- Production Environments & Integrations:
+ Production Environments & Integrations:
Detailed Method Specifications and Examples:
+ Detailed Method Specifications and Examples:
🔵 Navigating to a web page: (and related commands)
@@ -1059,7 +1044,7 @@ If the web page you're on already has jQuery loaded, you can start executing jQu
You'd know this because the web page would contain something like the following in the HTML:
You can use the @retry_on_exception()
decorator to retry failing methods. (First import: from seleniumbase import decorators
). To learn more about SeleniumBase decorators, click here.
BaseCase
is imported at the top of a Python file, followed by a Python class inheriting BaseCase
. Then, any test method defined in that class automatically gains access to SeleniumBase methods, including the setUp()
and tearDown()
methods that are automatically called for opening and closing web browsers at the start and end of tests.
-To run a test of this format, use **``pytest``** or ``nosetests``. If you add: ``if __name__ == "__main__":`` ``pytest.main([__file__])`` to a file, you can also use ``python`` as a runner, which invokes ``pytest``. Here's an example:
+To run a test of this format, use **``pytest``** or ``nosetests``. If you add: ``if __name__ == "__main__":`` ``pytest.main([__file__])`` to a file, you can also use ``python`` as a test runner, which invokes ``pytest``. Here's an example:
```python
from seleniumbase import BaseCase
@@ -60,13 +60,15 @@ class MyTestClass(BaseCase):
self.assert_exact_text("Demo Page", "h1")
self.assert_no_js_errors()
-if __name__ == "__main__": # Use "python" to call "pytest"
+if __name__ == "__main__":
from pytest import main
- main([__file__])
+ main([__file__, "-s"])
```
(See examples/test_demo_site.py for the full test.)
+Starting with ``seleniumbase`` ``4.11.0``, you can also include ``BaseCase.main(__name__, __file__)`` in your script to invoke ``pytest`` via ``python``. (Eg. [coffee_cart_tests.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/coffee_cart_tests.py))
+
Using ``BaseCase`` inheritance is a great starting point for anyone learning SeleniumBase, and it follows good object-oriented programming principles.
diff --git a/mkdocs_build/img/logo7.png b/mkdocs_build/img/logo7.png
new file mode 100644
index 0000000000000000000000000000000000000000..a99178a232b27e596da71191a96ca6dc501cacc5
GIT binary patch
literal 510
zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLGH$#^NA%Cx&(BWL^R}7O4@QX}-P;
zT0k}j17mw80}DtA5K93u0|V0nCb)>h0%imoB$+xhp$n+E#M8wwB!l&Bs9_dUpn$1b
zSQ1afk?x9yEpZ2qDVa?==48+@^@gO=27!Z@4yl<3te+74MCNt}$Lasw#wYf@uMxi&
z_J9A~ndZOm@q9LT8f(4S&|9OxSS!V0x2!3im^)B*_;H%jD&J*$a3#@{}-K=I_5I7CFJSdHRa<
z1n!r=?)=l0-LdzWRkQh#-e+