Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit fcd973b

Browse files
committed
docs(various): more documentation reorg and rewrite
1 parent 3d60689 commit fcd973b

19 files changed

+376
-283
lines changed

docs/api-overview.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
Working with the Protractor API
3+
===============================
4+
5+
Protractor needs two files to run, the test or spec file, and the configuration file.
6+
7+
Spec files
8+
==========
9+
10+
Protractor tests are written using the syntax of your test framework, for example [Jasmine](http://jasmine.github.io/), and the [Protractor API](/docs/api.md).
11+
12+
Example Spec File
13+
-----------------
14+
This simple script ([example_spec.js](/example/example_sped.js)) tests the 'The Basics' example on the [angularjs.org](http://www.angularjs.org) homepage.
15+
16+
```js
17+
describe('angularjs homepage', function() {
18+
it('should greet the named user', function() {
19+
// Load the AngularJS homepage.
20+
browser.get('http://www.angularjs.org');
21+
22+
// Find the element with ng-model matching 'yourName' - this will
23+
// find the <input type="text" ng-model="yourName"/> element - and then
24+
// type 'Julie' into it.
25+
element(by.model('yourName')).sendKeys('Julie');
26+
27+
// Find the element with binding matching 'yourName' - this will
28+
// find the <h1>Hello {{yourName}}!</h1> element.
29+
var greeting = element(by.binding('yourName'));
30+
31+
// Assert that the text element has the expected value.
32+
// Protractor patches 'expect' to understand promises.
33+
34+
expect(greeting.getText()).toEqual('Hello Julie!');
35+
});
36+
});
37+
```
38+
39+
Global Variables
40+
----------------
41+
42+
Protractor exports these global variables to your spec (test) file:
43+
44+
- `browser` - A wrapper around an instance of WebDriver, used for navigation and page-wide information. The `browser.get` method loads a page. Protractor expects Angular to be present on a page, so it will throw an error if the page it is attempting to load does not contain the Angular library. (If you need to interact with a non-Angular page, you may access the wrapped webdriver instance directly with `browser.driver`).
45+
46+
- `element` - A helper function for finding and interacting with DOM elements on the page you are testing. The `element` function searches for an element on the page. It requires one parameter, a locator strategy for locating the element. See [Using Locators](/docs/locators.md) for more information. See Protractor's findelements test suite ([elements_spec.js](/spec/basic/elements_spec.js)) for more examples.
47+
48+
- `by` - A collection of element locator strategies. For example, elements can be found by CSS selector, by ID, or by the attribute they are bound to with ng-model. See [Using Locators](/docs/locators.md).
49+
50+
- `protractor` - The Protractor namespace which wraps the WebDriver namespace. Contains static variables and classes, such as `protractor.Key` which enumerates the codes for special keyboard signals.
51+
52+
53+
Config Files
54+
============
55+
56+
The configuration file tells Protractor how to set up the Selenium Server, which tests to run, how to set up the browsers, and which test framework to use. The configuration file can also include one or more global settings.
57+
58+
Example Config File
59+
-------------------
60+
61+
A simple configuration ([conf.js](/example)) is shown below.
62+
```js
63+
// An example configuration file
64+
exports.config = {
65+
// The address of a running selenium server.
66+
seleniumAddress: 'http://localhost:4444/wd/hub',
67+
68+
// Capabilities to be passed to the webdriver instance.
69+
capabilities: {
70+
'browserName': 'chrome'
71+
},
72+
73+
// Spec patterns are relative to the configuration file location passed
74+
// to proractor (in this example conf.js).
75+
// They may include glob patterns.
76+
specs: ['example-spec.js'],
77+
78+
// Options to be passed to Jasmine-node.
79+
jasmineNodeOpts: {
80+
showColors: true, // Use colors in the command line report.
81+
}
82+
};
83+
```
84+
85+
Reference Config File
86+
---------------------
87+
88+
The [reference config file](/docs/referenceConf.js) file provides explanations for all of the Protractor configuration options. Default settings include the standalone Selenium Server, the Chrome browser, and the Jasmine test framework. Additional information about various configuration options is available here:
89+
90+
- [Setting Up the Selenium Server](/docs/server-setup.md)
91+
- [Setting Up the Browser](/docs/browser-setup.md)
92+
- [Choosing a Framework](/docs/frameworks.md)
93+
- [Using Page Objects to Organize Tests](/docs/page-objects.md)

docs/browser-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Setting Up Your Browser
1+
Setting Up the Browser
22
=======================
33

44
Protractor works with [Selenium WebDriver](http://docs.seleniumhq.org/docs/03_webdriver.jsp), a browser automation framework. Selenium WebDriver supports several browser implementations or [drivers](http://docs.seleniumhq.org/docs/03_webdriver.jsp#selenium-webdriver-s-drivers) which are discussed below.

docs/components.png

63.1 KB
Loading

docs/debugging.md

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
Debugging Protractor Tests
22
==========================
33

4-
End to end tests can be difficult to debug because they depend on an entire
4+
End-to-end tests can be difficult to debug because they depend on an entire
55
system, may depend on prior actions (such as log-in), and may change the
6-
state of the application they're testing. Webdriver tests in particular
7-
can be difficult to debug because long error messages and the separation
8-
between the browser and the process running the test. This document contains
9-
advice on what to look for and how Protractor can help.
6+
state of the application they're testing. WebDriver tests in particular
7+
can be difficult to debug because of long error messages and the separation
8+
between the browser and the process running the test.
109

11-
Types of failure
10+
Types of Failure
1211
----------------
1312

14-
Protractor comes with [examples of failing tests](https://github.com/angular/protractor/blob/master/debugging/failure_spec.js).
15-
To run, start up the test application and a selenium server, and run
13+
Protractor comes with examples of failing tests ([failure_spec.js](https://github.com/angular/protractor/blob/master/debugging/failure_spec.js)).
14+
To run, start up the test application and a Selenium Server, and run the command below. Then look at all the stack traces.
1615

1716
```
1817
protractor debugging/failureConf.js
1918
```
2019

21-
then look at all the pretty stack traces!
22-
2320
This test suite shows various types of failure:
24-
- Webdriver throws an error. When a command cannot be completed, for example
25-
an element is not found, webdriver throws an error.
21+
22+
- WebDriver throws an error - When a command cannot be completed, for example
23+
an element is not found.
2624
- Protractor will fail when it cannot find the Angular library on a page.
27-
If your test needs to interact with a non-angular page, access the webdriver
25+
If your test needs to interact with a non-angular page, access the WebDriver
2826
instance directly with `browser.driver`.
29-
- An expectation failure. This shows what a normal expectation failure looks
27+
- Expectation Failure - Shows what a normal expectation failure looks
3028
like.
3129

32-
Pausing to debug
30+
Pausing to Debug
3331
----------------
3432

3533
Protractor allows you to pause your test at any point and interact with the
36-
browser. To do this insert `browser.debugger();` into your test where you wish
37-
to break.
34+
browser. To do this insert `browser.debugger();` into your test where you want
35+
to break:
3836

3937
```javascript
4038
it('should fail to find a non-existent element', function() {
@@ -51,13 +49,13 @@ it('should fail to find a non-existent element', function() {
5149
});
5250
```
5351

54-
Then run the test in debug mode
52+
Then run the test in debug mode:
5553

5654
```
5755
protractor debug debugging/failureConf.js
5856
```
5957

60-
This uses the [node debugger](http://nodejs.org/api/debugger.html). Enter
58+
This example uses the [node debugger](http://nodejs.org/api/debugger.html). Enter
6159
`c` to start execution and continue after the breakpoint.
6260

6361
We use `browser.debugger();` instead of node's `debugger;` statement so that
@@ -82,35 +80,37 @@ used from the browser's console.
8280
```
8381

8482

85-
Setting up WebStorm for debugging
83+
Setting Up WebStorm for Debugging
8684
---------------------------------
8785

88-
1. Open Run/Debug Configurations dialog
89-
2. Add new Node.js configuration
90-
3. On Configuration tab set:
86+
To set up WebStorm for Protractor, do the following:
87+
88+
1. Open the Run/Debug Configurations dialog
89+
2. Add new Node.js configuration.
90+
3. On the Configuration tab set:
9191
- **Node Interpreter**: path to node executable
9292
- **Working directory**: your project base path
9393
- **JavaScript file**: path to Protractor cli.js file (e.g. *node_modules\protractor\lib\cli.js*)
9494
- **Application parameters**: path to your Protractor configuration file (e.g.
9595
*protractorConfig.js*)
96-
4. Click OK, place some breakpoints and start debugging
96+
4. Click OK, place some breakpoints, and start debugging.
9797

9898

99-
Testing out Protractor interactively
99+
Testing Out Protractor Interactively
100100
------------------------------------
101101

102102
When debugging or first writing test suites, you may find it helpful to
103103
try out Protractor commands without starting up the entire test suite. You can
104104
do this with the element explorer.
105105

106-
Currently, the explorer runs only with chrome and expects a selenium standalone
107-
server to be running at http://localhost:4444.
106+
Currently, the explorer runs only with chrome and expects a standalone Selenium
107+
Server to be running at http://localhost:4444.
108108

109-
From protractor directory, run with:
109+
From the Protractor directory, run with:
110110

111111
node ./bin/elementexplorer.js <urL>
112112

113-
This will load up the URL on webdriver and put the terminal into a REPL loop.
113+
This will load up the URL on WebDriver and put the terminal into a REPL loop.
114114
You will see a > prompt. The `browser`, `element` and `protractor` variables will
115115
be available. Enter a command such as:
116116

@@ -120,19 +120,17 @@ or
120120

121121
> browser.get('http://www.angularjs.org')
122122

123-
try just
123+
To get a list of functions you can call, try:
124124

125125
> browser
126126

127-
to get a list of functions you can call.
128-
129127
Typing tab at a blank prompt will fill in a suggestion for finding
130128
elements.
131129

132130
Taking Screenshots
133131
------------------
134132

135-
Webdriver can snap a screenshot with `browser.takeScreenshot()`.
133+
WebDriver can snap a screenshot with `browser.takeScreenshot()`.
136134
This returns a promise which will resolve to the screenshot as a base-64
137135
encoded PNG.
138136

@@ -162,5 +160,5 @@ browser.takeScreenshot().then(function (png) {
162160
Timeouts
163161
--------
164162

165-
There are several ways that Protractor can time out - see the [Timeouts](/docs/timeouts.md)
163+
There are several ways that Protractor can time out. See the [Timeouts](/docs/timeouts.md)
166164
reference for full documentation.

docs/faq.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ My tests time out in Protractor, but everything's working fine when running manu
77
There are several ways that Protractor can time out - see the [Timeouts](/docs/timeouts.md)
88
reference for full documentation.
99

10-
What's the difference between [Karma](http://karma-runner.github.io) and Protractor? When do I use which?
10+
What's the difference between Karma and Protractor? When do I use which?
1111
---------------------------------------------------
1212

13-
Karma is a great tool for unit testing, and Protractor is intended for
13+
[Karma](http://karma-runner.github.io) is a great tool for unit testing, and Protractor is intended for
1414
end to end or integration testing. This means that small tests for the logic
1515
of your individual controllers, directives, and services should be run using
1616
Karma. Big tests in which you have a running instance of your entire application
@@ -37,11 +37,11 @@ page is not written with Angular, you'll need to interact with it via
3737
unwrapped webdriver, which can be accessed like `browser.driver.get()`.
3838

3939
You can put your log-in code into an `onPrepare` function, which will be run
40-
once before any of your tests. See [this example](https://github.com/angular/protractor/blob/master/spec/withLoginConf.js).
40+
once before any of your tests. See this example ([withLoginConf.js](https://github.com/angular/protractor/blob/master/spec/withLoginConf.js)]
4141

4242
Which browsers are supported?
4343
-----------------------------
44-
The last two major versions of Chrome, Firefox, IE, and Safari. See details at [browser support](https://github.com/angular/protractor/blob/master/docs/browser-setup.md).
44+
The last two major versions of Chrome, Firefox, IE, and Safari. See details at [Setting Up the Browser](https://github.com/angular/protractor/blob/master/docs/browser-setup.md).
4545

4646
The result of `getText` from an input element is always empty
4747
-------------------------------------------------------------
@@ -77,7 +77,7 @@ browser.manage().logs().get('browser').then(function(browserLog) {
7777

7878
This will output logs from the browser console. Note that logs below the set logging level will be ignored. WebDriver does not currently support changing the logging level for browser logs.
7979

80-
[See an example of using this API to fail tests if the console has errors](https://github.com/juliemr/protractor-demo/blob/master/howtos/browserlog/spec.js).
80+
See an example ([spec.js](https://github.com/juliemr/protractor-demo/blob/master/howtos/browserlog/spec.js)) of using this API to fail tests if the console has errors.
8181

8282
How can I get screenshots of failures?
8383
--------------------------------------------
@@ -121,7 +121,7 @@ jasmine.Spec.prototype.addMatcherResult = function() {
121121
How do I produce an XML report of my test results?
122122
--------------------------------------------------
123123

124-
You can use the npm package [email protected] and add a JUnit XML Reporter. Check out [this example](https://github.com/angular/protractor/blob/master/spec/junitOutputConf.js). Note that the latest version of jasmine-reporters is for Jasmine 2.0, which is not yet supported by Protractor, so you'll need to be sure to use version 1.0.0.
124+
You can use the npm package [email protected] and add a JUnit XML Reporter. Check out this [example (junitOutputConf.js)](https://github.com/angular/protractor/blob/master/spec/junitOutputConf.js). Note that the latest version of jasmine-reporters is for Jasmine 2.0, which is not yet supported by Protractor, so you'll need to be sure to use version 1.0.0.
125125

126126
How can I catch errors such as ElementNotFound?
127127
-----------------------------------------------

docs/getting-started.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Getting Started
2+
===============
3+
4+
To get started quickly, begin with the [Tutorial](/docs/tutorial.md) which provides a step by step overview of how to install Protractor, create test files, set up config files, and run tests.
5+
6+
Protractor needs two files to run, the test or spec file, and the configuration file. For additional information, see [Working with Spec and Config Files](/docs/api-overview.md).
7+
8+
When writing tests, keep in mind that Protractor is a wrapper around WebDriverJS. You may want to skim through the [WebDriverJS Users Guide](https://code.google.com/p/selenium/wiki/WebDriverJs) before writing any tests.
9+
10+
The WebDriverJS API is based on promises. To learn more, check out [The WebDriver Control Flow](/docs/control-flow.md).
11+
12+
To learn how Protractor, Selenium Server, and Selenium WebDriver work together, take a look at [How It Works](/docs/infrastructure.md).
13+
14+
Once you are familiar with Protractor, it is recommended that you start using Page Objects. For more information see [Using Page Objects to Organize Tests](/docs/page-objects.md).
15+
16+
For a complete list of the Protractor documentation, see the [Table of Contents](/docs/toc.md).

docs/infrastructure.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
How It Works
2+
============
3+
4+
5+
Protractor is an end-to-end test framework for AngularJS applications. Protractor is a Node.js program that supports the Jasmine, Mocha, and Cucumber test frameworks.
6+
7+
Selenium is a browser automation framework. Selenium includes the Selenium Server, the WebDriver APIs, and the WebDriver browser drivers.
8+
9+
Protractor works in conjunction with Selenium to provide an automated test infrastructure that can simulate a user’s interaction with an Angular application running in a browser or mobile device.
10+
11+
![Protractor Components Diagram](/docs/components.png)
12+
13+
When working with Protractor, it’s important to keep the following in mind:
14+
- Protractor is a wrapper around WebDriverJS, the JavaScript bindings for the Selenium WebDriver API (before writing any tests, skim through the [WebDriverJS Users Guide](https://code.google.com/p/selenium/wiki/WebDriverJs)).
15+
- WebDriver commands are asynchronus. They are scheduled on a control flow and return promises, not primitive values (see [The WebDriver Control Flow](/docs/control-flow.md)).
16+
- Your test scripts send commands to the Selenium Server, which in turn communicates with the browser driver. Read on for more details.
17+
18+
Process Communication
19+
---------------------
20+
21+
A test using Selenium WebDriver involves three processes - the test script, the server, and the browser. The communication between these processes is shown in the diagram below.
22+
23+
![WebDriver test Processes Diagram](/docs/processes.png)
24+
25+
The Selenium Server takes care of interpreting commands from the test and forwarding them to one or more browsers. Communication between the server and the browser uses the [WebDriver Wire Protocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol), a JSON protocol. The command is interpreted by the Browser Driver.
26+
27+
With Protractor, the test script is run using Node.js. Protractor runs an extra command before performing any action on the browser to ensure that the application being tested has stabilized. For example, let's look at the following snippet of test code.
28+
29+
`element(by.css('button.myclass')).click();`
30+
31+
This will result in three commands being sent to the Browser Driver
32+
33+
- [/session/:sessionId/execute_async](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute_async) - First, Protractor tells the browser to run a snippet of JavaScript. This is a custom command which asks Angular to respond when the application is done with all timeouts and asynchronous requests, and ready for the test to resume.
34+
35+
- [/session/:sessionId/element](https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element) - Then, the command to find the element is sent.
36+
37+
- [/session/:sessionId/element/:id/click](https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/click) - Finally the command to perform a click action is sent.
38+
39+
40+

docs/install.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)