UNPKG

77.6 kBTypeScriptView Raw
1// Type definitions for Angular Protractor 1.5.0
2// Project: https://github.com/angular/protractor
3// Definitions by: Bill Armstrong <https://github.com/BillArmstrong>
4// Definitions: https://github.com/borisyankov/DefinitelyTyped
5
6/// <reference path="../selenium-webdriver/selenium-webdriver.d.ts" />
7
8declare module protractor {
9 //region Wrapped webdriver Items
10
11 class ActionSequence extends webdriver.ActionSequence {}
12 class Builder extends webdriver.Builder {}
13 class Capabilities extends webdriver.Capabilities {}
14 class Command extends webdriver.Command {}
15 class EventEmitter extends webdriver.EventEmitter {}
16 class Session extends webdriver.Session {}
17 class WebDriver extends webdriver.WebDriver {}
18 class WebElement extends webdriver.WebElement {}
19 class WebElementPromise extends webdriver.WebElementPromise { }
20
21 var Browser: webdriver.IBrowser;
22 var Button: webdriver.IButton;
23 var Capability: webdriver.ICapability;
24 var CommandName: webdriver.ICommandName;
25 var Key: webdriver.IKey;
26
27 module error {
28 class Error extends webdriver.error.Error {}
29 var ErrorCode: webdriver.error.IErrorCode;
30 }
31
32 module logging {
33 class Preferences extends webdriver.logging.Preferences { }
34 class Entry extends webdriver.logging.Entry { }
35
36 var Type: webdriver.logging.IType;
37 var Level: webdriver.logging.ILevelValues;
38
39 function getLevel(nameOrValue: string): webdriver.logging.ILevel;
40 function getLevel(nameOrValue: number): webdriver.logging.ILevel;
41 }
42
43 module promise {
44 class Thenable<T> extends webdriver.promise.Thenable<T> { }
45 class Promise<T> extends webdriver.promise.Promise<T> { }
46 class Deferred<T> extends webdriver.promise.Deferred<T> { }
47 class ControlFlow extends webdriver.promise.ControlFlow { }
48 class CancellationError extends webdriver.promise.CancellationError { }
49
50 /**
51 * Given an array of promises, will return a promise that will be fulfilled
52 * with the fulfillment values of the input array's values. If any of the
53 * input array's promises are rejected, the returned promise will be rejected
54 * with the same reason.
55 *
56 * @param {!Array.<(T|!webdriver.promise.Promise.<T>)>} arr An array of
57 * promises to wait on.
58 * @return {!webdriver.promise.Promise.<!Array.<T>>} A promise that is
59 * fulfilled with an array containing the fulfilled values of the
60 * input array, or rejected with the same reason as the first
61 * rejected value.
62 * @template T
63 */
64 function all(arr: webdriver.promise.Promise<any>[]): webdriver.promise.Promise<any[]>;
65
66 /**
67 * Invokes the appropriate callback function as soon as a promised
68 * {@code value} is resolved. This function is similar to
69 * {@link webdriver.promise.when}, except it does not return a new promise.
70 * @param {*} value The value to observe.
71 * @param {Function} callback The function to call when the value is
72 * resolved successfully.
73 * @param {Function=} opt_errback The function to call when the value is
74 * rejected.
75 */
76 function asap(value: any, callback: Function, opt_errback?: Function): void;
77
78 /**
79 * @return {!webdriver.promise.ControlFlow} The currently active control flow.
80 */
81 function controlFlow(): webdriver.promise.ControlFlow;
82
83 /**
84 * Creates a new control flow. The provided callback will be invoked as the
85 * first task within the new flow, with the flow as its sole argument. Returns
86 * a promise that resolves to the callback result.
87 * @param {function(!webdriver.promise.ControlFlow)} callback The entry point
88 * to the newly created flow.
89 * @return {!webdriver.promise.Promise} A promise that resolves to the callback
90 * result.
91 */
92 function createFlow<R>(callback: (flow: webdriver.promise.ControlFlow) => R): webdriver.promise.Promise<R>;
93
94 /**
95 * Determines whether a {@code value} should be treated as a promise.
96 * Any object whose "then" property is a function will be considered a promise.
97 *
98 * @param {*} value The value to test.
99 * @return {boolean} Whether the value is a promise.
100 */
101 function isPromise(value: any): boolean;
102
103 /**
104 * Tests is a function is a generator.
105 * @param {!Function} fn The function to test.
106 * @return {boolean} Whether the function is a generator.
107 */
108 function isGenerator(fn: Function): boolean;
109
110 /**
111 * Creates a promise that will be resolved at a set time in the future.
112 * @param {number} ms The amount of time, in milliseconds, to wait before
113 * resolving the promise.
114 * @return {!webdriver.promise.Promise} The promise.
115 */
116 function delayed(ms: number): webdriver.promise.Promise<void>;
117
118 /**
119 * Calls a function for each element in an array, and if the function returns
120 * true adds the element to a new array.
121 *
122 * <p>If the return value of the filter function is a promise, this function
123 * will wait for it to be fulfilled before determining whether to insert the
124 * element into the new array.
125 *
126 * <p>If the filter function throws or returns a rejected promise, the promise
127 * returned by this function will be rejected with the same reason. Only the
128 * first failure will be reported; all subsequent errors will be silently
129 * ignored.
130 *
131 * @param {!(Array.<TYPE>|webdriver.promise.Promise.<!Array.<TYPE>>)} arr The
132 * array to iterator over, or a promise that will resolve to said array.
133 * @param {function(this: SELF, TYPE, number, !Array.<TYPE>): (
134 * boolean|webdriver.promise.Promise.<boolean>)} fn The function
135 * to call for each element in the array.
136 * @param {SELF=} opt_self The object to be used as the value of 'this' within
137 * {@code fn}.
138 * @template TYPE, SELF
139 */
140 function filter<T>(arr: T[], fn: (element: T, index: number, array: T[]) => any, opt_self?: any): webdriver.promise.Promise<T[]>;
141 function filter<T>(arr: webdriver.promise.Promise<T[]>, fn: (element: T, index: number, array: T[]) => any, opt_self?: any): webdriver.promise.Promise<T[]>
142
143 /**
144 * Creates a new deferred object.
145 * @return {!webdriver.promise.Deferred} The new deferred object.
146 */
147 function defer<T>(): webdriver.promise.Deferred<T>;
148
149 /**
150 * Creates a promise that has been resolved with the given value.
151 * @param {*=} opt_value The resolved value.
152 * @return {!webdriver.promise.Promise} The resolved promise.
153 */
154 function fulfilled<T>(opt_value?: T): webdriver.promise.Promise<T>;
155
156 /**
157 * Calls a function for each element in an array and inserts the result into a
158 * new array, which is used as the fulfillment value of the promise returned
159 * by this function.
160 *
161 * <p>If the return value of the mapping function is a promise, this function
162 * will wait for it to be fulfilled before inserting it into the new array.
163 *
164 * <p>If the mapping function throws or returns a rejected promise, the
165 * promise returned by this function will be rejected with the same reason.
166 * Only the first failure will be reported; all subsequent errors will be
167 * silently ignored.
168 *
169 * @param {!(Array.<TYPE>|webdriver.promise.Promise.<!Array.<TYPE>>)} arr The
170 * array to iterator over, or a promise that will resolve to said array.
171 * @param {function(this: SELF, TYPE, number, !Array.<TYPE>): ?} fn The
172 * function to call for each element in the array. This function should
173 * expect three arguments (the element, the index, and the array itself.
174 * @param {SELF=} opt_self The object to be used as the value of 'this' within
175 * {@code fn}.
176 * @template TYPE, SELF
177 */
178 function map<T>(arr: T[], fn: (element: T, index: number, array: T[]) => any, opt_self?: any): webdriver.promise.Promise<T[]>
179 function map<T>(arr: webdriver.promise.Promise<T[]>, fn: (element: T, index: number, array: T[]) => any, opt_self?: any): webdriver.promise.Promise<T[]>
180
181 /**
182 * Creates a promise that has been rejected with the given reason.
183 * @param {*=} opt_reason The rejection reason; may be any value, but is
184 * usually an Error or a string.
185 * @return {!webdriver.promise.Promise} The rejected promise.
186 */
187 function rejected(opt_reason?: any): webdriver.promise.Promise<void>;
188
189 /**
190 * Wraps a function that is assumed to be a node-style callback as its final
191 * argument. This callback takes two arguments: an error value (which will be
192 * null if the call succeeded), and the success value as the second argument.
193 * If the call fails, the returned promise will be rejected, otherwise it will
194 * be resolved with the result.
195 * @param {!Function} fn The function to wrap.
196 * @return {!webdriver.promise.Promise} A promise that will be resolved with the
197 * result of the provided function's callback.
198 */
199 function checkedNodeCall<T>(fn: Function, ...var_args: any[]): webdriver.promise.Promise<T>;
200
201 /**
202 * Consumes a {@code GeneratorFunction}. Each time the generator yields a
203 * promise, this function will wait for it to be fulfilled before feeding the
204 * fulfilled value back into {@code next}. Likewise, if a yielded promise is
205 * rejected, the rejection error will be passed to {@code throw}.
206 *
207 * <p>Example 1: the Fibonacci Sequence.
208 * <pre><code>
209 * webdriver.promise.consume(function* fibonacci() {
210 * var n1 = 1, n2 = 1;
211 * for (var i = 0; i < 4; ++i) {
212 * var tmp = yield n1 + n2;
213 * n1 = n2;
214 * n2 = tmp;
215 * }
216 * return n1 + n2;
217 * }).then(function(result) {
218 * console.log(result); // 13
219 * });
220 * </code></pre>
221 *
222 * <p>Example 2: a generator that throws.
223 * <pre><code>
224 * webdriver.promise.consume(function* () {
225 * yield webdriver.promise.delayed(250).then(function() {
226 * throw Error('boom');
227 * });
228 * }).thenCatch(function(e) {
229 * console.log(e.toString()); // Error: boom
230 * });
231 * </code></pre>
232 *
233 * @param {!Function} generatorFn The generator function to execute.
234 * @param {Object=} opt_self The object to use as "this" when invoking the
235 * initial generator.
236 * @param {...*} var_args Any arguments to pass to the initial generator.
237 * @return {!webdriver.promise.Promise.<?>} A promise that will resolve to the
238 * generator's final result.
239 * @throws {TypeError} If the given function is not a generator.
240 */
241 function consume<T>(generatorFn: Function, opt_self?: any, ...var_args: any[]): webdriver.promise.Promise<T>;
242
243 /**
244 * Registers an observer on a promised {@code value}, returning a new promise
245 * that will be resolved when the value is. If {@code value} is not a promise,
246 * then the return promise will be immediately resolved.
247 * @param {*} value The value to observe.
248 * @param {Function=} opt_callback The function to call when the value is
249 * resolved successfully.
250 * @param {Function=} opt_errback The function to call when the value is
251 * rejected.
252 * @return {!webdriver.promise.Promise} A new promise.
253 */
254 function when<T, R>(value: T, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): webdriver.promise.Promise<R>;
255 function when<T, R>(value: webdriver.promise.Promise<T>, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): webdriver.promise.Promise<R>;
256
257 /**
258 * Returns a promise that will be resolved with the input value in a
259 * fully-resolved state. If the value is an array, each element will be fully
260 * resolved. Likewise, if the value is an object, all keys will be fully
261 * resolved. In both cases, all nested arrays and objects will also be
262 * fully resolved. All fields are resolved in place; the returned promise will
263 * resolve on {@code value} and not a copy.
264 *
265 * Warning: This function makes no checks against objects that contain
266 * cyclical references:
267 *
268 * var value = {};
269 * value['self'] = value;
270 * webdriver.promise.fullyResolved(value); // Stack overflow.
271 *
272 * @param {*} value The value to fully resolve.
273 * @return {!webdriver.promise.Promise} A promise for a fully resolved version
274 * of the input value.
275 */
276 function fullyResolved<T>(value: any): webdriver.promise.Promise<T>;
277
278 /**
279 * Changes the default flow to use when no others are active.
280 * @param {!webdriver.promise.ControlFlow} flow The new default flow.
281 * @throws {Error} If the default flow is not currently active.
282 */
283 function setDefaultFlow(flow: webdriver.promise.ControlFlow): void;
284 }
285
286 module stacktrace {
287 class Frame extends webdriver.stacktrace.Frame { }
288 class Snapshot extends webdriver.stacktrace.Snapshot { }
289
290 /**
291 * Formats an error's stack trace.
292 * @param {!(Error|goog.testing.JsUnitException)} error The error to format.
293 * @return {!(Error|goog.testing.JsUnitException)} The formatted error.
294 */
295 function format(error: any): any;
296
297 /**
298 * Gets the native stack trace if available otherwise follows the call chain.
299 * The generated trace will exclude all frames up to and including the call to
300 * this function.
301 * @return {!Array.<!webdriver.stacktrace.Frame>} The frames of the stack trace.
302 */
303 function get(): webdriver.stacktrace.Frame[];
304
305 /**
306 * Whether the current browser supports stack traces.
307 *
308 * @type {boolean}
309 * @const
310 */
311 var BROWSER_SUPPORTED: boolean;
312 }
313
314 module until {
315 class Condition<T> extends webdriver.until.Condition<T> { }
316
317 /**
318 * Creates a condition that will wait until the input driver is able to switch
319 * to the designated frame. The target frame may be specified as:
320 * <ol>
321 * <li>A numeric index into {@code window.frames} for the currently selected
322 * frame.
323 * <li>A {@link webdriver.WebElement}, which must reference a FRAME or IFRAME
324 * element on the current page.
325 * <li>A locator which may be used to first locate a FRAME or IFRAME on the
326 * current page before attempting to switch to it.
327 * </ol>
328 *
329 * <p>Upon successful resolution of this condition, the driver will be left
330 * focused on the new frame.
331 *
332 * @param {!(number|webdriver.WebElement|
333 * webdriver.Locator|webdriver.By.Hash|
334 * function(!webdriver.WebDriver): !webdriver.WebElement)} frame
335 * The frame identifier.
336 * @return {!until.Condition.<boolean>} A new condition.
337 */
338 function ableToSwitchToFrame(frame: number): webdriver.until.Condition<boolean>;
339 function ableToSwitchToFrame(frame: webdriver.IWebElement): webdriver.until.Condition<boolean>;
340 function ableToSwitchToFrame(frame: webdriver.Locator): webdriver.until.Condition<boolean>;
341 function ableToSwitchToFrame(frame: (webdriver: webdriver.WebDriver) => webdriver.IWebElement): webdriver.until.Condition<boolean>;
342 function ableToSwitchToFrame(frame: any): webdriver.until.Condition<boolean>;
343
344 /**
345 * Creates a condition that waits for an alert to be opened. Upon success, the
346 * returned promise will be fulfilled with the handle for the opened alert.
347 *
348 * @return {!until.Condition.<!webdriver.Alert>} The new condition.
349 */
350 function alertIsPresent(): webdriver.until.Condition<webdriver.Alert>;
351
352 /**
353 * Creates a condition that will wait for the given element to be disabled.
354 *
355 * @param {!webdriver.WebElement} element The element to test.
356 * @return {!until.Condition.<boolean>} The new condition.
357 * @see webdriver.WebDriver#isEnabled
358 */
359 function elementIsDisabled(element: webdriver.IWebElement): webdriver.until.Condition<boolean>;
360
361 /**
362 * Creates a condition that will wait for the given element to be enabled.
363 *
364 * @param {!webdriver.WebElement} element The element to test.
365 * @return {!until.Condition.<boolean>} The new condition.
366 * @see webdriver.WebDriver#isEnabled
367 */
368 function elementIsEnabled(element: webdriver.IWebElement): webdriver.until.Condition<boolean>;
369
370 /**
371 * Creates a condition that will wait for the given element to be deselected.
372 *
373 * @param {!webdriver.WebElement} element The element to test.
374 * @return {!until.Condition.<boolean>} The new condition.
375 * @see webdriver.WebDriver#isSelected
376 */
377 function elementIsNotSelected(element: webdriver.IWebElement): webdriver.until.Condition<boolean>;
378
379 /**
380 * Creates a condition that will wait for the given element to be in the DOM,
381 * yet not visible to the user.
382 *
383 * @param {!webdriver.WebElement} element The element to test.
384 * @return {!until.Condition.<boolean>} The new condition.
385 * @see webdriver.WebDriver#isDisplayed
386 */
387 function elementIsNotVisible(element: webdriver.IWebElement): webdriver.until.Condition<boolean>;
388
389 /**
390 * Creates a condition that will wait for the given element to be selected.
391 * @param {!webdriver.WebElement} element The element to test.
392 * @return {!until.Condition.<boolean>} The new condition.
393 * @see webdriver.WebDriver#isSelected
394 */
395 function elementIsSelected(element: webdriver.IWebElement): webdriver.until.Condition<boolean>;
396
397 /**
398 * Creates a condition that will wait for the given element to become visible.
399 *
400 * @param {!webdriver.WebElement} element The element to test.
401 * @return {!until.Condition.<boolean>} The new condition.
402 * @see webdriver.WebDriver#isDisplayed
403 */
404 function elementIsVisible(element: webdriver.IWebElement): webdriver.until.Condition<boolean>;
405
406 /**
407 * Creates a condition that will loop until an element is
408 * {@link webdriver.WebDriver#findElement found} with the given locator.
409 *
410 * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The locator
411 * to use.
412 * @return {!until.Condition.<!webdriver.WebElement>} The new condition.
413 */
414 function elementLocated(locator: webdriver.Locator): webdriver.until.Condition<webdriver.IWebElement>;
415 function elementLocated(locator: any): webdriver.until.Condition<webdriver.IWebElement>;
416
417 /**
418 * Creates a condition that will wait for the given element's
419 * {@link webdriver.WebDriver#getText visible text} to contain the given
420 * substring.
421 *
422 * @param {!webdriver.WebElement} element The element to test.
423 * @param {string} substr The substring to search for.
424 * @return {!until.Condition.<boolean>} The new condition.
425 * @see webdriver.WebDriver#getText
426 */
427 function elementTextContains(element: webdriver.IWebElement, substr: string): webdriver.until.Condition<boolean>;
428
429 /**
430 * Creates a condition that will wait for the given element's
431 * {@link webdriver.WebDriver#getText visible text} to match the given
432 * {@code text} exactly.
433 *
434 * @param {!webdriver.WebElement} element The element to test.
435 * @param {string} text The expected text.
436 * @return {!until.Condition.<boolean>} The new condition.
437 * @see webdriver.WebDriver#getText
438 */
439 function elementTextIs(element: webdriver.IWebElement, text: string): webdriver.until.Condition<boolean>;
440
441 /**
442 * Creates a condition that will wait for the given element's
443 * {@link webdriver.WebDriver#getText visible text} to match a regular
444 * expression.
445 *
446 * @param {!webdriver.WebElement} element The element to test.
447 * @param {!RegExp} regex The regular expression to test against.
448 * @return {!until.Condition.<boolean>} The new condition.
449 * @see webdriver.WebDriver#getText
450 */
451 function elementTextMatches(element: webdriver.IWebElement, regex: RegExp): webdriver.until.Condition<boolean>;
452
453 /**
454 * Creates a condition that will loop until at least one element is
455 * {@link webdriver.WebDriver#findElement found} with the given locator.
456 *
457 * @param {!(webdriver.Locator|webdriver.By.Hash|Function)} locator The locator
458 * to use.
459 * @return {!until.Condition.<!Array.<!webdriver.WebElement>>} The new
460 * condition.
461 */
462 function elementsLocated(locator: webdriver.Locator): webdriver.until.Condition<webdriver.IWebElement[]>;
463 function elementsLocated(locator: any): webdriver.until.Condition<webdriver.IWebElement[]>;
464
465 /**
466 * Creates a condition that will wait for the given element to become stale. An
467 * element is considered stale once it is removed from the DOM, or a new page
468 * has loaded.
469 *
470 * @param {!webdriver.WebElement} element The element that should become stale.
471 * @return {!until.Condition.<boolean>} The new condition.
472 */
473 function stalenessOf(element: webdriver.IWebElement): webdriver.until.Condition<boolean>;
474
475 /**
476 * Creates a condition that will wait for the current page's title to contain
477 * the given substring.
478 *
479 * @param {string} substr The substring that should be present in the page
480 * title.
481 * @return {!until.Condition.<boolean>} The new condition.
482 */
483 function titleContains(substr: string): webdriver.until.Condition<boolean>;
484
485 /**
486 * Creates a condition that will wait for the current page's title to match the
487 * given value.
488 *
489 * @param {string} title The expected page title.
490 * @return {!until.Condition.<boolean>} The new condition.
491 */
492 function titleIs(title: string): webdriver.until.Condition<boolean>;
493
494 /**
495 * Creates a condition that will wait for the current page's title to match the
496 * given regular expression.
497 *
498 * @param {!RegExp} regex The regular expression to test against.
499 * @return {!until.Condition.<boolean>} The new condition.
500 */
501 function titleMatches(regex: RegExp): webdriver.until.Condition<boolean>;
502 }
503
504 module ExpectedConditions {
505 /**
506 * Negates the result of a promise.
507 *
508 * @param {webdriver.until.Condition<boolean>} expectedCondition
509 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns the negated value.
510 */
511 function not<T>(expectedCondition: webdriver.until.Condition<T>): webdriver.until.Condition<T>;
512
513 /**
514 * Chain a number of expected conditions using logical_and, short circuiting at the
515 * first expected condition that evaluates to false.
516 *
517 * @param {...webdriver.until.Condition<boolean>[]} fns An array of expected conditions to 'and' together.
518 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise which evaluates
519 * to the result of the logical and.
520 */
521 function and<T>(...fns: webdriver.until.Condition<T>[]): webdriver.until.Condition<T>;
522
523 /**
524 * Chain a number of expected conditions using logical_or, short circuiting at the
525 * first expected condition that evaluates to true.
526 *
527 * @param {...webdriver.until.Condition<boolean>[]} fns An array of expected conditions to 'or' together.
528 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise which
529 * evaluates to the result of the logical or.
530 */
531 function or<T>(...fns: webdriver.until.Condition<T>[]): webdriver.until.Condition<T>;
532
533 /**
534 * Expect an alert to be present.
535 *
536 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
537 * whether an alert is present.
538 */
539 function alertIsPresent<T>(): webdriver.until.Condition<T>;
540
541 /**
542 * An Expectation for checking an element is visible and enabled such that you can click it.
543 *
544 * @param {ElementFinder} element The element to check
545 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
546 * whether the element is clickable.
547 */
548 function elementToBeClickable<T>(element: ElementFinder): webdriver.until.Condition<T>;
549
550 /**
551 * An expectation for checking if the given text is present in the element.
552 * Returns false if the elementFinder does not find an element.
553 *
554 * @param {ElementFinder} element The element to check
555 * @param {string} text The text to verify against
556 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
557 * whether the text is present in the element.
558 */
559 function textToBePresentInElement<T>(element: ElementFinder, text: string): webdriver.until.Condition<T>;
560
561 /**
562 * An expectation for checking if the given text is present in the element’s value.
563 * Returns false if the elementFinder does not find an element.
564 *
565 * @param {ElementFinder} element The element to check
566 * @param {string} text The text to verify against
567 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
568 * whether the text is present in the element's value.
569 */
570 function textToBePresentInElementValue<T>(
571 element: ElementFinder, text: string
572 ): webdriver.until.Condition<T>;
573
574 /**
575 * An expectation for checking that the title contains a case-sensitive substring.
576 *
577 * @param {string} title The fragment of title expected
578 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
579 * whether the title contains the string.
580 */
581 function titleContains<T>(title: string): webdriver.until.Condition<T>;
582
583 /**
584 * An expectation for checking the title of a page.
585 *
586 * @param {string} title The expected title, which must be an exact match.
587 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
588 * whether the title equals the string.
589 */
590 function titleIs<T>(title: string): webdriver.until.Condition<T>;
591
592 /**
593 * An expectation for checking that an element is present on the DOM of a page. This does not necessarily
594 * mean that the element is visible. This is the opposite of 'stalenessOf'.
595 *
596 * @param {ElementFinder} elementFinder The element to check
597 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise
598 * representing whether the element is present.
599 */
600 function presenceOf<T>(element: ElementFinder): webdriver.until.Condition<T>;
601
602 /**
603 * An expectation for checking that an element is not attached to the DOM of a page.
604 * This is the opposite of 'presenceOf'.
605 *
606 * @param {ElementFinder} elementFinder The element to check
607 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
608 * whether the element is stale.
609 */
610 function stalenessOf<T>(element: ElementFinder): webdriver.until.Condition<T>;
611
612 /**
613 * An expectation for checking that an element is present on the DOM of a page and visible.
614 * Visibility means that the element is not only displayed but also has a height and width that is
615 * greater than 0. This is the opposite of 'invisibilityOf'.
616 *
617 * @param {ElementFinder} elementFinder The element to check
618 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
619 * whether the element is visible.
620 */
621 function visibilityOf<T>(element: ElementFinder): webdriver.until.Condition<T>;
622
623 /**
624 * An expectation for checking that an element is present on the DOM of a page. This does not necessarily
625 * mean that the element is visible. This is the opposite of 'stalenessOf'.
626 *
627 * @param {ElementFinder} elementFinder The element to check
628 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
629 * whether the element is invisible.
630 */
631 function invisibilityOf<T>(element: ElementFinder): webdriver.until.Condition<T>;
632
633 /**
634 * An expectation for checking the selection is selected.
635 *
636 * @param {ElementFinder} elementFinder The element to check
637 * @return {!webdriver.until.Condition<boolean>} An expected condition that returns a promise representing
638 * whether the element is selected.
639 */
640 function elementToBeSelected<T>(element: ElementFinder): webdriver.until.Condition<T>;
641 }
642
643 //endregion
644
645 /**
646 * Use as: element(locator)
647 *
648 * The ElementFinder can be treated as a WebElement for most purposes, in
649 * particular, you may perform actions (i.e. click, getText) on them as you
650 * would a WebElement. ElementFinders extend Promise, and once an action
651 * is performed on an ElementFinder, the latest result from the chain can be
652 * accessed using then. Unlike a WebElement, an ElementFinder will wait for
653 * angular to settle before performing finds or actions.
654 *
655 * ElementFinder can be used to build a chain of locators that is used to find
656 * an element. An ElementFinder does not actually attempt to find the element
657 * until an action is called, which means they can be set up in helper files
658 * before the page is available.
659 *
660 * @param {webdriver.Locator} locator An element locator.
661 * @return {ElementFinder}
662 */
663 interface Element {
664 (locator: webdriver.Locator): ElementFinder;
665
666 /**
667 * ElementArrayFinder is used for operations on an array of elements (as opposed
668 * to a single element).
669 *
670 * @param {webdriver.Locator} locator An element locator.
671 * @return {ElementArrayFinder}
672 */
673 all(locator: webdriver.Locator): ElementArrayFinder;
674 }
675
676 interface ElementFinder extends webdriver.IWebElement, webdriver.promise.IThenable<any> {
677 /**
678 * Calls to element may be chained to find elements within a parent.
679 *
680 * @alias element(locator).element(locator)
681 * @view
682 * <div class="parent">
683 * <div class="child">
684 * Child text
685 * <div>{{person.phone}}</div>
686 * </div>
687 * </div>
688 *
689 * @example
690 * // Chain 2 element calls.
691 * var child = element(by.css('.parent')).
692 * element(by.css('.child'));
693 * expect(child.getText()).toBe('Child text\n555-123-4567');
694 *
695 * // Chain 3 element calls.
696 * var triple = element(by.css('.parent')).
697 * element(by.css('.child')).
698 * element(by.binding('person.phone'));
699 * expect(triple.getText()).toBe('555-123-4567');
700 *
701 * @param {webdriver.Locator} subLocator
702 * @return {ElementFinder}
703 */
704 element(subLocator: webdriver.Locator): ElementFinder;
705
706 /**
707 * Calls to element may be chained to find an array of elements within a parent.
708 *
709 * @alias element(locator).all(locator)
710 * @view
711 * <div class="parent">
712 * <ul>
713 * <li class="one">First</li>
714 * <li class="two">Second</li>
715 * <li class="three">Third</li>
716 * </ul>
717 * </div>
718 *
719 * @example
720 * var items = element(by.css('.parent')).all(by.tagName('li'))
721 *
722 * @param {webdriver.Locator} subLocator
723 * @return {ElementArrayFinder}
724 */
725 all(subLocator: webdriver.Locator): ElementArrayFinder;
726
727 /**
728 * Shortcut for querying the document directly with css.
729 *
730 * @alias $(cssSelector)
731 * @view
732 * <div class="count">
733 * <span class="one">First</span>
734 * <span class="two">Second</span>
735 * </div>
736 *
737 * @example
738 * var item = $('.count .two');
739 * expect(item.getText()).toBe('Second');
740 *
741 * @param {string} selector A css selector
742 * @return {ElementFinder} which identifies the located
743 * {@link webdriver.WebElement}
744 */
745 $(selector: string): ElementFinder;
746
747 /**
748 * Shortcut for querying the document directly with css.
749 *
750 * @alias $$(cssSelector)
751 * @view
752 * <div class="count">
753 * <span class="one">First</span>
754 * <span class="two">Second</span>
755 * </div>
756 *
757 * @example
758 * // The following protractor expressions are equivalent.
759 * var list = element.all(by.css('.count span'));
760 * expect(list.count()).toBe(2);
761 *
762 * list = $$('.count span');
763 * expect(list.count()).toBe(2);
764 * expect(list.get(0).getText()).toBe('First');
765 * expect(list.get(1).getText()).toBe('Second');
766 *
767 * @param {string} selector a css selector
768 * @return {ElementArrayFinder} which identifies the
769 * array of the located {@link webdriver.WebElement}s.
770 */
771 $$(selector: string): ElementArrayFinder;
772
773 /**
774 * Determine whether the element is present on the page.
775 *
776 * @view
777 * <span>{{person.name}}</span>
778 *
779 * @example
780 * // Element exists.
781 * expect(element(by.binding('person.name')).isPresent()).toBe(true);
782 *
783 * // Element not present.
784 * expect(element(by.binding('notPresent')).isPresent()).toBe(false);
785 *
786 * @return {ElementFinder} which resolves to whether
787 * the element is present on the page.
788 */
789 isPresent(): webdriver.promise.Promise<boolean>;
790
791 /**
792 * Override for WebElement.prototype.isElementPresent so that protractor waits
793 * for Angular to settle before making the check.
794 *
795 * @see ElementFinder.isPresent
796 *
797 * @param {webdriver.Locator} subLocator Locator for element to look for.
798 * @return {ElementFinder} which resolves to whether
799 * the element is present on the page.
800 */
801 isElementPresent(subLocator: webdriver.Locator): webdriver.promise.Promise<boolean>;
802
803 /**
804 * @see ElementArrayFinder.prototype.locator
805 *
806 * @return {webdriver.Locator}
807 */
808 locator(): webdriver.Locator;
809
810 /**
811 * Returns the WebElement represented by this ElementFinder.
812 * Throws the WebDriver error if the element doesn't exist.
813 *
814 * @example
815 * The following three expressions are equivalent.
816 * element(by.css('.parent')).getWebElement();
817 * browser.waitForAngular(); browser.driver.findElement(by.css('.parent'));
818 * browser.findElement(by.css('.parent'));
819 *
820 * @alias element(locator).getWebElement()
821 * @return {webdriver.WebElement}
822 */
823 getWebElement(): webdriver.WebElement;
824
825 /**
826 * Evaluates the input as if it were on the scope of the current element.
827 * @see ElementArrayFinder.evaluate
828 *
829 * @param {string} expression
830 *
831 * @return {ElementFinder} which resolves to the evaluated expression.
832 */
833 evaluate(expression: string): ElementFinder;
834
835 /**
836 * @see ElementArrayFinder.prototype.allowAnimations.
837 * @param {string} value
838 *
839 * @return {ElementFinder} which resolves to whether animation is allowed.
840 */
841 allowAnimations(value: string): ElementFinder;
842
843 /**
844 * Create a shallow copy of ElementFinder.
845 *
846 * @return {!ElementFinder} A shallow copy of this.
847 */
848 clone(): ElementFinder;
849 }
850
851 interface ElementArrayFinder extends webdriver.promise.IThenable<ElementFinder[]> {
852 /**
853 * Returns the elements as an array of WebElements.
854 */
855 getWebElements(): webdriver.WebElement[];
856
857
858 /**
859 * Get an element within the ElementArrayFinder by index. The index starts at 0.
860 * Negative indices are wrapped (i.e. -i means ith element from last)
861 * This does not actually retrieve the underlying element.
862 *
863 * @alias element.all(locator).get(index)
864 * @view
865 * <ul class="items">
866 * <li>First</li>
867 * <li>Second</li>
868 * <li>Third</li>
869 * </ul>
870 *
871 * @example
872 * var list = element.all(by.css('.items li'));
873 * expect(list.get(0).getText()).toBe('First');
874 * expect(list.get(1).getText()).toBe('Second');
875 *
876 * @param {number} index Element index.
877 * @return {ElementFinder} finder representing element at the given index.
878 */
879 get(index: number): ElementFinder;
880
881 /**
882 * Get the first matching element for the ElementArrayFinder. This does not
883 * actually retrieve the underlying element.
884 *
885 * @alias element.all(locator).first()
886 * @view
887 * <ul class="items">
888 * <li>First</li>
889 * <li>Second</li>
890 * <li>Third</li>
891 * </ul>
892 *
893 * @example
894 * var first = element.all(by.css('.items li')).first();
895 * expect(first.getText()).toBe('First');
896 *
897 * @return {ElementFinder} finder representing the first matching element
898 */
899 first(): ElementFinder;
900
901 /**
902 * Get the last matching element for the ElementArrayFinder. This does not
903 * actually retrieve the underlying element.
904 *
905 * @alias element.all(locator).last()
906 * @view
907 * <ul class="items">
908 * <li>First</li>
909 * <li>Second</li>
910 * <li>Third</li>
911 * </ul>
912 *
913 * @example
914 * var last = element.all(by.css('.items li')).last();
915 * expect(last.getText()).toBe('Third');
916 *
917 * @return {ElementFinder} finder representing the last matching element
918 */
919 last(): ElementFinder;
920
921 /**
922 * Count the number of elements represented by the ElementArrayFinder.
923 *
924 * @alias element.all(locator).count()
925 * @view
926 * <ul class="items">
927 * <li>First</li>
928 * <li>Second</li>
929 * <li>Third</li>
930 * </ul>
931 *
932 * @example
933 * var list = element.all(by.css('.items li'));
934 * expect(list.count()).toBe(3);
935 *
936 * @return {!webdriver.promise.Promise} A promise which resolves to the
937 * number of elements matching the locator.
938 */
939 count(): webdriver.promise.Promise<number>;
940
941 /**
942 * Calls the input function on each ElementFinder represented by the ElementArrayFinder.
943 *
944 * @alias element.all(locator).each(eachFunction)
945 * @view
946 * <ul class="items">
947 * <li>First</li>
948 * <li>Second</li>
949 * <li>Third</li>
950 * </ul>
951 *
952 * @example
953 * element.all(by.css('.items li')).each(function(element) {
954 * // Will print First, Second, Third.
955 * element.getText().then(console.log);
956 * });
957 *
958 * @param {function(ElementFinder)} fn Input function
959 */
960 each(fn: (element: ElementFinder, index: number) => void): void;
961
962 /**
963 * Apply a map function to each element within the ElementArrayFinder. The
964 * callback receives the ElementFinder as the first argument and the index as
965 * a second arg.
966 *
967 * @alias element.all(locator).map(mapFunction)
968 * @view
969 * <ul class="items">
970 * <li class="one">First</li>
971 * <li class="two">Second</li>
972 * <li class="three">Third</li>
973 * </ul>
974 *
975 * @example
976 * var items = element.all(by.css('.items li')).map(function(elm, index) {
977 * return {
978 * index: index,
979 * text: elm.getText(),
980 * class: elm.getAttribute('class')
981 * };
982 * });
983 * expect(items).toEqual([
984 * {index: 0, text: 'First', class: 'one'},
985 * {index: 1, text: 'Second', class: 'two'},
986 * {index: 2, text: 'Third', class: 'three'}
987 * ]);
988 *
989 * @param {function(ElementFinder, number)} mapFn Map function that
990 * will be applied to each element.
991 * @return {!webdriver.promise.Promise} A promise that resolves to an array
992 * of values returned by the map function.
993 */
994 map<T>(mapFn: (element: ElementFinder, index: number) => T): webdriver.promise.Promise<T[]>;
995
996 /**
997 * Apply a filter function to each element within the ElementArrayFinder. Returns
998 * a new ElementArrayFinder with all elements that pass the filter function. The
999 * filter function receives the ElementFinder as the first argument
1000 * and the index as a second arg.
1001 * This does not actually retrieve the underlying list of elements, so it can
1002 * be used in page objects.
1003 *
1004 * @alias element.all(locator).filter(filterFn)
1005 * @view
1006 * <ul class="items">
1007 * <li class="one">First</li>
1008 * <li class="two">Second</li>
1009 * <li class="three">Third</li>
1010 * </ul>
1011 *
1012 * @example
1013 * element.all(by.css('.items li')).filter(function(elem, index) {
1014 * return elem.getText().then(function(text) {
1015 * return text === 'Third';
1016 * });
1017 * }).then(function(filteredElements) {
1018 * filteredElements[0].click();
1019 * });
1020 *
1021 * @param {function(ElementFinder, number): webdriver.WebElement.Promise} filterFn
1022 * Filter function that will test if an element should be returned.
1023 * filterFn can either return a boolean or a promise that resolves to a boolean.
1024 * @return {!ElementArrayFinder} A ElementArrayFinder that represents an array
1025 * of element that satisfy the filter function.
1026 */
1027 filter(filterFn: (element: ElementFinder, index: number) => any): ElementArrayFinder;
1028
1029 /**
1030 * Apply a reduce function against an accumulator and every element found
1031 * using the locator (from left-to-right). The reduce function has to reduce
1032 * every element into a single value (the accumulator). Returns promise of
1033 * the accumulator. The reduce function receives the accumulator, current
1034 * ElementFinder, the index, and the entire array of ElementFinders,
1035 * respectively.
1036 *
1037 * @alias element.all(locator).reduce(reduceFn)
1038 * @view
1039 * <ul class="items">
1040 * <li class="one">First</li>
1041 * <li class="two">Second</li>
1042 * <li class="three">Third</li>
1043 * </ul>
1044 *
1045 * @example
1046 * var value = element.all(by.css('.items li')).reduce(function(acc, elem) {
1047 * return elem.getText().then(function(text) {
1048 * return acc + text + ' ';
1049 * });
1050 * });
1051 *
1052 * expect(value).toEqual('First Second Third ');
1053 *
1054 * @param {function(number, ElementFinder, number, Array.<ElementFinder>)}
1055 * reduceFn Reduce function that reduces every element into a single value.
1056 * @param {*} initialValue Initial value of the accumulator.
1057 * @return {!webdriver.promise.Promise} A promise that resolves to the final
1058 * value of the accumulator.
1059 */
1060 reduce<T>(reduceFn: (acc: T, element: ElementFinder, index: number, arr: ElementFinder[]) => webdriver.promise.Promise<T>, initialValue: T): webdriver.promise.Promise<T>;
1061 reduce<T>(reduceFn: (acc: T, element: ElementFinder, index: number, arr: ElementFinder[]) => T, initialValue: T): webdriver.promise.Promise<T>;
1062
1063 /**
1064 * Represents the ElementArrayFinder as an array of ElementFinders.
1065 *
1066 * @return {Array.<ElementFinder>} Return a promise, which resolves to a list
1067 * of ElementFinders specified by the locator.
1068 */
1069 asElementFinders_(): webdriver.promise.Promise<ElementFinder[]>;
1070
1071 /**
1072 * Create a shallow copy of ElementArrayFinder.
1073 *
1074 * @return {!ElementArrayFinder} A shallow copy of this.
1075 */
1076 clone(): ElementArrayFinder;
1077
1078 /**
1079 * Calls to ElementArrayFinder may be chained to find an array of elements
1080 * using the current elements in this ElementArrayFinder as the starting point.
1081 * This function returns a new ElementArrayFinder which would contain the
1082 * children elements found (and could also be empty).
1083 *
1084 * @alias element.all(locator).all(locator)
1085 * @view
1086 * <div id='id1' class="parent">
1087 * <ul>
1088 * <li class="foo">1a</li>
1089 * <li class="baz">1b</li>
1090 * </ul>
1091 * </div>
1092 * <div id='id2' class="parent">
1093 * <ul>
1094 * <li class="foo">2a</li>
1095 * <li class="bar">2b</li>
1096 * </ul>
1097 * </div>
1098 *
1099 * @example
1100 * var foo = element.all(by.css('.parent')).all(by.css('.foo'))
1101 * expect(foo.getText()).toEqual(['1a', '2a'])
1102 * var baz = element.all(by.css('.parent')).all(by.css('.baz'))
1103 * expect(baz.getText()).toEqual(['1b'])
1104 * var nonexistent = element.all(by.css('.parent')).all(by.css('.NONEXISTENT'))
1105 * expect(nonexistent.getText()).toEqual([''])
1106 *
1107 * @param {webdriver.Locator} subLocator
1108 * @return {ElementArrayFinder}
1109 */
1110 all(locator: webdriver.Locator): ElementArrayFinder;
1111
1112 /**
1113 * Shorthand function for finding arrays of elements by css.
1114 *
1115 * @type {function(string): ElementArrayFinder}
1116 */
1117 $$(selector: string): ElementArrayFinder;
1118
1119 /**
1120 * Returns an ElementFinder representation of ElementArrayFinder. It ensures
1121 * that the ElementArrayFinder resolves to one and only one underlying element.
1122 *
1123 * @return {ElementFinder} An ElementFinder representation
1124 * @private
1125 */
1126 toElementFinder_(): ElementFinder;
1127
1128 /**
1129 * Returns the most relevant locator.
1130 *
1131 * @example
1132 * $('#ID1').locator() // returns by.css('#ID1')
1133 * $('#ID1').$('#ID2').locator() // returns by.css('#ID2')
1134 * $$('#ID1').filter(filterFn).get(0).click().locator() // returns by.css('#ID1')
1135 *
1136 * @return {webdriver.Locator}
1137 */
1138 locator(): webdriver.Locator;
1139
1140 /**
1141 * Evaluates the input as if it were on the scope of the current underlying
1142 * elements.
1143 *
1144 * @view
1145 * <span id="foo">{{variableInScope}}</span>
1146 *
1147 * @example
1148 * var value = element(by.id('foo')).evaluate('variableInScope');
1149 *
1150 * @param {string} expression
1151 *
1152 * @return {ElementArrayFinder} which resolves to the
1153 * evaluated expression for each underlying element.
1154 * The result will be resolved as in
1155 * {@link webdriver.WebDriver.executeScript}. In summary - primitives will
1156 * be resolved as is, functions will be converted to string, and elements
1157 * will be returned as a WebElement.
1158 */
1159 evaluate(expression: string): ElementArrayFinder;
1160
1161 /**
1162 * Determine if animation is allowed on the current underlying elements.
1163 * @param {string} value
1164 *
1165 * @example
1166 * // Turns off ng-animate animations for all elements in the <body>
1167 * element(by.css('body')).allowAnimations(false);
1168 *
1169 * @return {ElementArrayFinder} which resolves to whether animation is allowed.
1170 */
1171 allowAnimations(value: boolean): ElementArrayFinder;
1172
1173 /**
1174 * Schedules a command to click on this element.
1175 * @return {!webdriver.promise.Promise} A promise that will be resolved when
1176 * the click command has completed.
1177 */
1178 click(): webdriver.promise.Promise<void>;
1179
1180 /**
1181 * Schedules a command to type a sequence on the DOM element represented by this
1182 * instance.
1183 * <p/>
1184 * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is
1185 * processed in the keysequence, that key state is toggled until one of the
1186 * following occurs:
1187 * <ul>
1188 * <li>The modifier key is encountered again in the sequence. At this point the
1189 * state of the key is toggled (along with the appropriate keyup/down events).
1190 * </li>
1191 * <li>The {@code webdriver.Key.NULL} key is encountered in the sequence. When
1192 * this key is encountered, all modifier keys current in the down state are
1193 * released (with accompanying keyup events). The NULL key can be used to
1194 * simulate common keyboard shortcuts:
1195 * <code>
1196 * element.sendKeys("text was",
1197 * webdriver.Key.CONTROL, "a", webdriver.Key.NULL,
1198 * "now text is");
1199 * // Alternatively:
1200 * element.sendKeys("text was",
1201 * webdriver.Key.chord(webdriver.Key.CONTROL, "a"),
1202 * "now text is");
1203 * </code></li>
1204 * <li>The end of the keysequence is encountered. When there are no more keys
1205 * to type, all depressed modifier keys are released (with accompanying keyup
1206 * events).
1207 * </li>
1208 * </ul>
1209 * <strong>Note:</strong> On browsers where native keyboard events are not yet
1210 * supported (e.g. Firefox on OS X), key events will be synthesized. Special
1211 * punctionation keys will be synthesized according to a standard QWERTY en-us
1212 * keyboard layout.
1213 *
1214 * @param {...string} var_args The sequence of keys to
1215 * type. All arguments will be joined into a single sequence (var_args is
1216 * permitted for convenience).
1217 * @return {!webdriver.promise.Promise} A promise that will be resolved when all
1218 * keys have been typed.
1219 */
1220 sendKeys(...var_args: string[]): webdriver.promise.Promise<void>;
1221
1222 /**
1223 * Schedules a command to query for the tag/node name of this element.
1224 * @return {!webdriver.promise.Promise} A promise that will be resolved with the
1225 * element's tag name.
1226 */
1227 getTagName(): webdriver.promise.Promise<string[]>;
1228
1229 /**
1230 * Schedules a command to query for the computed style of the element
1231 * represented by this instance. If the element inherits the named style from
1232 * its parent, the parent will be queried for its value. Where possible, color
1233 * values will be converted to their hex representation (e.g. #00ff00 instead of
1234 * rgb(0, 255, 0)).
1235 * <p/>
1236 * <em>Warning:</em> the value returned will be as the browser interprets it, so
1237 * it may be tricky to form a proper assertion.
1238 *
1239 * @param {string} cssStyleProperty The name of the CSS style property to look
1240 * up.
1241 * @return {!webdriver.promise.Promise} A promise that will be resolved with the
1242 * requested CSS value.
1243 */
1244 getCssValue(cssStyleProperty: string): webdriver.promise.Promise<string[]>;
1245
1246 /**
1247 * Schedules a command to query for the value of the given attribute of the
1248 * element. Will return the current value even if it has been modified after the
1249 * page has been loaded. More exactly, this method will return the value of the
1250 * given attribute, unless that attribute is not present, in which case the
1251 * value of the property with the same name is returned. If neither value is
1252 * set, null is returned. The "style" attribute is converted as best can be to a
1253 * text representation with a trailing semi-colon. The following are deemed to
1254 * be "boolean" attributes and will be returned as thus:
1255 *
1256 * <p>async, autofocus, autoplay, checked, compact, complete, controls, declare,
1257 * defaultchecked, defaultselected, defer, disabled, draggable, ended,
1258 * formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope,
1259 * loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open,
1260 * paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
1261 * selected, spellcheck, truespeed, willvalidate
1262 *
1263 * <p>Finally, the following commonly mis-capitalized attribute/property names
1264 * are evaluated as expected:
1265 * <ul>
1266 * <li>"class"
1267 * <li>"readonly"
1268 * </ul>
1269 * @param {string} attributeName The name of the attribute to query.
1270 * @return {!webdriver.promise.Promise} A promise that will be resolved with the
1271 * attribute's value.
1272 */
1273 getAttribute(attributeName: string): webdriver.promise.Promise<string[]>;
1274
1275 /**
1276 * Get the visible (i.e. not hidden by CSS) innerText of this element, including
1277 * sub-elements, without any leading or trailing whitespace.
1278 * @return {!webdriver.promise.Promise} A promise that will be resolved with the
1279 * element's visible text.
1280 */
1281 getText(): webdriver.promise.Promise<string[]>;
1282
1283 /**
1284 * Schedules a command to compute the size of this element's bounding box, in
1285 * pixels.
1286 * @return {!webdriver.promise.Promise} A promise that will be resolved with the
1287 * element's size as a {@code {width:number, height:number}} object.
1288 */
1289 getSize(): webdriver.promise.Promise<webdriver.ISize[]>;
1290
1291 /**
1292 * Schedules a command to compute the location of this element in page space.
1293 * @return {!webdriver.promise.Promise} A promise that will be resolved to the
1294 * element's location as a {@code {x:number, y:number}} object.
1295 */
1296 getLocation(): webdriver.promise.Promise<webdriver.ILocation[]>;
1297
1298 /**
1299 * Schedules a command to query whether the DOM element represented by this
1300 * instance is enabled, as dicted by the {@code disabled} attribute.
1301 * @return {!webdriver.promise.Promise} A promise that will be resolved with
1302 * whether this element is currently enabled.
1303 */
1304 isEnabled(): webdriver.promise.Promise<boolean[]>;
1305
1306 /**
1307 * Schedules a command to query whether this element is selected.
1308 * @return {!webdriver.promise.Promise} A promise that will be resolved with
1309 * whether this element is currently selected.
1310 */
1311 isSelected(): webdriver.promise.Promise<boolean[]>;
1312
1313 /**
1314 * Schedules a command to submit the form containing this element (or this
1315 * element if it is a FORM element). This command is a no-op if the element is
1316 * not contained in a form.
1317 * @return {!webdriver.promise.Promise} A promise that will be resolved when
1318 * the form has been submitted.
1319 */
1320 submit(): webdriver.promise.Promise<void>;
1321
1322 /**
1323 * Schedules a command to clear the {@code value} of this element. This command
1324 * has no effect if the underlying DOM element is neither a text INPUT element
1325 * nor a TEXTAREA element.
1326 * @return {!webdriver.promise.Promise} A promise that will be resolved when
1327 * the element has been cleared.
1328 */
1329 clear(): webdriver.promise.Promise<void>;
1330
1331 /**
1332 * Schedules a command to test whether this element is currently displayed.
1333 * @return {!webdriver.promise.Promise} A promise that will be resolved with
1334 * whether this element is currently visible on the page.
1335 */
1336 isDisplayed(): webdriver.promise.Promise<boolean[]>;
1337
1338 /**
1339 * Schedules a command to retrieve the outer HTML of this element.
1340 * @return {!webdriver.promise.Promise} A promise that will be resolved with
1341 * the element's outer HTML.
1342 */
1343 getOuterHtml(): webdriver.promise.Promise<string[]>;
1344
1345 /**
1346 * @return {!webdriver.promise.Promise.<webdriver.WebElement.Id>} A promise
1347 * that resolves to this element's JSON representation as defined by the
1348 * WebDriver wire protocol.
1349 * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol
1350 */
1351 getId(): webdriver.promise.Promise<webdriver.IWebElementId[]>
1352
1353 /**
1354 * Schedules a command to retrieve the inner HTML of this element.
1355 * @return {!webdriver.promise.Promise} A promise that will be resolved with the
1356 * element's inner HTML.
1357 */
1358 getInnerHtml(): webdriver.promise.Promise<string[]>;
1359 }
1360
1361 interface LocatorWithColumn extends webdriver.Locator {
1362 column(index: number): webdriver.Locator;
1363 column(name: string): webdriver.Locator;
1364 }
1365
1366 interface RepeaterLocator extends LocatorWithColumn {
1367 row(index: number): LocatorWithColumn;
1368 }
1369
1370 interface IProtractorLocatorStrategy {
1371 /**
1372 * webdriver's By is an enum of locator functions, so we must set it to
1373 * a prototype before inheriting from it.
1374 */
1375 className: typeof webdriver.By.className;
1376 css: typeof webdriver.By.css;
1377 id: typeof webdriver.By.id;
1378 linkText: typeof webdriver.By.linkText;
1379 js: typeof webdriver.By.js;
1380 name: typeof webdriver.By.name;
1381 partialLinkText: typeof webdriver.By.partialLinkText;
1382 tagName: typeof webdriver.By.tagName;
1383 xpath: typeof webdriver.By.xpath;
1384
1385 /**
1386 * Add a locator to this instance of ProtractorBy. This locator can then be
1387 * used with element(by.locatorName(args)).
1388 *
1389 * @view
1390 * <button ng-click="doAddition()">Go!</button>
1391 *
1392 * @example
1393 * // Add the custom locator.
1394 * by.addLocator('buttonTextSimple',
1395 * function(buttonText, opt_parentElement, opt_rootSelector) {
1396 * // This function will be serialized as a string and will execute in the
1397 * // browser. The first argument is the text for the button. The second
1398 * // argument is the parent element, if any.
1399 * var using = opt_parentElement,
1400 * buttons = using.querySelectorAll('button');
1401 *
1402 * // Return an array of buttons with the text.
1403 * return Array.prototype.filter.call(buttons, function(button) {
1404 * return button.textContent === buttonText;
1405 * });
1406 * });
1407 *
1408 * // Use the custom locator.
1409 * element(by.buttonTextSimple('Go!')).click();
1410 *
1411 * @alias by.addLocator(locatorName, functionOrScript)
1412 * @param {string} name The name of the new locator.
1413 * @param {Function|string} script A script to be run in the context of
1414 * the browser. This script will be passed an array of arguments
1415 * that contains any args passed into the locator followed by the
1416 * element scoping the search and the css selector for the root angular
1417 * element. It should return an array of elements.
1418 */
1419 addLocator(name: string, script: string): void;
1420 addLocator(name: string, script: Function): void;
1421
1422 /**
1423 * Find an element by binding.
1424 *
1425 * @view
1426 * <span>{{person.name}}</span>
1427 * <span ng-bind="person.email"></span>
1428 *
1429 * @example
1430 * var span1 = element(by.binding('person.name'));
1431 * expect(span1.getText()).toBe('Foo');
1432 *
1433 * var span2 = element(by.binding('person.email'));
1434 * expect(span2.getText()).toBe('foo@bar.com');
1435 *
1436 * @param {string} bindingDescriptor
1437 * @return {{findElementsOverride: findElementsOverride, toString: Function|string}}
1438 */
1439 binding(bindingDescriptor: string): webdriver.Locator;
1440
1441 /**
1442 * Find an element by exact binding.
1443 *
1444 * @view
1445 * <span>{{ person.name }}</span>
1446 * <span ng-bind="person-email"></span>
1447 * <span>{{person_phone|uppercase}}</span>
1448 *
1449 * @example
1450 * expect(element(by.exactBinding('person.name')).isPresent()).toBe(true);
1451 * expect(element(by.exactBinding('person-email')).isPresent()).toBe(true);
1452 * expect(element(by.exactBinding('person')).isPresent()).toBe(false);
1453 * expect(element(by.exactBinding('person_phone')).isPresent()).toBe(true);
1454 * expect(element(by.exactBinding('person_phone|uppercase')).isPresent()).toBe(true);
1455 * expect(element(by.exactBinding('phone')).isPresent()).toBe(false);
1456 *
1457 * @param {string} bindingDescriptor
1458 * @return {{findElementsOverride: findElementsOverride, toString: Function|string}}
1459 */
1460 exactBinding(bindingDescriptor: string): webdriver.Locator;
1461
1462 /**
1463 * Find an element by ng-model expression.
1464 *
1465 * @alias by.model(modelName)
1466 * @view
1467 * <input type="text" ng-model="person.name"/>
1468 *
1469 * @example
1470 * var input = element(by.model('person.name'));
1471 * input.sendKeys('123');
1472 * expect(input.getAttribute('value')).toBe('Foo123');
1473 *
1474 * @param {string} model ng-model expression.
1475 */
1476 model(model: string): webdriver.Locator;
1477
1478 /**
1479 * Find a button by text.
1480 *
1481 * @view
1482 * <button>Save</button>
1483 *
1484 * @example
1485 * element(by.buttonText('Save'));
1486 *
1487 * @param {string} searchText
1488 * @return {{findElementsOverride: findElementsOverride, toString: Function|string}}
1489 */
1490 buttonText(searchText: string): webdriver.Locator;
1491
1492 /**
1493 * Find a button by partial text.
1494 *
1495 * @view
1496 * <button>Save my file</button>
1497 *
1498 * @example
1499 * element(by.partialButtonText('Save'));
1500 *
1501 * @param {string} searchText
1502 * @return {{findElementsOverride: findElementsOverride, toString: Function|string}}
1503 */
1504 partialButtonText(searchText: string): webdriver.Locator;
1505
1506
1507 /**
1508 * Find elements inside an ng-repeat.
1509 *
1510 * @view
1511 * <div ng-repeat="cat in pets">
1512 * <span>{{cat.name}}</span>
1513 * <span>{{cat.age}}</span>
1514 * </div>
1515 *
1516 * <div class="book-img" ng-repeat-start="book in library">
1517 * <span>{{$index}}</span>
1518 * </div>
1519 * <div class="book-info" ng-repeat-end>
1520 * <h4>{{book.name}}</h4>
1521 * <p>{{book.blurb}}</p>
1522 * </div>
1523 *
1524 * @example
1525 * // Returns the DIV for the second cat.
1526 * var secondCat = element(by.repeater('cat in pets').row(1));
1527 *
1528 * // Returns the SPAN for the first cat's name.
1529 * var firstCatName = element(by.repeater('cat in pets').
1530 * row(0).column('{{cat.name}}'));
1531 *
1532 * // Returns a promise that resolves to an array of WebElements from a column
1533 * var ages = element.all(
1534 * by.repeater('cat in pets').column('{{cat.age}}'));
1535 *
1536 * // Returns a promise that resolves to an array of WebElements containing
1537 * // all top level elements repeated by the repeater. For 2 pets rows resolves
1538 * // to an array of 2 elements.
1539 * var rows = element.all(by.repeater('cat in pets'));
1540 *
1541 * // Returns a promise that resolves to an array of WebElements containing all
1542 * // the elements with a binding to the book's name.
1543 * var divs = element.all(by.repeater('book in library').column('book.name'));
1544 *
1545 * // Returns a promise that resolves to an array of WebElements containing
1546 * // the DIVs for the second book.
1547 * var bookInfo = element.all(by.repeater('book in library').row(1));
1548 *
1549 * // Returns the H4 for the first book's name.
1550 * var firstBookName = element(by.repeater('book in library').
1551 * row(0).column('{{book.name}}'));
1552 *
1553 * // Returns a promise that resolves to an array of WebElements containing
1554 * // all top level elements repeated by the repeater. For 2 books divs
1555 * // resolves to an array of 4 elements.
1556 * var divs = element.all(by.repeater('book in library'));
1557 */
1558 repeater(repeatDescriptor: string): RepeaterLocator;
1559
1560 /**
1561 * Find elements by CSS which contain a certain string.
1562 *
1563 * @view
1564 * <ul>
1565 * <li class="pet">Dog</li>
1566 * <li class="pet">Cat</li>
1567 * </ul>
1568 *
1569 * @example
1570 * // Returns the DIV for the dog, but not cat.
1571 * var dog = element(by.cssContainingText('.pet', 'Dog'));
1572 */
1573 cssContainingText(cssSelector: string, searchText: string): webdriver.Locator;
1574
1575 /**
1576 * Find an element by ng-options expression.
1577 *
1578 * @alias by.options(optionsDescriptor)
1579 * @view
1580 * <select ng-model="color" ng-options="c for c in colors">
1581 * <option value="0" selected="selected">red</option>
1582 * <option value="1">green</option>
1583 * </select>
1584 *
1585 * @example
1586 * var allOptions = element.all(by.options('c for c in colors'));
1587 * expect(allOptions.count()).toEqual(2);
1588 * var firstOption = allOptions.first();
1589 * expect(firstOption.getText()).toEqual('red');
1590 *
1591 * @param {string} optionsDescriptor ng-options expression.
1592 */
1593 options(optionsDescriptor: string): webdriver.Locator;
1594 }
1595
1596 var By: IProtractorLocatorStrategy;
1597
1598 interface Protractor extends webdriver.WebDriver {
1599
1600 /**
1601 * The wrapped webdriver instance. Use this to interact with pages that do
1602 * not contain Angular (such as a log-in screen).
1603 *
1604 * @type {webdriver.WebDriver}
1605 */
1606 driver: webdriver.WebDriver;
1607
1608 /**
1609 * Helper function for finding elements.
1610 *
1611 * @type {function(webdriver.Locator): ElementFinder}
1612 */
1613 element(locator: webdriver.Locator): ElementFinder;
1614
1615 /**
1616 * Shorthand function for finding elements by css.
1617 *
1618 * @type {function(string): ElementFinder}
1619 */
1620 $(selector: string): ElementFinder;
1621
1622 /**
1623 * Shorthand function for finding arrays of elements by css.
1624 *
1625 * @type {function(string): ElementArrayFinder}
1626 */
1627 $$(selector: string): ElementArrayFinder;
1628
1629 /**
1630 * All get methods will be resolved against this base URL. Relative URLs are =
1631 * resolved the way anchor tags resolve.
1632 *
1633 * @type {string}
1634 */
1635 baseUrl: string;
1636
1637 /**
1638 * The css selector for an element on which to find Angular. This is usually
1639 * 'body' but if your ng-app is on a subsection of the page it may be
1640 * a subelement.
1641 *
1642 * @type {string}
1643 */
1644 rootEl: string;
1645
1646 /**
1647 * If true, Protractor will not attempt to synchronize with the page before
1648 * performing actions. This can be harmful because Protractor will not wait
1649 * until $timeouts and $http calls have been processed, which can cause
1650 * tests to become flaky. This should be used only when necessary, such as
1651 * when a page continuously polls an API using $timeout.
1652 *
1653 * @type {boolean}
1654 */
1655 ignoreSynchronization: boolean;
1656
1657 /**
1658 * Timeout in milliseconds to wait for pages to load when calling `get`.
1659 *
1660 * @type {number}
1661 */
1662 getPageTimeout: number;
1663
1664 /**
1665 * An object that holds custom test parameters.
1666 *
1667 * @type {Object}
1668 */
1669 params: any;
1670
1671 /**
1672 * The reset URL to use between page loads.
1673 *
1674 * @type {string}
1675 */
1676 resetUrl: string;
1677
1678 /**
1679 * Instruct webdriver to wait until Angular has finished rendering and has
1680 * no outstanding $http calls before continuing.
1681 *
1682 * @return {!webdriver.promise.Promise} A promise that will resolve to the
1683 * scripts return value.
1684 */
1685 waitForAngular(): webdriver.promise.Promise<void>;
1686
1687 /**
1688 * Add a module to load before Angular whenever Protractor.get is called.
1689 * Modules will be registered after existing modules already on the page,
1690 * so any module registered here will override preexisting modules with the same
1691 * name.
1692 *
1693 * @example
1694 * browser.addMockModule('modName', function() {
1695 * angular.module('modName', []).value('foo', 'bar');
1696 * });
1697 *
1698 * @param {!string} name The name of the module to load or override.
1699 * @param {!string|Function} script The JavaScript to load the module.
1700 * @param {...*} varArgs Any additional arguments will be provided to
1701 * the script and may be referenced using the `arguments` object.
1702 */
1703 addMockModule(name: string, script: string, ...varArgs: any[]): void;
1704 addMockModule(name: string, script: Function, ...varArgs: any[]): void;
1705
1706 /**
1707 * Clear the list of registered mock modules.
1708 */
1709 clearMockModules(): void;
1710
1711 /**
1712 * Remove a registered mock module.
1713 *
1714 * @example
1715 * browser.removeMockModule('modName');
1716 *
1717 * @param {!string} name The name of the module to remove.
1718 */
1719 removeMockModule(name: string): void;
1720
1721 /**
1722 * @see webdriver.WebDriver.get
1723 *
1724 * Navigate to the given destination and loads mock modules before
1725 * Angular. Assumes that the page being loaded uses Angular.
1726 * If you need to access a page which does not have Angular on load, use
1727 * the wrapped webdriver directly.
1728 *
1729 * @param {string} destination Destination URL.
1730 * @param {number=} opt_timeout Number of milliseconds to wait for Angular to
1731 * start.
1732 */
1733 get(destination: string, opt_timeout?: number): webdriver.promise.Promise<void>;
1734
1735 /**
1736 * See webdriver.WebDriver.refresh
1737 *
1738 * Makes a full reload of the current page and loads mock modules before
1739 * Angular. Assumes that the page being loaded uses Angular.
1740 * If you need to access a page which does not have Angular on load, use
1741 * the wrapped webdriver directly.
1742 *
1743 * @param {number=} opt_timeout Number of seconds to wait for Angular to start.
1744 */
1745 refresh(opt_timeout?: number): webdriver.promise.Promise<void>;
1746
1747 /**
1748 * Browse to another page using in-page navigation.
1749 *
1750 * @param {string} url In page URL using the same syntax as $location.url()
1751 * @returns {!webdriver.promise.Promise} A promise that will resolve once
1752 * page has been changed.
1753 */
1754 setLocation(url: string): webdriver.promise.Promise<void>;
1755
1756 /**
1757 * Returns the current absolute url from AngularJS.
1758 */
1759 getLocationAbsUrl(): webdriver.promise.Promise<string>;
1760
1761 /**
1762 * Pauses the test and injects some helper functions into the browser, so that
1763 * debugging may be done in the browser console.
1764 *
1765 * This should be used under node in debug mode, i.e. with
1766 * protractor debug <configuration.js>
1767 *
1768 * @example
1769 * While in the debugger, commands can be scheduled through webdriver by
1770 * entering the repl:
1771 * debug> repl
1772 * Press Ctrl + C to leave rdebug repl
1773 * > ptor.findElement(protractor.By.input('user').sendKeys('Laura'));
1774 * > ptor.debugger();
1775 * debug> c
1776 *
1777 * This will run the sendKeys command as the next task, then re-enter the
1778 * debugger.
1779 */
1780 debugger(): void;
1781
1782 /**
1783 * Beta (unstable) pause function for debugging webdriver tests. Use
1784 * browser.pause() in your test to enter the protractor debugger from that
1785 * point in the control flow.
1786 * Does not require changes to the command line (no need to add 'debug').
1787 *
1788 * @example
1789 * element(by.id('foo')).click();
1790 * browser.pause();
1791 * // Execution will stop before the next click action.
1792 * element(by.id('bar')).click();
1793 *
1794 * @param {number=} opt_debugPort Optional port to use for the debugging process
1795 */
1796 pause(opt_debugPort?: number): void;
1797 }
1798
1799 // Interface for the global browser object.
1800 interface IBrowser extends Protractor {
1801 /**
1802 * Fork another instance of protractor for use in interactive tests.
1803 *
1804 * @param {boolean} opt_useSameUrl Whether to navigate to current url on creation
1805 * @param {boolean} opt_copyMockModules Whether to apply same mock modules on creation
1806 * @return {Protractor} a protractor instance.
1807 */
1808 forkNewDriverInstance(opt_useSameUrl?: boolean, opt_copyMockModules?: boolean): Protractor;
1809
1810 /**
1811 * Get the processed configuration object that is currently being run. This will contain
1812 * the specs and capabilities properties of the current runner instance.
1813 *
1814 * Set by the runner.
1815 *
1816 * @return {webdriver.promise.Promise<any>} A promise which resolves to the capabilities object.
1817 */
1818 getProcessedConfig(): webdriver.promise.Promise<any>;
1819 }
1820
1821 /**
1822 * Create a new instance of Protractor by wrapping a webdriver instance.
1823 *
1824 * @param {webdriver.WebDriver} webdriver The configured webdriver instance.
1825 * @param {string=} opt_baseUrl A URL to prepend to relative gets.
1826 * @return {Protractor}
1827 */
1828 function wrapDriver(webdriver: webdriver.WebDriver, opt_baseUrl?: string, opt_rootElement?: string): Protractor;
1829}
1830
1831interface cssSelectorHelper {
1832 (cssLocator: string): protractor.ElementFinder;
1833}
1834
1835interface cssArraySelectorHelper {
1836 (cssLocator: string): protractor.ElementArrayFinder;
1837}
1838
1839declare var browser: protractor.IBrowser;
1840declare var by: protractor.IProtractorLocatorStrategy;
1841declare var By: protractor.IProtractorLocatorStrategy;
1842declare var element: protractor.Element;
1843declare var $: cssSelectorHelper;
1844declare var $$: cssArraySelectorHelper;
1845
1846declare module 'protractor' {
1847 export = protractor;
1848}
1849
\No newline at end of file