You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
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.
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)
Copy file name to clipboardExpand all lines: docs/browser-setup.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
Setting Up Your Browser
1
+
Setting Up the Browser
2
2
=======================
3
3
4
4
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.
Copy file name to clipboardExpand all lines: docs/debugging.md
+32-34Lines changed: 32 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -1,40 +1,38 @@
1
1
Debugging Protractor Tests
2
2
==========================
3
3
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
5
5
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.
10
9
11
-
Types of failure
10
+
Types of Failure
12
11
----------------
13
12
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.
16
15
17
16
```
18
17
protractor debugging/failureConf.js
19
18
```
20
19
21
-
then look at all the pretty stack traces!
22
-
23
20
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.
26
24
- 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
28
26
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
30
28
like.
31
29
32
-
Pausing to debug
30
+
Pausing to Debug
33
31
----------------
34
32
35
33
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:
38
36
39
37
```javascript
40
38
it('should fail to find a non-existent element', function() {
@@ -51,13 +49,13 @@ it('should fail to find a non-existent element', function() {
51
49
});
52
50
```
53
51
54
-
Then run the test in debug mode
52
+
Then run the test in debug mode:
55
53
56
54
```
57
55
protractor debug debugging/failureConf.js
58
56
```
59
57
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
61
59
`c` to start execution and continue after the breakpoint.
62
60
63
61
We use `browser.debugger();` instead of node's `debugger;` statement so that
@@ -82,35 +80,37 @@ used from the browser's console.
82
80
```
83
81
84
82
85
-
Setting up WebStorm for debugging
83
+
Setting Up WebStorm for Debugging
86
84
---------------------------------
87
85
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:
91
91
-**Node Interpreter**: path to node executable
92
92
-**Working directory**: your project base path
93
93
-**JavaScript file**: path to Protractor cli.js file (e.g. *node_modules\protractor\lib\cli.js*)
94
94
-**Application parameters**: path to your Protractor configuration file (e.g.
95
95
*protractorConfig.js*)
96
-
4. Click OK, place some breakpoints and start debugging
96
+
4. Click OK, place some breakpoints, and start debugging.
97
97
98
98
99
-
Testing out Protractor interactively
99
+
Testing Out Protractor Interactively
100
100
------------------------------------
101
101
102
102
When debugging or first writing test suites, you may find it helpful to
103
103
try out Protractor commands without starting up the entire test suite. You can
104
104
do this with the element explorer.
105
105
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.
108
108
109
-
From protractor directory, run with:
109
+
From the Protractor directory, run with:
110
110
111
111
node ./bin/elementexplorer.js <urL>
112
112
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.
114
114
You will see a > prompt. The `browser`, `element` and `protractor` variables will
115
115
be available. Enter a command such as:
116
116
@@ -120,19 +120,17 @@ or
120
120
121
121
> browser.get('http://www.angularjs.org')
122
122
123
-
try just
123
+
To get a list of functions you can call, try:
124
124
125
125
> browser
126
126
127
-
to get a list of functions you can call.
128
-
129
127
Typing tab at a blank prompt will fill in a suggestion for finding
130
128
elements.
131
129
132
130
Taking Screenshots
133
131
------------------
134
132
135
-
Webdriver can snap a screenshot with `browser.takeScreenshot()`.
133
+
WebDriver can snap a screenshot with `browser.takeScreenshot()`.
136
134
This returns a promise which will resolve to the screenshot as a base-64
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
14
14
end to end or integration testing. This means that small tests for the logic
15
15
of your individual controllers, directives, and services should be run using
16
16
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
37
37
unwrapped webdriver, which can be accessed like `browser.driver.get()`.
38
38
39
39
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)]
41
41
42
42
Which browsers are supported?
43
43
-----------------------------
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).
45
45
46
46
The result of `getText` from an input element is always empty
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.
79
79
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.
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.
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).
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.
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
+

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.
0 commit comments