UNPKG

12.8 kBTypeScriptView Raw
1import { ProtractorBrowser } from './browser';
2import { ElementFinder } from './element';
3/**
4 * Represents a library of canned expected conditions that are useful for
5 * protractor, especially when dealing with non-angular apps.
6 *
7 * Each condition returns a function that evaluates to a promise. You may mix
8 * multiple conditions using `and`, `or`, and/or `not`. You may also
9 * mix these conditions with any other conditions that you write.
10 *
11 * See ExpectedCondition Class in Selenium WebDriver codebase.
12 * http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html
13 *
14 *
15 * @example
16 * var EC = protractor.ExpectedConditions;
17 * var button = $('#xyz');
18 * var isClickable = EC.elementToBeClickable(button);
19 *
20 * browser.get(URL);
21 * browser.wait(isClickable, 5000); //wait for an element to become clickable
22 * button.click();
23 *
24 * // You can define your own expected condition, which is a function that
25 * // takes no parameter and evaluates to a promise of a boolean.
26 * var urlChanged = function() {
27 * return browser.getCurrentUrl().then(function(url) {
28 * return url === 'http://www.angularjs.org';
29 * });
30 * };
31 *
32 * // You can customize the conditions with EC.and, EC.or, and EC.not.
33 * // Here's a condition to wait for url to change, $('abc') element to contain
34 * // text 'bar', and button becomes clickable.
35 * var condition = EC.and(urlChanged, EC.textToBePresentInElement($('abc'),
36 * 'bar'), isClickable);
37 * browser.get(URL);
38 * browser.wait(condition, 5000); //wait for condition to be true.
39 * button.click();
40 *
41 * @alias ExpectedConditions
42 * @constructor
43 */
44export declare class ProtractorExpectedConditions {
45 browser: ProtractorBrowser;
46 constructor(browser: ProtractorBrowser);
47 /**
48 * Negates the result of a promise.
49 *
50 * @example
51 * var EC = protractor.ExpectedConditions;
52 * var titleIsNotFoo = EC.not(EC.titleIs('Foo'));
53 * // Waits for title to become something besides 'foo'.
54 * browser.wait(titleIsNotFoo, 5000);
55 *
56 * @alias ExpectedConditions.not
57 * @param {!function} expectedCondition
58 *
59 * @returns {!function} An expected condition that returns the negated value.
60 */
61 not(expectedCondition: Function): Function;
62 /**
63 * Helper function that is equivalent to the logical_and if defaultRet==true,
64 * or logical_or if defaultRet==false
65 *
66 * @private
67 * @param {boolean} defaultRet
68 * @param {Array.<Function>} fns An array of expected conditions to chain.
69 *
70 * @returns {!function} An expected condition that returns a promise which
71 * evaluates to the result of the logical chain.
72 */
73 logicalChain_(defaultRet: boolean, fns: Array<Function>): Function;
74 /**
75 * Chain a number of expected conditions using logical_and, short circuiting
76 * at the first expected condition that evaluates to false.
77 *
78 * @example
79 * var EC = protractor.ExpectedConditions;
80 * var titleContainsFoo = EC.titleContains('Foo');
81 * var titleIsNotFooBar = EC.not(EC.titleIs('FooBar'));
82 * // Waits for title to contain 'Foo', but is not 'FooBar'
83 * browser.wait(EC.and(titleContainsFoo, titleIsNotFooBar), 5000);
84 *
85 * @alias ExpectedConditions.and
86 * @param {Array.<Function>} fns An array of expected conditions to 'and'
87 * together.
88 *
89 * @returns {!function} An expected condition that returns a promise which
90 * evaluates to the result of the logical and.
91 */
92 and(...args: Function[]): Function;
93 /**
94 * Chain a number of expected conditions using logical_or, short circuiting
95 * at the first expected condition that evaluates to true.
96 *
97 * @alias ExpectedConditions.or
98 * @example
99 * var EC = protractor.ExpectedConditions;
100 * var titleContainsFoo = EC.titleContains('Foo');
101 * var titleContainsBar = EC.titleContains('Bar');
102 * // Waits for title to contain either 'Foo' or 'Bar'
103 * browser.wait(EC.or(titleContainsFoo, titleContainsBar), 5000);
104 *
105 * @param {Array.<Function>} fns An array of expected conditions to 'or'
106 * together.
107 *
108 * @returns {!function} An expected condition that returns a promise which
109 * evaluates to the result of the logical or.
110 */
111 or(...args: Function[]): Function;
112 /**
113 * Expect an alert to be present.
114 *
115 * @example
116 * var EC = protractor.ExpectedConditions;
117 * // Waits for an alert pops up.
118 * browser.wait(EC.alertIsPresent(), 5000);
119 *
120 * @alias ExpectedConditions.alertIsPresent
121 * @returns {!function} An expected condition that returns a promise
122 * representing whether an alert is present.
123 */
124 alertIsPresent(): Function;
125 /**
126 * An Expectation for checking an element is visible and enabled such that you
127 * can click it.
128 *
129 * @example
130 * var EC = protractor.ExpectedConditions;
131 * // Waits for the element with id 'abc' to be clickable.
132 * browser.wait(EC.elementToBeClickable($('#abc')), 5000);
133 *
134 * @alias ExpectedConditions.elementToBeClickable
135 * @param {!ElementFinder} elementFinder The element to check
136 *
137 * @returns {!function} An expected condition that returns a promise
138 * representing whether the element is clickable.
139 */
140 elementToBeClickable(elementFinder: ElementFinder): Function;
141 /**
142 * An expectation for checking if the given text is present in the
143 * element. Returns false if the elementFinder does not find an element.
144 *
145 * @example
146 * var EC = protractor.ExpectedConditions;
147 * // Waits for the element with id 'abc' to contain the text 'foo'.
148 * browser.wait(EC.textToBePresentInElement($('#abc'), 'foo'), 5000);
149 *
150 * @alias ExpectedConditions.textToBePresentInElement
151 * @param {!ElementFinder} elementFinder The element to check
152 * @param {!string} text The text to verify against
153 *
154 * @returns {!function} An expected condition that returns a promise
155 * representing whether the text is present in the element.
156 */
157 textToBePresentInElement(elementFinder: ElementFinder, text: string): Function;
158 /**
159 * An expectation for checking if the given text is present in the element’s
160 * value. Returns false if the elementFinder does not find an element.
161 *
162 * @example
163 * var EC = protractor.ExpectedConditions;
164 * // Waits for the element with id 'myInput' to contain the input 'foo'.
165 * browser.wait(EC.textToBePresentInElementValue($('#myInput'), 'foo'), 5000);
166 *
167 * @alias ExpectedConditions.textToBePresentInElementValue
168 * @param {!ElementFinder} elementFinder The element to check
169 * @param {!string} text The text to verify against
170 *
171 * @returns {!function} An expected condition that returns a promise
172 * representing whether the text is present in the element's value.
173 */
174 textToBePresentInElementValue(elementFinder: ElementFinder, text: string): Function;
175 /**
176 * An expectation for checking that the title contains a case-sensitive
177 * substring.
178 *
179 * @example
180 * var EC = protractor.ExpectedConditions;
181 * // Waits for the title to contain 'foo'.
182 * browser.wait(EC.titleContains('foo'), 5000);
183 *
184 * @alias ExpectedConditions.titleContains
185 * @param {!string} title The fragment of title expected
186 *
187 * @returns {!function} An expected condition that returns a promise
188 * representing whether the title contains the string.
189 */
190 titleContains(title: string): Function;
191 /**
192 * An expectation for checking the title of a page.
193 *
194 * @example
195 * var EC = protractor.ExpectedConditions;
196 * // Waits for the title to be 'foo'.
197 * browser.wait(EC.titleIs('foo'), 5000);
198 *
199 * @alias ExpectedConditions.titleIs
200 * @param {!string} title The expected title, which must be an exact match.
201 *
202 * @returns {!function} An expected condition that returns a promise
203 * representing whether the title equals the string.
204 */
205 titleIs(title: string): Function;
206 /**
207 * An expectation for checking that the URL contains a case-sensitive
208 * substring.
209 *
210 * @example
211 * var EC = protractor.ExpectedConditions;
212 * // Waits for the URL to contain 'foo'.
213 * browser.wait(EC.urlContains('foo'), 5000);
214 *
215 * @alias ExpectedConditions.urlContains
216 * @param {!string} url The fragment of URL expected
217 *
218 * @returns {!function} An expected condition that returns a promise
219 * representing whether the URL contains the string.
220 */
221 urlContains(url: string): Function;
222 /**
223 * An expectation for checking the URL of a page.
224 *
225 * @example
226 * var EC = protractor.ExpectedConditions;
227 * // Waits for the URL to be 'foo'.
228 * browser.wait(EC.urlIs('foo'), 5000);
229 *
230 * @alias ExpectedConditions.urlIs
231 * @param {!string} url The expected URL, which must be an exact match.
232 *
233 * @returns {!function} An expected condition that returns a promise
234 * representing whether the url equals the string.
235 */
236 urlIs(url: string): Function;
237 /**
238 * An expectation for checking that an element is present on the DOM
239 * of a page. This does not necessarily mean that the element is visible.
240 * This is the opposite of 'stalenessOf'.
241 *
242 * @example
243 * var EC = protractor.ExpectedConditions;
244 * // Waits for the element with id 'abc' to be present on the dom.
245 * browser.wait(EC.presenceOf($('#abc')), 5000);
246 *
247 * @alias ExpectedConditions.presenceOf
248 * @param {!ElementFinder} elementFinder The element to check
249 *
250 * @returns {!function} An expected condition that returns a promise
251 * representing whether the element is present.
252 */
253 presenceOf(elementFinder: ElementFinder): Function;
254 /**
255 * An expectation for checking that an element is not attached to the DOM
256 * of a page. This is the opposite of 'presenceOf'.
257 *
258 * @example
259 * var EC = protractor.ExpectedConditions;
260 * // Waits for the element with id 'abc' to be no longer present on the dom.
261 * browser.wait(EC.stalenessOf($('#abc')), 5000);
262 *
263 * @alias ExpectedConditions.stalenessOf
264 * @param {!ElementFinder} elementFinder The element to check
265 *
266 * @returns {!function} An expected condition that returns a promise
267 * representing whether the element is stale.
268 */
269 stalenessOf(elementFinder: ElementFinder): Function;
270 /**
271 * An expectation for checking that an element is present on the DOM of a
272 * page and visible. Visibility means that the element is not only displayed
273 * but also has a height and width that is greater than 0. This is the
274 * opposite
275 * of 'invisibilityOf'.
276 *
277 * @example
278 * var EC = protractor.ExpectedConditions;
279 * // Waits for the element with id 'abc' to be visible on the dom.
280 * browser.wait(EC.visibilityOf($('#abc')), 5000);
281 *
282 * @alias ExpectedConditions.visibilityOf
283 * @param {!ElementFinder} elementFinder The element to check
284 *
285 * @returns {!function} An expected condition that returns a promise
286 * representing whether the element is visible.
287 */
288 visibilityOf(elementFinder: ElementFinder): Function;
289 /**
290 * An expectation for checking that an element is either invisible or not
291 * present on the DOM. This is the opposite of 'visibilityOf'.
292 *
293 * @example
294 * var EC = protractor.ExpectedConditions;
295 * // Waits for the element with id 'abc' to be no longer visible on the dom.
296 * browser.wait(EC.invisibilityOf($('#abc')), 5000);
297 *
298 * @alias ExpectedConditions.invisibilityOf
299 * @param {!ElementFinder} elementFinder The element to check
300 *
301 * @returns {!function} An expected condition that returns a promise
302 * representing whether the element is invisible.
303 */
304 invisibilityOf(elementFinder: ElementFinder): Function;
305 /**
306 * An expectation for checking the selection is selected.
307 *
308 * @example
309 * var EC = protractor.ExpectedConditions;
310 * // Waits for the element with id 'myCheckbox' to be selected.
311 * browser.wait(EC.elementToBeSelected($('#myCheckbox')), 5000);
312 *
313 * @alias ExpectedConditions.elementToBeSelected
314 * @param {!ElementFinder} elementFinder The element to check
315 *
316 * @returns {!function} An expected condition that returns a promise
317 * representing whether the element is selected.
318 */
319 elementToBeSelected(elementFinder: ElementFinder): Function;
320}