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

Commit 10110bc

Browse files
juliemrcaitp
authored andcommitted
docs(tutorial): update tutorial steps to discuss protractor
Closes #6940
1 parent 0ed0207 commit 10110bc

File tree

7 files changed

+78
-70
lines changed

7 files changed

+78
-70
lines changed

docs/content/tutorial/index.ngdoc

+7-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ are working on the code.
150150
## Running End to End Tests
151151

152152
The project is preconfigured to use [Protractor][protractor] to run the end to end tests for the
153-
application. Execute the Protractor test scripts against your application by running:
153+
application. Set up the binaries protractor needs to run by running:
154+
155+
```
156+
npm run update-webdriver
157+
```
158+
(You will only need to do this once) Execute the Protractor test scripts against your application
159+
by running:
154160

155161
```
156162
npm run protractor

docs/content/tutorial/step_03.ngdoc

+26-31
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,23 @@ describe('PhoneCat App', function() {
9696
describe('Phone list view', function() {
9797

9898
beforeEach(function() {
99-
browser().navigateTo('../../app/index.html');
99+
browser.get('app/index.html');
100100
});
101101

102102

103103
it('should filter the phone list as user types into the search box', function() {
104-
expect(repeater('.phones li').count()).toBe(3);
105104

106-
input('query').enter('nexus');
107-
expect(repeater('.phones li').count()).toBe(1);
105+
var phoneList = element.all(by.repeater('phone in phones'));
106+
var query = element(by.model('query'));
108107

109-
input('query').enter('motorola');
110-
expect(repeater('.phones li').count()).toBe(2);
108+
expect(phoneList.count()).toBe(3);
109+
110+
query.sendKeys('nexus');
111+
expect(phoneList.count()).toBe(1);
112+
113+
query.clear();
114+
query.sendKeys('motorola');
115+
expect(phoneList.count()).toBe(2);
111116
});
112117
});
113118
});
@@ -117,20 +122,14 @@ Even though the syntax of this test looks very much like our controller unit tes
117122
Jasmine, the end-to-end test uses APIs of {@link guide/e2e-testing Angular's end-to-end
118123
test runner}.
119124

120-
To run the end-to-end test, open one of the following in a new browser tab:
121-
122-
* node.js users: http://localhost:8000/test/e2e/runner.html
123-
* users with other http servers:
124-
`http://localhost:[port-number]/[context-path]/test/e2e/runner.html`
125-
* casual reader: http://angular.github.com/angular-phonecat/step-3/test/e2e/runner.html
125+
Much like Karma is the test runner for unit tests, we use Protractor to run end-to-end tests.
126+
Try it with `npm run protractor`. End-to-end tests are slow, so unlike with unit tests, Protractor
127+
will exit after the test run and will not automatically rerun the test suite on every file change.
128+
To rerun the test suite, execute `npm run protractor` again.
126129

127-
Previously we've seen how Karma can be used to execute unit tests. Well, it can also run the
128-
end-to-end tests! Use `./scripts/e2e-test.sh` (if you are on Windows, run `scripts\e2e-test.bat`) script for that. End-to-end tests are slow, so unlike
129-
with unit tests, Karma will exit after the test run and will not automatically rerun the test
130-
suite on every file change. To rerun the test suite, execute the `e2e-test.sh` or `e2e-test.bat` script again.
131-
132-
Note: You must ensure you've installed the karma-ng-scenario framework plugin prior to running the
133-
`e2e-test.sh` script. You can do this by issuing `npm install` into your terminal.
130+
Note: You must ensure you've installed the protractor and updated webdriver prior to running the
131+
`npm run protractor`. You can do this by issuing `npm install` and `npm run update-webdriver` into
132+
your terminal.
134133

135134
This test verifies that the search box and the repeater are correctly wired together. Notice how
136135
easy it is to write end-to-end tests in Angular. Although this example is for a simple test, it
@@ -173,28 +172,24 @@ ngBindTemplate} directives, which are invisible to the user while the page is lo
173172
```js
174173
it('should display the current filter value within an element with id "status"',
175174
function() {
176-
expect(element('#status').text()).toMatch(/Current filter: \s*$/);
175+
var statusElement = element(by.id('status'));
176+
expect(statusElement.getText()).toMatch(/Current filter: \s*$/);
177177

178-
input('query').enter('nexus');
178+
element(by.model('query')).sendKeys('nexus');
179179

180-
expect(element('#status').text()).toMatch(/Current filter: nexus\s*$/);
180+
expect(statusElement.getText()).toMatch(/Current filter: nexus\s*$/);
181181

182182
//alternative version of the last assertion that tests just the value of the binding
183-
using('#status').expect(binding('query')).toBe('nexus');
183+
expect(statusElement.element(by.binding('query'))).toBe('nexus');
184184
});
185185
```
186186

