forked from angular/protractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib_spec.js
More file actions
143 lines (119 loc) · 4.47 KB
/
lib_spec.js
File metadata and controls
143 lines (119 loc) · 4.47 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var util = require('util');
describe('no protractor at all', function() {
it('should still do normal tests', function() {
expect(true).toBe(true);
});
});
describe('protractor library', function() {
it('should expose the correct global variables', function() {
expect(protractor).toBeDefined();
expect(browser).toBeDefined();
expect(by).toBeDefined();
expect(By).toBeDefined();
expect(element).toBeDefined();
expect($).toBeDefined();
expect(DartObject).toBeDefined();
var obj = {};
var dartProxy = new DartObject(obj);
expect(dartProxy.o === obj).toBe(true);
});
it('should export other webdriver classes onto the global protractor',
function() {
expect(protractor.ActionSequence).toBeDefined();
expect(protractor.Key.RETURN).toEqual('\uE006');
});
it('should export custom parameters to the protractor instance', function() {
expect(browser.params.login).toBeDefined();
expect(browser.params.login.user).toEqual('Jane');
expect(browser.params.login.password).toEqual('1234');
});
it('should allow a mix of using protractor and using the driver directly',
function() {
browser.get('index.html');
expect(browser.getCurrentUrl()).toMatch('#/form');
browser.driver.findElement(protractor.By.linkText('repeater')).click();
expect(browser.driver.getCurrentUrl()).toMatch('#/repeater');
browser.navigate().back();
expect(browser.driver.getCurrentUrl()).toMatch('#/form');
});
it('should unwrap WebElements', function() {
browser.get('index.html');
var ptorEl = element(by.binding('greet'));
browser.executeScript('', ptorEl); // Will crash if element isn't unwrapped
});
it('should have access to the processed config block', function() {
function containsMatching(arr, string) {
var contains = false;
for (var i = 0; i < arr.length; ++i) {
if (arr[i].indexOf(string) !== -1) {
contains = true;
}
}
return contains;
}
browser.getProcessedConfig().then(function(config) {
expect(config.params.login).toBeDefined();
expect(config.params.login.user).toEqual('Jane');
expect(config.params.login.password).toEqual('1234');
expect(containsMatching(config.specs, 'lib_spec.js')).toBe(true);
expect(config.capabilities).toBeDefined();
});
});
it('should allow adding custom locators', function() {
var findMenuItem = function() {
var itemName = arguments[0];
var using = arguments[1]; // unused
var menu = document.querySelectorAll('.menu li');
for (var i = 0; i < menu.length; ++i) {
if (menu[i].textContent == itemName) {
return [menu[i]];
}
}
};
by.addLocator('menuItem', findMenuItem);
expect(by.menuItem).toBeDefined();
browser.get('index.html');
expect(element(by.menuItem('repeater')).isPresent());
expect(element(by.menuItem('repeater')).getText()).toEqual('repeater');
});
it('should allow adding custom varargs locators', function() {
var findMenuItemWithName = function() {
var css = arguments[0];
var itemName = arguments[1];
var using = arguments[2]; // unused
var menu = document.querySelectorAll(css);
for (var i = 0; i < menu.length; ++i) {
if (menu[i].textContent == itemName) {
return [menu[i]];
}
}
};
by.addLocator('menuItemWithName', findMenuItemWithName);
expect(by.menuItemWithName).toBeDefined();
browser.get('index.html');
expect(element(by.menuItemWithName('.menu li', 'repeater')).isPresent());
expect(element(by.menuItemWithName('.menu li', 'repeater')).getText()).
toEqual('repeater');
});
it('should allow self-wrapped webdriver instances', function() {
var driver = protractor.wrapDriver(browser.driver);
var url = require('url').resolve(browser.baseUrl, 'index.html');
driver.get(url);
});
describe('helper functions', function() {
it('should get the absolute URL', function() {
browser.get('index.html');
expect(browser.getLocationAbsUrl()).
toMatch('/form');
element(by.linkText('repeater')).click();
expect(browser.getLocationAbsUrl()).
toMatch('/repeater');
});
it('should navigate to another url with setLocation', function() {
browser.get('index.html');
browser.setLocation('/repeater');
expect(browser.getLocationAbsUrl()).
toMatch('/repeater');
});
});
});