This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathexpected_conditions_spec.js
180 lines (141 loc) · 6.5 KB
/
expected_conditions_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var EC = protractor.ExpectedConditions;
var env = require('../environment');
describe('expected conditions', function() {
beforeEach(function() {
browser.get('index.html#/form');
});
it('should have alertIsPresent', function() {
var alertIsPresent = EC.alertIsPresent();
expect(alertIsPresent.call()).toBe(false);
var alertButton = $('#alertbutton');
alertButton.click();
browser.wait(protractor.ExpectedConditions.alertIsPresent(), 1000);
browser.switchTo().alert().accept();
});
it('should have presenceOf', function() {
var presenceOfInvalid = EC.presenceOf($('#INVALID'));
var presenceOfHideable = EC.presenceOf($('#shower'));
expect(presenceOfInvalid.call()).toBe(false);
expect(presenceOfHideable.call()).toBe(true);
element(by.model('show')).click();
expect(presenceOfHideable.call()).toBe(true); // Should be able to reuse.
});
it('should have stalenessOf', function() {
var stalenessOfInvalid = EC.stalenessOf($('#INVALID'));
var stalenessOfHideable = EC.stalenessOf($('#shower'));
expect(stalenessOfInvalid.call()).toBe(true);
expect(stalenessOfHideable.call()).toBe(false);
element(by.model('show')).click();
expect(stalenessOfHideable.call()).toBe(false);
});
it('should have visibilityOf', function() {
var visibilityOfInvalid = EC.visibilityOf($('#INVALID'));
var visibilityOfHideable = EC.visibilityOf($('#shower'));
expect(visibilityOfInvalid.call()).toBe(false);
expect(visibilityOfHideable.call()).toBe(true);
element(by.model('show')).click();
expect(visibilityOfHideable.call()).toBe(false);
});
it('should have invisibilityOf', function() {
var invisibilityOfInvalid = EC.invisibilityOf($('#INVALID'));
var invisibilityOfHideable = EC.invisibilityOf($('#shower'));
expect(invisibilityOfInvalid.call()).toBe(true);
expect(invisibilityOfHideable.call()).toBe(false);
element(by.model('show')).click();
expect(invisibilityOfHideable.call()).toBe(true);
});
it('should have titleContains', function() {
expect(EC.titleContains('My Angular').call()).toBe(true);
expect(EC.titleContains('My AngularJS App').call()).toBe(true);
});
it('should have titleIs', function() {
expect(EC.titleIs('My Angular').call()).toBe(false);
expect(EC.titleIs('My AngularJS App').call()).toBe(true);
});
it('should have urlContains', function() {
var baseUrlFromSpec = browser.baseUrl;
expect(EC.urlContains('/form').call()).toBe(true);
expect(EC.urlContains(baseUrlFromSpec+ 'index.html#/form').call()).toBe(true);
});
it('should have urlIs', function() {
var baseUrlFromSpec = browser.baseUrl;
expect(EC.urlIs(env.baseUrl).call()).toBe(false);
expect(EC.urlIs(baseUrlFromSpec+'index.html#/form').call()).toBe(true);
});
it('should have elementToBeClickable', function() {
var invalidIsClickable = EC.elementToBeClickable($('#INVALID'));
var buttonIsClickable = EC.elementToBeClickable($('#disabledButton'));
expect(invalidIsClickable.call()).toBe(false);
expect(buttonIsClickable.call()).toBe(true);
element(by.model('disabled')).click();
expect(buttonIsClickable.call()).toBe(false);
});
it('should have textToBePresentInElement', function() {
var invalidHasText = EC.textToBePresentInElement($('#INVALID'), 'shouldnt throw');
var hideableHasText = EC.textToBePresentInElement($('#shower'), 'Shown');
expect(invalidHasText.call()).toBe(false);
expect(hideableHasText.call()).toBe(true);
element(by.model('show')).click();
expect(hideableHasText.call()).toBe(false);
});
it('should have textToBePresentInElementValue', function() {
var invalid = $('#INVALID');
var about = element(by.model('aboutbox'));
expect(EC.textToBePresentInElementValue(invalid, 'shouldnt throw').call()).toBe(false);
expect(EC.textToBePresentInElementValue(about, 'text box').call()).toBe(true);
});
it('should have elementToBeSelected', function() {
var checkbox = element(by.model('show'));
expect(EC.elementToBeSelected(checkbox).call()).toBe(true);
checkbox.click();
expect(EC.elementToBeSelected(checkbox).call()).toBe(false);
});
it('should have not', function() {
var presenceOfValidElement = EC.presenceOf($('#shower'));
expect(presenceOfValidElement.call()).toBe(true);
expect(EC.not(presenceOfValidElement).call()).toBe(false);
});
it('should have and', function() {
var presenceOfValidElement = EC.presenceOf($('#shower'));
var presenceOfInvalidElement = EC.presenceOf($('#INVALID'));
var validityOfTitle = EC.titleIs('My AngularJS App');
expect(EC.and(presenceOfValidElement, validityOfTitle).call()).toBe(true);
// support multiple conditions
expect(EC.and(presenceOfValidElement,
validityOfTitle, presenceOfInvalidElement).call()).toBe(false);
});
it('and should shortcircuit', function() {
var invalidElem = $('#INVALID');
var presenceOfInvalidElement = EC.presenceOf(invalidElem);
var isDisplayed = invalidElem.isDisplayed.bind(invalidElem);
// check isDisplayed on invalid element
var condition = EC.and(presenceOfInvalidElement, isDisplayed);
// Should short circuit after the first condition is false, and not throw error
expect(condition.call()).toBe(false);
});
it('should have or', function() {
var presenceOfValidElement = EC.presenceOf($('#shower'));
var presenceOfInvalidElement = EC.presenceOf($('#INVALID'));
var presenceOfInvalidElement2 = EC.presenceOf($('#INVALID2'));
expect(EC.or(presenceOfInvalidElement, presenceOfInvalidElement2).call()).toBe(false);
// support multiple conditions
expect(EC.or(presenceOfInvalidElement,
presenceOfInvalidElement2, presenceOfValidElement).call()).toBe(true);
});
it('or should shortcircuit', function() {
var validElem = $('#shower');
var invalidElem = $('#INVALID');
var presenceOfValidElement = EC.presenceOf(validElem);
var isDisplayed = invalidElem.isDisplayed.bind(invalidElem);
// check isDisplayed on invalid element
var condition = EC.or(presenceOfValidElement, isDisplayed);
// Should short circuit after the first condition is true, and not throw error
expect(condition.call()).toBe(true);
});
it('should be able to mix conditions', function() {
var valid = EC.presenceOf($('#shower'));
var invalid = EC.presenceOf($('#INVALID'));
expect(EC.or(valid, EC.and(valid, invalid)).call()).toBe(true);
expect(EC.or(EC.not(valid), EC.and(valid, invalid)).call()).toBe(false);
});
});