UNPKG

5.69 kBMarkdownView Raw
1# Building and Testing Protractor
2
3This document describes building, testing, releasing Protractor and provides an overview of
4the repository layout.
5
6## Prerequisite software
7
8The prerequisite software (Node.js, npm, git, jdk) are the same as for angular. See
9https://github.com/angular/angular/blob/master/docs/DEVELOPER.md#prerequisite-software
10
11## Getting the sources
12
13Fork Protractor from github, then clone your fork with:
14
15```shell
16git clone git@github.com:<github username>/protractor.git
17
18# Go to the Protractor directory:
19cd protractor/
20
21# Add the main protractor repository as an upstream remote to your repository:
22git remote add upstream https://github.com/angular/protractor.git
23```
24
25## Installing and Building
26
27All Protractor dependencies come from npm. Install with:
28
29```shell
30npm install
31```
32
33This will also trigger our build step. The build step runs the TypeScript compiler
34and copies necessary files into the output `built` directory. To run the build step
35independently, run:
36
37```shell
38npm run prepublish
39```
40
41You can see the other available npm scripts in `package.json`. Note that most of these
42scripts just call our `gulp` commands, which can be seen in `gulpfile.js`.
43
44## Formatting
45
46Protractor uses clang-format to format the source code. If the source code is not properly formatted,
47the CI will fail and the PR can not be merged.
48
49You can automatically format your code by running:
50
51```shell
52npm run format
53```
54
55You can check that you will pass lint tests with:
56
57```shell
58gulp 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
73Most 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
82TBD.
83
84## Testing
85
86Run `npm test` to run the full test suite. This assumes that you have the testapp and a
87selenium server running. Start these as separate processes with:
88
89```shell
90webdriver-manager update
91webdriver-manager start
92```
93
94and
95
96```shell
97npm start
98```
99
100This suite is described in `scripts/test.js`. It uses some small helper functions to run commands
101as child processes and capture the results, so that we can run protractor commands which should
102result in failures and verify that we get the expected number and type of failures.
103
104The suite contains unit tests, end to end tests using the built binary, and interactive tests.
105Interactive tests are for testing `browser.pause` and element explorer.
106
107End to end tests all have configuration files which live in `spec/`. Many tests do not need
108an actual Selenium server backing them and use the `mockSelenium` configuration, which saves
109time by not connecting to a real selenium server.
110
111## Important dependencies
112
113Protractor 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
116working 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
119webdriver. It can be turned on via a protractor configuration file, and in the future
120all 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
124the various binaries necessary for running webdriver tests. These binaries include
125specific drivers for various browsers (e.g. chromedriver) and the selenium standalone
126server. [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
133PRs or changes submitted to master will automatically trigger continuous integration on two
134different services - Travis, and Circle CI. We use Travis for tests run with SauceLabs because
135we have more vm time on Travis and their integration with SauceLabs is smooth. CircleCI gives us
136greater control over the vm, which allows us to run tests against local browsers and get better
137logs.
138
139Travis runs e2e tests via SauceLabs against a variety of browsers. The essential browsers run a
140more complete test suite, `specified by spec/ciFullConf.js`. We also run a set of smoke tests
141against 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.
143We also run a small set of tests using BrowserStack to verify that our integration with their
144Selenium farm works.
145
146Circle CI runs a slightly modified version of `npm test` in a single VM. It installs
147the browsers it needs locally. Circle CI runs unit tests and a set of e2e tests against Chrome.
148
149## Releasing
150
151See [release.md](https://github.com/angular/protractor/blob/master/release.md) for full instructions.