2021-11-01 01:20:46 +08:00
< h3 align = "center" > < a href = "https://github.com/seleniumbase/SeleniumBase/" > < img src = "https://seleniumbase.io/cdn/img/sb_logo_10t.png" alt = "SeleniumBase" title = "SeleniumBase" width = "240" > < / a > < / h3 >
2020-05-12 10:15:19 +08:00
2020-12-18 14:25:31 +08:00
< h2 > < img src = "https://seleniumbase.io/img/logo6.png" title = "SeleniumBase" width = "32" / > Running Example Tests:< / h2 >
2019-10-27 14:25:53 +08:00
2021-10-18 13:49:29 +08:00
< p align = "left" > < a align = "center" href = "https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_demo_site.py" > < img align = "center" src = "https://seleniumbase.io/cdn/img/sb_demo_page.png" alt = "SeleniumBase Demo Page" width = "420" / > < / a > < / p >
2016-02-03 16:29:11 +08:00
2020-11-06 09:43:04 +08:00
* < b > SeleniumBase</ b > tests are run with < b > pytest</ b > .
2020-12-24 11:03:53 +08:00
* Chrome is the default browser if not specified.
2021-09-29 15:21:58 +08:00
* Tests are structured using [17 unique syntax formats ](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md ).
* Logs from test failures are saved to ``./latest_logs/``.
* Tests can be run with [multiple command-line options ](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md ).
* Example tests are found in: ** [SeleniumBase/examples/ ](https://github.com/seleniumbase/SeleniumBase/tree/master/examples )**.
2017-10-24 15:20:33 +08:00
2020-05-13 07:58:43 +08:00
(NOTE: Some example tests fail on purpose to demonstrate [logging features ](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md ).)
2020-05-11 04:06:21 +08:00
2020-12-27 10:03:17 +08:00
< h3 > < img src = "https://seleniumbase.io/img/logo6.png" title = "SeleniumBase" width = "32" / > Example tests with run commands to help you get started:< / h3 >
2016-02-03 16:29:11 +08:00
2019-12-15 14:10:37 +08:00
Run an example test in Chrome: (Default: ``--browser=chrome``)
2020-10-12 06:53:54 +08:00
2016-02-03 16:29:11 +08:00
```bash
2019-10-29 12:37:45 +08:00
pytest my_first_test.py
2016-02-03 16:29:11 +08:00
```
2019-12-15 14:10:37 +08:00
Run an example test in Firefox:
2020-10-12 06:53:54 +08:00
2016-02-03 16:29:11 +08:00
```bash
2017-10-24 15:20:33 +08:00
pytest my_first_test.py --browser=firefox
2016-02-03 16:29:11 +08:00
```
2019-12-15 14:10:37 +08:00
Run an example test in Demo Mode: (highlight assertions)
2020-10-12 06:53:54 +08:00
2016-02-03 16:29:11 +08:00
```bash
2019-12-03 13:23:18 +08:00
pytest my_first_test.py --demo
2016-05-19 09:46:35 +08:00
```
2020-10-12 06:53:54 +08:00
2021-10-02 11:55:06 +08:00
< img src = "https://seleniumbase.io/cdn/gif/my_first_test_2.gif" title = "SeleniumBase Demo Mode" / > < br / >
2016-05-19 09:46:35 +08:00
2020-05-20 14:01:43 +08:00
Run a different example in Demo Mode:
2020-10-12 06:53:54 +08:00
2020-05-20 14:01:43 +08:00
```bash
pytest test_swag_labs.py --demo
```
2020-10-12 06:53:54 +08:00
2021-10-02 11:55:06 +08:00
< img src = "https://seleniumbase.io/cdn/gif/swag_demo_3.gif" / > < br / >
2020-05-20 14:01:43 +08:00
2019-12-15 14:10:37 +08:00
Run an example test in Headless Mode: (invisible browser)
2020-10-12 06:53:54 +08:00
2019-07-07 08:13:32 +08:00
```bash
2019-12-10 12:30:02 +08:00
pytest my_first_test.py --headless
2019-07-07 08:13:32 +08:00
```
2020-05-11 05:01:01 +08:00
Run an example test using Chrome's mobile device emulator: (default settings)
2020-10-12 06:53:54 +08:00
2020-05-11 05:01:01 +08:00
```bash
pytest test_swag_labs.py --mobile
```
2020-10-12 06:53:54 +08:00
2020-11-12 13:57:20 +08:00
< img src = "https://seleniumbase.io/cdn/gif/swag_mobile_2.gif" title = "SeleniumBase Mobile Mode" / > < br / >
2020-05-11 05:01:01 +08:00
2019-12-15 14:10:37 +08:00
Run tests with verbose output: (includes more details)
2020-10-12 06:53:54 +08:00
2019-12-12 15:01:41 +08:00
```bash
pytest test_suite.py -v
```
2020-06-06 03:33:09 +08:00
Run a test on the Demo Site to try many SeleniumBase methods:
2020-10-12 06:53:54 +08:00
2020-06-06 03:33:09 +08:00
```bash
pytest test_demo_site.py
```
2020-10-12 06:53:54 +08:00
2021-10-23 04:27:08 +08:00
< img src = "https://seleniumbase.io/cdn/gif/demo_page_4.gif" title = "SeleniumBase Demo Page" / > < br / >
2020-06-06 03:33:09 +08:00
2019-12-15 14:10:37 +08:00
Run tests multi-threaded using [n] threads:
2020-10-12 06:53:54 +08:00
2016-05-21 12:04:37 +08:00
```bash
2020-12-20 03:46:03 +08:00
pytest test_suite.py -n=4
2016-05-21 12:04:37 +08:00
```
2019-12-15 14:10:37 +08:00
Run a parameterized test: (Generates multiple tests from one)
2020-10-12 06:53:54 +08:00
2017-03-14 10:23:36 +08:00
```bash
2019-12-12 15:01:41 +08:00
pytest parameterized_test.py -v
2017-03-14 10:23:36 +08:00
```
2020-12-20 03:46:03 +08:00
Run a test suite and generate a SeleniumBase Dashboard:
2020-10-12 06:53:54 +08:00
2016-02-03 16:29:11 +08:00
```bash
2020-12-20 03:46:03 +08:00
pytest test_suite.py --dashboard
```
Run a test suite and generate a pytest report:
```bash
pytest test_suite.py --html=report.html
2016-02-03 16:29:11 +08:00
```
2019-12-15 14:10:37 +08:00
Run a failing test: (See the ``latest_logs/`` folder for logs and screenshots)
2020-10-12 06:53:54 +08:00
2016-02-03 16:29:11 +08:00
```bash
2019-12-10 12:30:02 +08:00
pytest test_fail.py
2016-02-03 16:29:11 +08:00
```
2019-12-15 14:10:37 +08:00
Run a failing test with Debug-mode enabled: (``pdb`` activates on failures)
2020-10-12 06:53:54 +08:00
2016-02-03 16:29:11 +08:00
```bash
2019-07-07 08:13:32 +08:00
pytest test_fail.py --pdb -s
```
2019-12-15 14:10:37 +08:00
Run an example test suite that demonstrates the use of pytest markers:
2020-10-12 06:53:54 +08:00
2019-12-10 12:30:02 +08:00
```bash
2019-12-12 15:01:41 +08:00
pytest -m marker_test_suite -v
2019-12-10 12:30:02 +08:00
```
2019-12-15 14:10:37 +08:00
Run an example test suite that reuses the browser session between tests:
2020-10-12 06:53:54 +08:00
2019-12-03 13:23:18 +08:00
```bash
2020-12-20 03:46:03 +08:00
pytest test_suite.py --reuse-session
2019-12-03 13:23:18 +08:00
```
2019-12-15 14:10:37 +08:00
Run an example test demonstrating the ``rate_limited`` Python decorator:
2020-10-12 06:53:54 +08:00
2019-07-07 08:13:32 +08:00
```bash
2019-12-10 12:30:02 +08:00
pytest rate_limiting_test.py
2019-07-07 08:13:32 +08:00
```
2019-12-15 14:10:37 +08:00
Run an example test that demonstrates how to upload a file to a website:
2020-10-12 06:53:54 +08:00
2019-07-07 08:13:32 +08:00
```bash
pytest upload_file_test.py
2016-02-06 15:50:20 +08:00
```
2020-05-12 10:15:19 +08:00
--------
2020-10-03 09:11:27 +08:00
< b > SeleniumBase tests can also be run with ``nosetests``:< / b >
2020-05-12 10:15:19 +08:00
Run an example test with nosetests:
2020-10-12 06:53:54 +08:00
2020-05-12 10:15:19 +08:00
```bash
nosetests my_first_test.py
```
2020-12-20 03:46:03 +08:00
Run an example test suite and generate a nosetest report:
2020-10-12 06:53:54 +08:00
2019-12-10 12:30:02 +08:00
```bash
nosetests test_suite.py --report --show-report
```
2020-12-20 03:46:03 +08:00
Run an example test using a nosetest configuration file:
2020-10-12 06:53:54 +08:00
2019-12-10 12:30:02 +08:00
```bash
nosetests my_first_test.py --config=example_config.cfg
```
2021-05-23 02:15:36 +08:00
--------
2019-09-16 17:17:33 +08:00
For more advanced run commands, such as using a proxy server, see [../help_docs/customizing_test_runs.md ](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md )
2018-07-04 06:56:43 +08:00
2018-08-01 02:47:10 +08:00
--------
2021-10-02 11:55:06 +08:00
If you just need to perform some quick website verification on various devices, you can use the < a href = "https://seleniumbase.io/devices/" > SeleniumBase Device Farm< / a > . Just plug in a website URL, and it will display how the website looks on four different devices:
< a href = "https://seleniumbase.io/devices/" > < img src = "https://seleniumbase.io/cdn/img/github_demo.png" width = "540" title = "SeleniumBase Mobile Mode" / > < / a > < br / >
--------
2019-10-29 12:37:45 +08:00
To make things easier, here's a simple GUI program that allows you to run a few example tests by pressing a button:
2018-08-01 02:47:10 +08:00
```bash
python gui_test_runner.py
```
2020-10-12 06:53:54 +08:00
2020-11-12 13:57:20 +08:00
< img src = "https://seleniumbase.io/cdn/img/gui_test_runner.png" title = "GUI Test Runner" width = "320" / >
2019-12-30 13:58:39 +08:00
--------
2021-09-27 03:05:21 +08:00
< img src = "https://seleniumbase.io/cdn/img/super_logo_sb.png" title = "SeleniumBase" width = "320" / >
2020-05-20 02:13:17 +08:00
2020-05-13 07:58:43 +08:00
< a href = "https://github.com/seleniumbase/SeleniumBase" >
< img src = "https://img.shields.io/badge/tested%20with-SeleniumBase-04C38E.svg" alt = "Tested with SeleniumBase" / > < / a >