|
1 | 1 | # Codebender Selenium Tests
|
2 | 2 |
|
3 |
| -This repo contains Selenium tests for the codebender website. |
4 |
| -The tests are written in Python 3. |
| 3 | +This repo contains Selenium tests for the codebender website. The tests are |
| 4 | +written in Python 3, and utilize pytest as a testing framework and Selenium |
| 5 | +for browser automation. |
5 | 6 |
|
6 | 7 | ## Running Tests
|
7 | 8 |
|
8 |
| -To run tests locally, you'll need to be running a selenium server. See |
9 |
| -[here](https://selenium-python.readthedocs.org/installation.html#downloading-selenium-server) |
10 |
| -for instructions. |
| 9 | +### Dependencies |
11 | 10 |
|
12 |
| -Once you've got a Selenium server running, simply run `$ tox` from within the |
13 |
| -repo. If you don't have tox, run `$ sudo pip3 install -r requirements-dev.txt` |
14 |
| -from within the repo to install it. |
| 11 | +To run these tests, you'll need to have Python 3 installed. In addition, it is |
| 12 | +advantageous to have pip, a package manager for Python, in order to install |
| 13 | +dependencies. |
| 14 | + |
| 15 | +Notably, the pip2 (for Python 2) and pip3 (for Python 3) packages both attempt |
| 16 | +to link `/usr/local/bin/pip` to the `pip2` or `pip3` executable, respectively. |
| 17 | +To deal with this, you could explicitly type out `pip3` or `pip2` instead of |
| 18 | +`pip` whenever you use pip via the command line. (It may be best to just remove |
| 19 | +`/usr/local/bin/pip` entirely). |
| 20 | + |
| 21 | +To install `pip` in Ubuntu, run `$ sudo apt-get install python3 |
| 22 | +python3-setuptools`, then `$ sudo easy_install3 pip`. |
| 23 | + |
| 24 | +After getting set up with pip and cloning the seleniumTests repo, you should |
| 25 | +make sure to install all the seleniumTests dependencies by `cd`ing to your local |
| 26 | +clone of the repo and running `$ sudo pip3 install -r requirements-dev.txt`. |
| 27 | + |
| 28 | +### Invoking Tests via `tox` |
| 29 | + |
| 30 | +After installing dependencies, you should have the `tox` command available. To |
| 31 | +run all of the tests, you can simply run `$ tox` from within the cloned repo. |
| 32 | + |
| 33 | +You can also run individual tests by providing the appropriate directory or |
| 34 | +filename as an argument, for example: `$ tox tests/sketch`. |
| 35 | + |
| 36 | +Invoking tox will also run `flake8`, which is essentially a lint checker for |
| 37 | +Python. It is best to fix any issues reported by `flake8` before committing |
| 38 | +to the repo. It can be run on its own via the command `$ flake8`. |
| 39 | + |
| 40 | +#### Specifying a URL for Tests |
| 41 | + |
| 42 | +Tests can either be run for the |
| 43 | +[bachelor](https://github.com/codebendercc/bachelor) version of the site, |
| 44 | +running locally, or for the live site. The version of the site that is running |
| 45 | +is inferred from the `--url` parameter. You can run `$ tox --url |
| 46 | +http://localhost` to run the tests for a locally running bachelor site (this is |
| 47 | +the default url), or `$ tox --url http://codebender.cc` to run the tests for the |
| 48 | +live site. |
| 49 | + |
| 50 | +Certain tests are specially written for one site or the other. This is |
| 51 | +implemented with a custom `pytest` marker. Tests that require a certain `--url` |
| 52 | +are decorated with `@pytest.mark.requires_url(<url>)`. |
| 53 | + |
| 54 | +### Changing Test Configuration |
| 55 | + |
| 56 | +Various global configuration parameters are specified in |
| 57 | +`codebender_testing/config.py`. Such parameters include URLs and site endpoints |
| 58 | +which are subject to change. This is also where the webdrivers (Firefox and |
| 59 | +Chrome) are specified. |
| 60 | + |
| 61 | +## Compilation Logs |
| 62 | + |
| 63 | +Certain tests exist to iterate through groups of sketches and compile them |
| 64 | +one-by-one. Since these tests take a long time, they are not run in full by |
| 65 | +default. You can run them by specifying the `--full` option; for example: `$ tox |
| 66 | +tests/cb_compile_tester --full`. |
| 67 | + |
| 68 | +The following test cases are compile tests that generate such logs: |
| 69 | +- `tests/libraries/test_libraries.py::TestLibraryExamples` |
| 70 | +- `tests/compile_tester/test_compile_tester_projects.py::TestCompileTester` |
| 71 | + |
| 72 | +The generated logs are placed in the `logs` directory. They give detailed output |
| 73 | +in JSON format containing the codebender site URL that was used to run the |
| 74 | +tests, along with the URLs of the individual sketches that were compiled, and |
| 75 | +whether they succeeded or failed to compile. |
| 76 | + |
| 77 | +## Framework Overview |
| 78 | + |
| 79 | +The following outlines the structure of the repository as well as important |
| 80 | +framework components. |
| 81 | + |
| 82 | +### Directory Structure |
| 83 | + |
| 84 | +#### `tests/` |
| 85 | + |
| 86 | +The `tests/` directory contains all of the actual unit tests for the codebender |
| 87 | +site. That is, all of the tests discovered by `py.test` should come from this |
| 88 | +directory. |
| 89 | + |
| 90 | +**`tests/conftest.py`** contains the global configuration for pytest, |
| 91 | +including specifying the webdriver fixtures as well as the available command |
| 92 | +line arguments. |
| 93 | + |
| 94 | +#### `codebender_testing/` |
| 95 | + |
| 96 | +This is where all major components of the testing framework live. All of the |
| 97 | +unit tests rely on the files in this directory. |
| 98 | + |
| 99 | +**`codebender_testing/config.py`** specifies global configuration parameters for |
| 100 | +testing (see "Changing Test Configuration" above). |
| 101 | + |
| 102 | +**`codebender_testing/utils.py`** defines codebender-specific utilities used to |
| 103 | +test the site. These mostly consist of abstractions to the Selenium framework. |
| 104 | +The most important class is `SeleniumTestCase`, which all of the unit test cases |
| 105 | +inherit from. This grants them access (via `self`) to a number of methods and |
| 106 | +attributes that are useful for performing codebender-specific actions. |
| 107 | + |
| 108 | +#### `batch/` |
| 109 | + |
| 110 | +The `batch/` directory contains any executable scripts not directly used to |
| 111 | +perform tests. For example, it contains a script `fetch_projects.py` which can |
| 112 | +be used to download all of the public projects of a particular codebender user. |
| 113 | + |
| 114 | +#### `extensions/` |
| 115 | + |
| 116 | +The `extensions/` directory contains the codebender browser extensions to be |
| 117 | +used by the Selenium webdrivers. |
| 118 | + |
| 119 | +#### `test_data/` |
| 120 | + |
| 121 | +The `test_data/` directory contains any data used for testing. For example, it |
| 122 | +contains example projects that we should successfully be able to upload and |
| 123 | +compile. |
| 124 | + |
| 125 | +#### `logs/` |
| 126 | + |
| 127 | +The `logs/` directory contains the results of running certain tests, e.g. |
| 128 | +whether certain sets of sketches have compiled successfully (see "Compilation |
| 129 | +Logs"). |
15 | 130 |
|
0 commit comments