forked from angular/protractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpspec.js
More file actions
106 lines (85 loc) · 3.36 KB
/
httpspec.js
File metadata and controls
106 lines (85 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var webdriver = require('selenium-webdriver');
var protractor = require('./protractor.js');
var assert = require('assert');
var util = require('util');
var driver = new webdriver.Builder().
usingServer('http://localhost:4444/wd/hub').
withCapabilities({
'browserName': 'chrome',
'version': '',
'platform': 'ANY',
'javascriptEnabled': true
}).build();
var ptor = protractor.wrapDriver(driver);
driver.manage().timeouts().setScriptTimeout(10000);
// A module to override the 'version' service.
var mockModuleA = function() {
var newModule = angular.module('moduleA', []);
newModule.value('version', '2');
};
// A second module overriding the 'version' service.
// This module shows the use of a string for the load
// function.
// TODO(julie): Consider this syntax. Should we allow loading the
// modules from files? Provide helpers?
var mockModuleB = "angular.module('moduleB', []).value('version', '3');";
ptor.addMockModule('moduleA', mockModuleA);
ptor.addMockModule('moduleB', mockModuleB);
// The value of version will be '3' because mockModuleB is loaded last.
ptor.get('http://localhost:8000/app/index.html');
// Could still use driver.get to get a URL normally, without injecting modules.
ptor.findElement(webdriver.By.css('[app-version]')).getText().then(function(text) {
assert.equal('3', text);
});
var sample1Button = driver.findElement(webdriver.By.id('sample1'));
var sample2Button = driver.findElement(webdriver.By.id('sample2'));
sample1Button.click();
var fetchButton = driver.findElement(webdriver.By.id('fetch'));
fetchButton.click();
// The quick RPC works fine.
var status = ptor.findElement(protractor.By.binding(), '{{status}}');
status.getText().then(function(text) {
assert.equal('200', text);
});
ptor.findElement(protractor.By.binding(), "{{data}}").getText().then(function(text) {
assert.equal('done', text);
});
// Slow RPC.
sample2Button.click();
fetchButton.click();
// Would normally need driver.sleep(2) or something.
ptor.findElement(webdriver.By.id('statuscode')).getText().then(function(text) {
assert.equal('200', text);
});
ptor.findElement(webdriver.By.id('data')).getText().then(function(text) {
assert.equal('finally done', text);
});
// Custom length RPC.
var urlBox = ptor.findElement(protractor.By.input('url'));
urlBox.clear();
urlBox.sendKeys('/3seccall');
fetchButton.click();
ptor.findElement(webdriver.By.id('data')).getText().then(function(text) {
assert.equal('done after 3 seconds', text);
});
ptor.clearMockModules();
ptor.addMockModule('moduleA', mockModuleA);
driver.get('http://www.google.com'); // need to navigate away from an Angular page so that it will
// bootstrap again.
ptor.get('http://localhost:8000/app/index.html#/bindings');
// Now, version should be 2, since only moduleA has been loaded.
ptor.findElement(webdriver.By.css('[app-version]')).getText().then(function(text) {
assert.equal('2', text);
});
ptor.findElement(protractor.By.select('planet')).
findElements(webdriver.By.tagName("option")).then(function(planetOptions) {
for (var i = 0; i < planetOptions.length; ++i) {
planetOptions[i].getText().then(function(text) {
util.puts(text);
});
}
}); // Prints out the list of planet names.
ptor.findElement(protractor.By.selectedOption('planet')).getText().then(function(text) {
assert.equal('Mercury', text);
});
driver.quit();