187-
Refresh the browser tab with the end-to-end test runner to see the test fail. To make the test
188-
pass, edit the `index.html` template to add a `div` or `p` element with `id` `"status"` and content
189-
with the `query` binding, prefixed by "Current filter:". For instance:
187+
Re-run `npm run protractor` to see the test fail. To make the test pass, edit the `index.html`
188+
template to add a `div` or `p` element with `id` `"status"` and content with the `query` binding,
189+
prefixed by "Current filter:". For instance:
190190

191191
<div id="status">Current filter: {{query}}</div>
192192

193-
* Add a `pause()` statement inside of an end-to-end test and rerun it. You'll see the runner pause;
194-
this gives you the opportunity to explore the state of your application while it is displayed in
195-
the browser. The app is live! You can change the search query to prove it. Notice how useful this
196-
is for troubleshooting end-to-end tests.
197-
198193

199194
# Summary
200195

docs/content/tutorial/step_04.ngdoc

+23-15
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,36 @@ __`test/e2e/scenarios.js`:__
152152

153153
```js
154154
...
155-
it('should be possible to control phone order via the drop down select box',
156-
function() {
157-
//let's narrow the dataset to make the test assertions shorter
158-
input('query').enter('tablet');
155+
it('should be possible to control phone order via the drop down select box', function() {
159156

160-
expect(repeater('.phones li', 'Phone List').column('phone.name')).
161-
toEqual(["Motorola XOOM\u2122 with Wi-Fi",
162-
"MOTOROLA XOOM\u2122"]);
157+
var phoneNameColumn = element.all(by.repeater('phone in phones').column('{{phone.name}}'));
158+
var query = element(by.model('query'));
163159

164-
select('orderProp').option('Alphabetical');
160+
function getNames() {
161+
return phoneNameColumn.map(function(elm) {
162+
return elm.getText();
163+
});
164+
}
165165

166-
expect(repeater('.phones li', 'Phone List').column('phone.name')).
167-
toEqual(["MOTOROLA XOOM\u2122",
168-
"Motorola XOOM\u2122 with Wi-Fi"]);
169-
});
170-
...
166+
query.sendKeys('tablet'); //let's narrow the dataset to make the test assertions shorter
167+
168+
expect(getNames()).toEqual([
169+
"Motorola XOOM\u2122 with Wi-Fi",
170+
"MOTOROLA XOOM\u2122"
171+
]);
172+
173+
element(by.model('orderProp')).findElement(by.css('option[value="name"]')).click();
174+
175+
expect(getNames()).toEqual([
176+
"MOTOROLA XOOM\u2122",
177+
"Motorola XOOM\u2122 with Wi-Fi"
178+
]);
179+
});...
171180
```
172181

173182
The end-to-end test verifies that the ordering mechanism of the select box is working correctly.
174183

175-
You can now rerun `./scripts/e2e-test.sh` or refresh the browser tab with the end-to-end test
176-
`runner.html` to see the tests run, or you can see them running on [Angular's server](http://angular.github.com/angular-phonecat/step-4/test/e2e/runner.html).
184+
You can now rerun `npm run protractor` to see the tests run.
177185

178186
# Experiments
179187

docs/content/tutorial/step_06.ngdoc

+7-5
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,20 @@ __`test/e2e/scenarios.js`__:
7676
```js
7777
...
7878
it('should render phone specific links', function() {
79-
input('query').enter('nexus');
80-
element('.phones li a').click();
81-
expect(browser().location().url()).toBe('/phones/nexus-s');
79+
var query = element(by.model('query'));
80+
query.sendKeys('nexus');
81+
element(by.css('.phones li a')).click();
82+
browser.getLocationAbsUrl().then(function(url) {
83+
expect(url.split('#')[1]).toBe('/phones/nexus-s');
84+
});
8285
});
8386
...
8487
```
8588

8689
We added a new end-to-end test to verify that the app is generating correct links to the phone
8790
views that we will implement in the upcoming steps.
8891

89-
You can now rerun `./scripts/e2e-test.sh` or refresh the browser tab with the end-to-end test
90-
runner to see the tests run, or you can see them running on [Angular's server](http://angular.github.com/angular-phonecat/step-6/test/e2e/runner.html).
92+
You can now rerun `npm run protractor` to see the tests run.
9193

9294

9395
# Experiments

docs/content/tutorial/step_07.ngdoc

+5-6
Original file line numberDiff line numberDiff line change
@@ -267,22 +267,21 @@ to various URLs and verify that the correct view was rendered.
267267
});
268268
...
269269

