forked from angular/protractor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib_spec.js
129 lines (107 loc) · 4.17 KB
/
lib_spec.js
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
describe('no protractor at all', () => {
it('should still do normal tests', () => {
expect(true).toBe(true);
});
});
describe('protractor library', () => {
it('should expose the correct global variables', () => {
expect(protractor).toBeDefined();
expect(browser).toBeDefined();
expect(by).toBeDefined();
expect(By).toBeDefined();
expect(element).toBeDefined();
expect($).toBeDefined();
expect(DartObject).toBeDefined();
const obj = {};
const dartProxy = new DartObject(obj);
expect(dartProxy.o === obj).toBe(true);
});
it('should export other webdriver classes onto the global protractor',
() => {
expect(protractor.ActionSequence).toBeDefined();
expect(protractor.Key.RETURN).toEqual('\uE006');
});
it('should export custom parameters to the protractor instance', () => {
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',
async() => {
await browser.get('index.html');
expect(await browser.getCurrentUrl()).toMatch('#/form');
await browser.driver.findElement(protractor.By.linkText('repeater')).click();
expect(await browser.driver.getCurrentUrl()).toMatch('#/repeater');
await browser.navigate().back();
expect(await browser.driver.getCurrentUrl()).toMatch('#/form');
});
it('should unwrap WebElements', async() => {
await browser.get('index.html');
const ptorEl = element(by.binding('greet'));
await browser.executeScript('', ptorEl); // Will crash if element isn't unwrapped
});
it('should have access to the processed config block', async() => {
let containsMatching = (arr, string) => {
let contains = false;
for (let i = 0; i < arr.length; ++i) {
if (arr[i].indexOf(string) !== -1) {
contains = true;
}
}
return contains;
}
const config = await browser.getProcessedConfig();
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', async() => {
let findMenuItem = () => {
const itemName = arguments[0];
const menu = document.querySelectorAll('.menu li');
for (const i = 0; i < menu.length; ++i) {
if (menu[i].textContent == itemName) {
return [menu[i]];
}
}
};
by.addLocator('menuItem', findMenuItem);
expect(by.menuItem).toBeDefined();
await browser.get('index.html');
expect(await element(by.menuItem('repeater')).isPresent());
expect(await element(by.menuItem('repeater')).getText()).toEqual('repeater');
});
it('should allow adding custom varargs locators', async() => {
let findMenuItemWithName = function() {
const css = arguments[0];
const itemName = arguments[1];
const menu = document.querySelectorAll(css);
for (const i = 0; i < menu.length; ++i) {
if (menu[i].textContent == itemName) {
return [menu[i]];
}
}
};
by.addLocator('menuItemWithName', findMenuItemWithName);
expect(by.menuItemWithName).toBeDefined();
await browser.get('index.html');
expect(await element(by.menuItemWithName('.menu li', 'repeater')).isPresent());
expect(await element(by.menuItemWithName('.menu li', 'repeater')).getText())
.toEqual('repeater');
});
describe('helper functions', () => {
it('should get the absolute URL', async() => {
await browser.get('index.html');
expect(await browser.getLocationAbsUrl()).toMatch('/form');
await element(by.linkText('repeater')).click();
expect(await browser.getLocationAbsUrl()).toMatch('/repeater');
});
it('should navigate to another url with setLocation', async() => {
await browser.get('index.html');
await browser.setLocation('/repeater');
expect(await browser.getLocationAbsUrl()).toMatch('/repeater');
});
});
});