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

Commit aba4331

Browse files
committed
chore(test): move lib_spec.js off of the control flow
1 parent 8af3be7 commit aba4331

File tree

3 files changed

+63
-64
lines changed

3 files changed

+63
-64
lines changed

spec/basic/lib_spec.js

+58-62
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,77 @@
1-
describe('no protractor at all', function() {
2-
it('should still do normal tests', function() {
1+
describe('no protractor at all', () => {
2+
it('should still do normal tests', () => {
33
expect(true).toBe(true);
44
});
55
});
66

7-
describe('protractor library', function() {
8-
it('should expose the correct global variables', function() {
7+
describe('protractor library', () => {
8+
it('should expose the correct global variables', () => {
99
expect(protractor).toBeDefined();
1010
expect(browser).toBeDefined();
1111
expect(by).toBeDefined();
1212
expect(By).toBeDefined();
1313
expect(element).toBeDefined();
1414
expect($).toBeDefined();
1515
expect(DartObject).toBeDefined();
16-
var obj = {};
17-
var dartProxy = new DartObject(obj);
16+
const obj = {};
17+
const dartProxy = new DartObject(obj);
1818
expect(dartProxy.o === obj).toBe(true);
1919
});
2020

2121
it('should export other webdriver classes onto the global protractor',
22-
function() {
22+
() => {
2323
expect(protractor.ActionSequence).toBeDefined();
2424
expect(protractor.Key.RETURN).toEqual('\uE006');
2525
});
2626

27-
it('should export custom parameters to the protractor instance', function() {
27+
it('should export custom parameters to the protractor instance', () => {
2828
expect(browser.params.login).toBeDefined();
2929
expect(browser.params.login.user).toEqual('Jane');
3030
expect(browser.params.login.password).toEqual('1234');
3131
});
3232

3333
it('should allow a mix of using protractor and using the driver directly',
34-
function() {
35-
browser.get('index.html');
36-
expect(browser.getCurrentUrl()).toMatch('#/form');
34+
async() => {
35+
await browser.get('index.html');
36+
expect(await browser.getCurrentUrl()).toMatch('#/form');
3737

38-
browser.driver.findElement(protractor.By.linkText('repeater')).click();
39-
expect(browser.driver.getCurrentUrl()).toMatch('#/repeater');
38+
await browser.driver.findElement(protractor.By.linkText('repeater')).click();
39+
expect(await browser.driver.getCurrentUrl()).toMatch('#/repeater');
4040

41-
browser.navigate().back();
42-
expect(browser.driver.getCurrentUrl()).toMatch('#/form');
43-
});
41+
await browser.navigate().back();
42+
expect(await browser.driver.getCurrentUrl()).toMatch('#/form');
43+
});
4444

45-
it('should unwrap WebElements', function() {
46-
browser.get('index.html');
47-
var ptorEl = element(by.binding('greet'));
48-
browser.executeScript('', ptorEl); // Will crash if element isn't unwrapped
45+
it('should unwrap WebElements', async() => {
46+
await browser.get('index.html');
47+
const ptorEl = element(by.binding('greet'));
48+
await browser.executeScript('', ptorEl); // Will crash if element isn't unwrapped
4949
});
5050

51-
it('should have access to the processed config block', function() {
52-
function containsMatching(arr, string) {
53-
var contains = false;
54-
for (var i = 0; i < arr.length; ++i) {
51+
it('should have access to the processed config block', async() => {
52+
let containsMatching = (arr, string) => {
53+
let contains = false;
54+
for (let i = 0; i < arr.length; ++i) {
5555
if (arr[i].indexOf(string) !== -1) {
5656
contains = true;
5757
}
5858
}
5959
return contains;
6060
}
6161

62-
browser.getProcessedConfig().then(function(config) {
63-
expect(config.params.login).toBeDefined();
64-
expect(config.params.login.user).toEqual('Jane');
65-
expect(config.params.login.password).toEqual('1234');
66-
expect(containsMatching(config.specs, 'lib_spec.js')).toBe(true);
67-
expect(config.capabilities).toBeDefined();
68-
});
62+
const config = await browser.getProcessedConfig();
63+
expect(config.params.login).toBeDefined();
64+
expect(config.params.login.user).toEqual('Jane');
65+
expect(config.params.login.password).toEqual('1234');
66+
expect(containsMatching(config.specs, 'lib_spec.js')).toBe(true);
67+
expect(config.capabilities).toBeDefined();
6968
});
7069

71-
it('should allow adding custom locators', function() {
72-
var findMenuItem = function() {
73-
var itemName = arguments[0];
74-
var menu = document.querySelectorAll('.menu li');
75-
for (var i = 0; i < menu.length; ++i) {
70+
it('should allow adding custom locators', async() => {
71+
let findMenuItem = () => {
72+
const itemName = arguments[0];
73+
const menu = document.querySelectorAll('.menu li');
74+
for (const i = 0; i < menu.length; ++i) {
7675
if (menu[i].textContent == itemName) {
7776
return [menu[i]];
7877
}
@@ -83,17 +82,17 @@ describe('protractor library', function() {
8382

8483
expect(by.menuItem).toBeDefined();
8584

86-
browser.get('index.html');
87-
expect(element(by.menuItem('repeater')).isPresent());
88-
expect(element(by.menuItem('repeater')).getText()).toEqual('repeater');
85+
await browser.get('index.html');
86+
expect(await element(by.menuItem('repeater')).isPresent());
87+
expect(await element(by.menuItem('repeater')).getText()).toEqual('repeater');
8988
});
9089

91-
it('should allow adding custom varargs locators', function() {
92-
var findMenuItemWithName = function() {
93-
var css = arguments[0];
94-
var itemName = arguments[1];
95-
var menu = document.querySelectorAll(css);
96-
for (var i = 0; i < menu.length; ++i) {
90+
it('should allow adding custom varargs locators', async() => {
91+
let findMenuItemWithName = function() {
92+
const css = arguments[0];
93+
const itemName = arguments[1];
94+
const menu = document.querySelectorAll(css);
95+
for (const i = 0; i < menu.length; ++i) {
9796
if (menu[i].textContent == itemName) {
9897
return [menu[i]];
9998
}
@@ -104,30 +103,27 @@ describe('protractor library', function() {
104103

105104
expect(by.menuItemWithName).toBeDefined();
106105

107-
browser.get('index.html');
108-
expect(element(by.menuItemWithName('.menu li', 'repeater')).isPresent());
109-
expect(element(by.menuItemWithName('.menu li', 'repeater')).getText()).
110-
toEqual('repeater');
106+
await browser.get('index.html');
107+
expect(await element(by.menuItemWithName('.menu li', 'repeater')).isPresent());
108+
expect(await element(by.menuItemWithName('.menu li', 'repeater')).getText())
109+
.toEqual('repeater');
111110
});
112111

113-
describe('helper functions', function() {
114-
it('should get the absolute URL', function() {
115-
browser.get('index.html');
116-
expect(browser.getLocationAbsUrl()).
117-
toMatch('/form');
112+
describe('helper functions', () => {
113+
it('should get the absolute URL', async() => {
114+
await browser.get('index.html');
115+
expect(await browser.getLocationAbsUrl()).toMatch('/form');
118116

119-
element(by.linkText('repeater')).click();
120-
expect(browser.getLocationAbsUrl()).
121-
toMatch('/repeater');
117+
await element(by.linkText('repeater')).click();
118+
expect(await browser.getLocationAbsUrl()).toMatch('/repeater');
122119
});
123120

124-
it('should navigate to another url with setLocation', function() {
125-
browser.get('index.html');
121+
it('should navigate to another url with setLocation', async() => {
122+
await browser.get('index.html');
126123

127-
browser.setLocation('/repeater');
124+
await browser.setLocation('/repeater');
128125

129-
expect(browser.getLocationAbsUrl()).
130-
toMatch('/repeater');
126+
expect(await browser.getLocationAbsUrl()).toMatch('/repeater');
131127
});
132128
});
133129
});

spec/basicConf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ exports.config = {
99

1010
// Spec patterns are relative to this directory.
1111
specs: [
12-
'basic/elements_spec.js'
12+
'basic/elements_spec.js',
13+
'basic/lib_spec.js'
1314
],
1415

1516
// Exclude patterns are relative to this directory.

spec/ciFullConf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ exports.config = {
88
framework: 'jasmine',
99

1010
// Spec patterns are relative to this directory.
11+
// TODO(selenium4): revert back to basic/*_spec.js
1112
specs: [
12-
'basic/*_spec.js'
13+
'basic/elements_spec.js',
14+
'basic/lib_spec.js'
1315
],
1416

1517
// Exclude patterns are relative to this directory.

0 commit comments

Comments
 (0)