1 | # Building and Testing Protractor
|
2 |
|
3 | This document describes building, testing, releasing Protractor and provides an overview of
|
4 | the repository layout.
|
5 |
|
6 | ## Prerequisite software
|
7 |
|
8 | The prerequisite software (Node.js, npm, git, jdk) are the same as for angular. See
|
9 | https://github.com/angular/angular/blob/master/docs/DEVELOPER.md#prerequisite-software
|
10 |
|
11 | ## Getting the sources
|
12 |
|
13 | Fork Protractor from github, then clone your fork with:
|
14 |
|
15 | ```shell
|
16 | git clone git@github.com:<github username>/protractor.git
|
17 |
|
18 | # Go to the Protractor directory:
|
19 | cd protractor/
|
20 |
|
21 | # Add the main protractor repository as an upstream remote to your repository:
|
22 | git remote add upstream https://github.com/angular/protractor.git
|
23 | ```
|
24 |
|
25 | ## Installing and Building
|
26 |
|
27 | All Protractor dependencies come from npm. Install with:
|
28 |
|
29 | ```shell
|
30 | npm install
|
31 | ```
|
32 |
|
33 | This will also trigger our build step. The build step runs the TypeScript compiler
|
34 | and copies necessary files into the output `built` directory. To run the build step
|
35 | independently, run:
|
36 |
|
37 | ```shell
|
38 | npm run prepublish
|
39 | ```
|
40 |
|
41 | You can see the other available npm scripts in `package.json`. Note that most of these
|
42 | scripts just call our `gulp` commands, which can be seen in `gulpfile.js`.
|
43 |
|
44 | ## Formatting
|
45 |
|
46 | Protractor uses clang-format to format the source code. If the source code is not properly formatted,
|
47 | the CI will fail and the PR can not be merged.
|
48 |
|
49 | You can automatically format your code by running:
|
50 |
|
51 | ```shell
|
52 | npm run format
|
53 | ```
|
54 |
|
55 | You can check that you will pass lint tests with:
|
56 |
|
57 | ```shell
|
58 | gulp lint
|
59 |
|
60 | # or if you don't have gulp installed globally:
|
61 | ./node_modules/.bin/gulp lint
|
62 | ```
|
63 |
|
64 | ## Code layout
|
65 |
|
66 | `docs/` contains markdown documentation files.
|
67 | `lib/` contains the actual Protractor code.
|
68 | `scripts/` contains scripts used for CI setup and running tests.
|
69 | `spec/` contains e2e and unit tests and configuration files for tests.
|
70 | `testapp/` contains the code for the Angular applications that e2e tests run against.
|
71 | `website/` contains code for generating Protractor API documentation and the website at protractortest.org.
|
72 |
|
73 | Most of the code is written in TypeScript, with the exception of a few js files.
|
74 |
|
75 | `lib/debugger` is for element explorer, `browser.pause` and `browser.explore`.
|
76 | `lib/driverProviders` controls how WebDriver instances are created.
|
77 | `lib/frameworks` contains adapters for test frameworks such as Jasmine and Mocha.
|
78 | `lib/selenium-webdriver` and `lib/webdriver-js-extender` are used ONLY for API documentation generation.
|
79 |
|
80 | ## Lightning Code Walkthrough
|
81 |
|
82 | TBD.
|
83 |
|
84 | ## Testing
|
85 |
|
86 | Run `npm test` to run the full test suite. This assumes that you have the testapp and a
|
87 | selenium server running. Start these as separate processes with:
|
88 |
|
89 | ```shell
|
90 | webdriver-manager update
|
91 | webdriver-manager start
|
92 | ```
|
93 |
|
94 | and
|
95 |
|
96 | ```shell
|
97 | npm start
|
98 | ```
|
99 |
|
100 | This suite is described in `scripts/test.js`. It uses some small helper functions to run commands
|
101 | as child processes and capture the results, so that we can run protractor commands which should
|
102 | result in failures and verify that we get the expected number and type of failures.
|
103 |
|
104 | The suite contains unit tests, end to end tests using the built binary, and interactive tests.
|
105 | Interactive tests are for testing `browser.pause` and element explorer.
|
106 |
|
107 | End to end tests all have configuration files which live in `spec/`. Many tests do not need
|
108 | an actual Selenium server backing them and use the `mockSelenium` configuration, which saves
|
109 | time by not connecting to a real selenium server.
|
110 |
|
111 | ## Important dependencies
|
112 |
|
113 | Protractor has very close dependencies with several other projects under the Angular umbrella:
|
114 |
|
115 | `jasminewd2` is an extension of the Jasmine test framework that adds utilities for
|
116 | working with selenium-webdriver. [jasminewd](https://github.com/angular/jasminewd)
|
117 |
|
118 | `blocking-proxy` is a separate binary, which handles traffic between a test script and
|
119 | webdriver. It can be turned on via a protractor configuration file, and in the future
|
120 | all logic to wait for Angular will be handled through the blocking proxy.
|
121 | [blocking-proxy](https://github.com/angular/blocking-proxy)
|
122 |
|
123 | `webdriver-manager` is a separate binary which manages installing and starting up
|
124 | the various binaries necessary for running webdriver tests. These binaries include
|
125 | specific drivers for various browsers (e.g. chromedriver) and the selenium standalone
|
126 | server. [webdriver-manager](https://github.com/angular/webdriver-manager)
|
127 |
|
128 | `webdriver-js-extender` extends selenium-webdriver to add Appium commands.
|
129 | [webdriver-js-extender](https://github.com/angular/webdriver-js-extender)
|
130 |
|
131 | ## Continuous Integration
|
132 |
|
133 | PRs or changes submitted to master will automatically trigger continuous integration on two
|
134 | different services - Travis, and Circle CI. We use Travis for tests run with SauceLabs because
|
135 | we have more vm time on Travis and their integration with SauceLabs is smooth. CircleCI gives us
|
136 | greater control over the vm, which allows us to run tests against local browsers and get better
|
137 | logs.
|
138 |
|
139 | Travis runs e2e tests via SauceLabs against a variety of browsers. The essential browsers run a
|
140 | more complete test suite, `specified by spec/ciFullConf.js`. We also run a set of smoke tests
|
141 | against a larger set of browsers, which is allowed to fail - this is configured in
|
142 | `spec/ciSmokeConf.js`. This is due to flakiness in IE, Safari and older browser versions.
|
143 | We also run a small set of tests using BrowserStack to verify that our integration with their
|
144 | Selenium farm works.
|
145 |
|
146 | Circle CI runs a slightly modified version of `npm test` in a single VM. It installs
|
147 | the browsers it needs locally. Circle CI runs unit tests and a set of e2e tests against Chrome.
|
148 |
|
149 | ## Releasing
|
150 |
|
151 | See [release.md](https://github.com/angular/protractor/blob/master/release.md) for full instructions.
|