270-
describe('Phone detail view', function() {
270+
describe('Phone detail view', function() {
271271

272272
beforeEach(function() {
273-
browser().navigateTo('app/index.html#/phones/nexus-s');
273+
browser.get('app/index.html#/phones/nexus-s');
274274
});
275275

276276

277277
it('should display placeholder page with phoneId', function() {
278-
expect(binding('phoneId')).toBe('nexus-s');
278+
expect(element(by.binding('phoneId')).getText()).toBe('nexus-s');
279279
});
280-
});
280+
});
281281
```
282282

283283

284-
You can now rerun `./scripts/e2e-test.sh` or refresh the browser tab with the end-to-end test
285-
runner to see the tests run, or you can see them running on [Angular's server](http://angular.github.com/angular-phonecat/step-7/test/e2e/runner.html).
284+
You can now rerun `npm run protractor` to see the tests run.
286285

287286

288287
# Experiments

docs/content/tutorial/step_08.ngdoc

+3-4
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,19 @@ __`test/e2e/scenarios.js`:__
166166
describe('Phone detail view', function() {
167167

168168
beforeEach(function() {
169-
browser().navigateTo('../../app/index.html#/phones/nexus-s');
169+
browser.get('app/index.html#/phones/nexus-s');
170170
});
171171

172172

173173
it('should display nexus-s page', function() {
174-
expect(binding('phone.name')).toBe('Nexus S');
174+
expect(element(by.binding('phone.name')).getText()).toBe('Nexus S');
175175
});
176176
});
177177
...
178178
```
179179

180180

181-
You can now rerun `./scripts/e2e-test.sh` or refresh the browser tab with the end-to-end test
182-
runner to see the tests run, or you can see them running on [Angular's server](http://angular.github.com/angular-phonecat/step-8/test/e2e/runner.html).
181+
You can now rerun `npm run protractor` to see the tests run.
183182

184183

185184
# Experiments

docs/content/tutorial/step_10.ngdoc

+7-8
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,22 @@ __`test/e2e/scenarios.js`:__
9090
...
9191

9292
it('should display the first phone image as the main phone image', function() {
93-
expect(element('img.phone').attr('src')).toBe('img/phones/nexus-s.0.jpg');
93+
expect(element(by.css('img.phone')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
9494
});
9595

9696

9797
it('should swap main image if a thumbnail image is clicked on', function() {
98-
element('.phone-thumbs li:nth-child(3) img').click();
99-
expect(element('img.phone').attr('src')).toBe('img/phones/nexus-s.2.jpg');
98+
element(by.css('.phone-thumbs li:nth-child(3) img')).click();
99+
expect(element(by.css('img.phone')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/);
100100

101-
element('.phone-thumbs li:nth-child(1) img').click();
102-
expect(element('img.phone').attr('src')).toBe('img/phones/nexus-s.0.jpg');
101+
element(by.css('.phone-thumbs li:nth-child(1) img')).click();
102+
expect(element(by.css('img.phone')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
103103
});
104104
});
105-
});
106105
```
107106

108-
You can now rerun `./scripts/e2e-test.sh` or refresh the browser tab with the end-to-end test
109-
runner to see the tests run, or you can see them running on [Angular's server](http://angular.github.com/angular-phonecat/step-10/test/e2e/runner.html).
107+
You can now rerun `npm run protractor` to see the tests run.
108+
110109

111110
# Experiments
112111

0 commit comments

Comments
 (0)