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
(<i>Above: [my_first_test.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) from [examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) running in demo mode, which adds JavaScript for highlighting page actions.</i>)<br />
9
-
```
10
+
```bash
10
11
pytest my_first_test.py --demo_mode
11
12
```
12
13
13
14
SeleniumBase is an all-in-one test automation framework that uses WebDriver APIs for spinning up web browsers while using pytest and nosetests for running tests.
You'll need **[Python](https://www.python.org/downloads/)**[<imgsrc="https://img.shields.io/badge/python-2.7,_3.5,_3.6,_3.7-22AADD.svg"alt="Python versions" />](https://www.python.org/downloads/)
18
+
You'll need **[Python](https://www.python.org/downloads/)**[<imgsrc="https://img.shields.io/badge/python-2.7,_3.5,_3.6,_3.7+-22AADD.svg"alt="Python versions" />](https://www.python.org/downloads/)
With Python installed and on your System PATH, you can get the latest ``pip`` with:
22
-
```
23
+
```bash
23
24
python -m easy_install -U pip
24
25
```
25
26
@@ -28,14 +29,14 @@ python -m easy_install -U pip
28
29
You may want to use a **Python Virtual Environment** to isolate Python dependencies between projects. (The Seleniumbase virtualenv tutorial can be found **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/virtualenv_instructions.md)**, and the official virtualenv tutorial can be found **[here](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)**.)
### <imgsrc="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png"title="SeleniumBase"height="32"> Download a web driver:
52
53
53
54
SeleniumBase can download a web driver to the [seleniumbase/drivers](https://github.com/seleniumbase/SeleniumBase/tree/master/seleniumbase/drivers) folder with the ``install`` command:
54
-
```
55
+
```bash
55
56
seleniumbase install chromedriver
56
57
```
57
58
* You need a different web driver for each web browser you want to run automation on: ``chromedriver`` for Chrome, ``edgedriver`` for Edge, ``geckodriver`` for Firefox, ``operadriver`` for Opera, and ``iedriver`` for Internet Explorer.
58
59
59
60
### <imgsrc="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png"title="SeleniumBase"height="32"> Run a test on Chrome:
If the example test is moving too fast for your eyes, you can run it in **Demo Mode** by adding ``--demo_mode`` on the command line, which pauses the browser briefly between actions, highlights page elements being acted on, and lets you know what test assertions are happening in real time:
The code above will leave your browser window open in case there's a failure. (ipdb commands: 'c', 's', 'n' => continue, step, next).
154
155
155
-
Here are some other useful **nosetest**-specific arguments:
156
-
156
+
Here are some other useful arguments:
157
+
```bash
158
+
-v # Prints the full test name rather than a dot for each test.
159
+
-x # Stop running the tests after the first failure is reached.
157
160
```
161
+
162
+
Here's a **nosetests**-specific argument:
163
+
```bash
158
164
--logging-level=INFO # Hide DEBUG messages, which can be overwhelming.
159
-
-x # Stop running the tests after the first failure is reached.
160
-
-v # Prints the full test name rather than a dot for each test.
161
-
--with-id # If -v is also used, will number the tests for easy counting.
162
165
```
163
166
164
167
During test failures, logs and screenshots from the most recent test run will get saved to the ``latest_logs/`` folder. Those logs will get moved to ``archived_logs/`` if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), otherwise log files with be cleaned up at the start of the next test run. The ``test_suite.py`` collection contains tests that fail on purpose so that you can see how logging works.
165
168
166
-
```
169
+
```bash
167
170
cd examples/
168
171
169
172
pytest test_suite.py --browser=chrome
@@ -183,7 +186,7 @@ For running tests outside of the SeleniumBase repo with **Pytest**, you'll want
183
186
184
187
As a shortcut, you'll be able to run ``seleniumbase mkdir [DIRECTORY_NAME]`` to create a new folder that already contains necessary files and some example tests that you can run. Example:
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.
228
231
229
-
```
232
+
```bash
230
233
pytest proxy_test.py --proxy=IP_ADDRESS:PORT
231
234
```
232
235
233
236
If the proxy server that you wish to use requires authentication, you can do the following (Chrome only):
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.
240
243
241
-
```
244
+
```bash
242
245
pytest proxy_test.py --proxy=proxy1
243
246
```
244
247
@@ -268,7 +271,7 @@ Here are some things you can do to setup a production environment for your testi
268
271
269
272
* If you're using the [SeleniumBase MySQL feature](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/mysql_installation.md) to save results from tests running on a server machine, you can install [MySQL Workbench](https://dev.mysql.com/downloads/tools/workbench/) to help you read & write from your DB more easily. You'll also need to install the MySQL Python client. Depending on your system, you may need to install additional requirements for this (such as on Windows). See [Stackoverflow](https://stackoverflow.com/questions/43102442/whats-the-difference-between-mysqldb-mysqlclient-and-mysql-connector-python) for more info.
* If you're using AWS, you can setup an [Amazon S3](https://aws.amazon.com/s3/) account for saving your log files and screenshots for future viewing. SeleniumBase already has [all the code you need to connect to S3](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/s3_logging_plugin.py). You'll need to modify [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) with connection details to your instance and the location in S3 where you want log files to be saved. You'll also need to add "``--with-s3_logging``" on the command line when you run your tests.
279
282
280
283
Here's an example of running tests with additional features enabled:
(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``.)
@@ -287,15 +290,15 @@ When the testing_base plugin is used, if there's a test failure, the basic_test_
287
290
288
291
To simplify that long run command, you can create a ``*.cfg`` file, such as the one provided in the example, and enter your plugins there so that you can run everything by typing:
You can simplify that even more by using a setup.cfg file, such as the one provided for you in the examples folder. If you kick off a test run from within the folder that setup.cfg is location in, that file will automatically be used as your configuration, meaning that you wouldn't have to type out all the plugins that you want to use (or include a config file) everytime you run tests.
295
298
296
299
If you tell pytest/nosetests to run an entire file, it will run every method in that python file that starts with "test". You can be more specific on what to run by doing something like the following: (<i>Note that the syntax is different for pytest vs nosetests.</i>)
Additionally, you can use the ``@retry_on_exception()`` decorator to specifically retry failing methods. (First import: ``from seleniumbase import decorators``) To learn more about SeleniumBase decorators, [click here](https://github.com/seleniumbase/SeleniumBase/tree/master/seleniumbase/common).
613
616
614
-
#### Checking Email:
617
+
#### Email Testing / Checking Email:
615
618
Let's say you have a test that sends an email, and now you want to check that the email was received:
616
619
617
620
```python
618
621
from seleniumbase.fixtures.email_manager import EmailManager, EmailException
619
622
num_email_results =0
620
623
email_subject ="This is the subject to search for (maybe include a timestamp)"
621
-
email_manager = EmailManager("{YOUR SELENIUM GMAIL ACCOUNT EMAIL ADDRESS}") # the password for this would be stored in seleniumbase/config/settings.py
(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.)
158
158
159
-
Here are some other useful **nosetest**-specific arguments:
159
+
Here are some other useful arguments:
160
+
```bash
161
+
-v # Prints the full test name rather than a dot for each test.
162
+
-x # Stop running the tests after the first failure is reached.
163
+
```
160
164
165
+
Here's a **nosetests**-specific argument:
161
166
```bash
162
167
--logging-level=INFO # Hide DEBUG messages, which can be overwhelming.
163
-
-x # Stop running the tests after the first failure is reached.
164
-
-v # Prints the full test name rather than a dot for each test.
165
-
--with-id # If -v is also used, will number the tests for easy counting.
0 commit comments