You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**WebDriver automation simplified by extending Python's unittest framework.**
4
4
5
5
[](https://pypi.python.org/pypi/seleniumbase)[](https://travis-ci.org/seleniumbase/SeleniumBase)[](https://gitter.im/seleniumbase/SeleniumBase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
6
7
-
SeleniumBase simplifies web automation & testing with WebDriver in the same way that jQuery, AnglularJS, and ReactJS simplify web development with JavaScript. All tests using SeleniumBase's BaseCase class inherit Python's unittest.TestCase class, which allows for running tests automatically with Pytest and Nosetest. This framework can use the Page Object Model for test structure, as well as all features of WebDriver and Python's unittest.
7
+
SeleniumBase simplifies web automation & testing with WebDriver in the same way that jQuery, AnglularJS, and ReactJS simplify web development with JavaScript. All tests using SeleniumBase's BaseCase class inherit Python's unittest.TestCase class, allowing users to run tests automatically with Pytest and Nose. Tests can use the Page Object Model for structure, as well as all features of Python and WebDriver.
(<i>If no browser is specified, Chrome is used by default.</i>)
108
106
@@ -147,14 +145,14 @@ Here are some other useful nosetest arguments for appending to your run commands
147
145
--with-id # If -v is also used, will number the tests for easy counting.
148
146
```
149
147
150
-
The ``--with-testing_base`` plugin gives you full logging on test failures, which saves screenshots, page source, and basic test info into the logs folder:
148
+
During test failures you'll get detailed log files, which include screenshots, page source, and basic test info, which will get added to the logs folder at ``latest_logs/``. (Unless you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), log files with be cleaned up at the start of the next test run. If the archive feature is enabled, those logs will get saved to the ``archived_logs/`` folder.) The ``my_test_suite.py`` collection contains tests that fail on purpose so that you can see how logging works.
If you want to run tests headlessly, use ``--headless``, which you'll need to do if your system lacks a GUI interface. Even if your system does have a GUI interface, it may still support headless browser automation.
@@ -165,6 +163,7 @@ For running tests outside of the SeleniumBase repo with **Nosetests**, you'll wa
165
163
166
164
If you want to pass additional data from the command line to your tests, you can use ``--data=STRING``. Now inside your tests, you can use ``self.data`` to access that.
167
165
166
+
To run Pytest multithreaded on multiple CPUs at the same time, add ``-n NUM`` on the command line, where NUM is the number of CPUs you want to use.
168
167
169
168
<aid="creating_visual_reports"></a>
170
169
### **Creating Visual Test Suite Reports:**
@@ -179,22 +178,42 @@ Using ``--html=report.html`` gives you a fancy report of the name specified afte
179
178
pytest my_test_suite.py --html=report.html
180
179
```
181
180
181
+
You can also use ``--junitxml=report.xml`` to get an xml report instead. Jenkins can use this file to display better reporting for your tests.
The ``--report`` option gives you a fancy report after your test suite completes. (Requires ``--with-testing_base`` to also be set when ``--report`` is used because it's part of that plugin.)
191
+
The ``--report`` option gives you a fancy report after your test suite completes.
(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.)
194
199
195
200
201
+
### **Using a Proxy Server:**
202
+
203
+
If you wish to use a proxy server for your browser tests (Chrome and Firefox only), you can add ``--proxy=IP_ADDRESS:PORT`` as an argument on the command line.
204
+
205
+
```bash
206
+
pytest proxy_test.py --proxy=IP_ADDRESS:PORT
207
+
```
208
+
209
+
To make things easier, you can add your frequently-used proxies to PROXY_LIST in [proxy_list.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/proxy_list.py), and then use ``--proxy=KEY_FROM_PROXY_LIST`` to use the IP_ADDRESS:PORT of that key.
210
+
211
+
```bash
212
+
pytest proxy_test.py --proxy=proxy1
213
+
```
214
+
196
215
<aid="utilizing_advanced_features"></a>
197
-
### **Using Production Environments & Integrations:**
(NOTE: If you haven't configured your MySQL or S3 connections in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), don't use ``--with-db_reporting`` or ``--with-s3_logging``.)
223
242
@@ -237,7 +256,7 @@ If you tell nosetests to run an entire file, it will run every method in that py
You'll notice that a logs folder, "latest_logs", was created to hold information about the failing test, and screenshots. Take a look at what you get. Remember, this data can be saved in your MySQL DB and in S3 if you include the necessary plugins in your run command (and if you set up the neccessary connections properly). For future test runs, past test results will get stored in the archived_logs folder if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py).
@@ -500,29 +520,29 @@ self.click("a.analytics") # Clicks the generated button
500
520
```
501
521
(Due to popular demand, this traffic generation example has been baked into SeleniumBase with the ``self.generate_referral(start_page, end_page)`` and the ``self.generate_traffic(start_page, end_page, loops)`` methods.)
502
522
503
-
#### Using non-terminating verifications:
523
+
#### Using delayed asserts:
504
524
505
-
Let's say you want to verify multiple different elements on a web page in a single test, but you don't want the test to fail until you verified several elements at once so that you don't have to rerun the test to find more missing elements on the same page. That's where page checks come in. Here's the example:
525
+
Let's say you want to verify multiple different elements on a web page in a single test, but you don't want the test to fail until you verified several elements at once so that you don't have to rerun the test to find more missing elements on the same page. That's where delayed asserts come in. Here's the example:
self.delayed_assert_element('a[name="Super Fake !!!"]') # Will Fail
541
+
self.process_delayed_asserts()
522
542
```
523
543
524
-
``check_assert_element()`` and ``check_assert_text()`` will save any exceptions that would be raised.
525
-
To flush out all the failed checks into a single exception, make sure to call ``self.process_checks()`` at the end of your test method. If your test hits multiple pages, you can call ``self.process_checks()`` at the end of all your checks for a single page. This way, the screenshot from your log file will make the location where the checks were made.
544
+
``delayed_assert_element()`` and ``delayed_assert_text()`` will save any exceptions that would be raised.
545
+
To flush out all the failed delayed asserts into a single exception, make sure to call ``self.process_delayed_asserts()`` at the end of your test method. If your test hits multiple pages, you can call ``self.process_delayed_asserts()`` at the end of all your delayed asserts for a single page. This way, the screenshot from your log file will have the location where the delayed asserts were made.
Copy file name to clipboardExpand all lines: examples/ReadMe.md
+6-16Lines changed: 6 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@ python gui_test_runner.py
12
12
13
13
(NOTE: You can interchange ``nosetests`` with ``pytest`` in most of these examples.)
14
14
15
-

15
+
<imgsrc="https://cdn2.hubspot.net/hubfs/100006/images/The_GUI_Runner.png"title="GUI Test Runner"height="400">
16
16
17
-
If you run scripts with logging enabled, (using ``--with-testing_base``), you’ll see two folders appear: “latest_logs” and “archived_logs”. The “latest_logs” folder will contain log files from the most recent test run, but logs will only be created if the test run is failing. Afterwards, logs from the “latest_logs” folder will get pushed to the “archived_logs” folder if you have have the ``ARCHIVE_EXISTING_LOGS`` feature enabled in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py).
17
+
When you run tests, you’ll see two folders appear: “latest_logs” and “archived_logs”. The “latest_logs” folder will contain log files from the most recent test run, but logs will only be created if the test run is failing. Afterwards, logs from the “latest_logs” folder will get pushed to the “archived_logs” folder if you have have the ``ARCHIVE_EXISTING_LOGS`` feature enabled in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py).
18
18
19
19
**For running scripts the usual way, here are some of the example run commands:**
20
20
@@ -28,29 +28,19 @@ Run the example test in Firefox:
28
28
pytest my_first_test.py --browser=firefox
29
29
```
30
30
31
-
Run the example test in PhantomJS:
32
-
```bash
33
-
pytest my_first_test.py --browser=phantomjs
34
-
```
35
-
36
31
Run the example test in Demo Mode (runs slower and adds highlights):
0 commit comments