|
1 | 1 | # Codebender Selenium Tests
|
2 | 2 |
|
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 |
| 4 | +written in Python 2, and utilize pytest as a testing framework and Selenium |
5 | 5 | for browser automation.
|
6 | 6 |
|
7 | 7 | ## Running Tests
|
8 | 8 |
|
9 |
| -### Dependencies |
| 9 | +Tests are run by invoking `tox`. Run `tox --help` to see all the |
| 10 | +Codebender-specific arguments that can be passed to `py.test`. |
10 | 11 |
|
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. |
| 12 | +In addition to these arguments, there are certain environment variables that |
| 13 | +should be set when running tests: |
14 | 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). |
| 15 | +- `CODEBENDER_SELENIUM_HUB_URL`: the URL of the Selenium Hub. If you are using |
| 16 | + SauceLabs, the URL has the following format: |
| 17 | + `http://{USERNAME}:{ACCESS_KEY}@ondemand.saucelabs.com:80/wd/hub`. You can |
| 18 | + also use a [docker-selenium](https://github.com/SeleniumHQ/docker-selenium) |
| 19 | + hub. In that case, it is necessary to link the docker-selenium instance to the |
| 20 | + Docker instance from which tests are running. |
| 21 | +- `CODEBENDER_TEST_USER`: username that the webdriver will use to log into the |
| 22 | + site in order to perform tests. |
| 23 | +- `CODEBENDER_TEST_PASS`: password for `CODEBENDER_TEST_USER`. |
20 | 24 |
|
21 |
| -To install `pip` in Ubuntu, run `$ sudo apt-get install python3 |
22 |
| -python3-setuptools`, then `$ sudo easy_install3 pip`. |
| 25 | +Rather than invoking `tox` directly, the easiest way to run tests is with |
| 26 | +Docker. If you are not familiar with Docker, please consult the |
| 27 | +[documentation](http://docs.docker.com/) for an introduction. |
23 | 28 |
|
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`. |
| 29 | +First, build the image with `$ docker build . -t codebender/selenium`. |
27 | 30 |
|
28 |
| -### Invoking Tests via `tox` |
| 31 | +Then invoke `tox` via `docker run`. Here is a sample command to run all tests, |
| 32 | +where the Codebender server is running at `http://192.168.1.2:8080`: |
29 | 33 |
|
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. |
| 34 | +``` |
| 35 | +$ docker run -e CODEBENDER_SELENIUM_HUB_URL=http://johndoe:[email protected]:80/wd/hub \ |
| 36 | + -e CODEBENDER_TEST_USER=tester \ |
| 37 | + -e CODEBENDER_TEST_PASS=1234 \ |
| 38 | + -it codebender/selenium \ |
| 39 | + tox -- --url http://192.168.1.2:8080 --source bachelor |
| 40 | +``` |
32 | 41 |
|
33 |
| -You can also run individual tests by providing the appropriate directory or |
34 |
| -filename as an argument, for example: `$ tox tests/sketch`. |
| 42 | +### Running Tests Manually |
35 | 43 |
|
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`. |
| 44 | +The recommended way of running tests is with Docker. If you would like to |
| 45 | +manually provision your machine to be able to run tests, you can use the |
| 46 | +Dockerfile as a step-by-step guide for provisioning. Then invoke `tox` to run |
| 47 | +tests. |
39 | 48 |
|
40 | 49 | #### Specifying a URL for Tests
|
41 | 50 |
|
@@ -105,6 +114,11 @@ The most important class is `SeleniumTestCase`, which all of the unit test cases
|
105 | 114 | inherit from. This grants them access (via `self`) to a number of methods and
|
106 | 115 | attributes that are useful for performing codebender-specific actions.
|
107 | 116 |
|
| 117 | +**`codebender_testing/capabilities.yaml`** defines a list of `capabilities` to |
| 118 | +be passed as arguments when instantiating remote webdrivers. In particular, it |
| 119 | +specifies the web browsers that we would like to use. Consult this file for more |
| 120 | +information. |
| 121 | + |
108 | 122 | #### `batch/`
|
109 | 123 |
|
110 | 124 | The `batch/` directory contains any executable scripts not directly used to
|
|
0 commit comments