UNPKG

21.2 kBTypeScriptView Raw
1import { BPClient } from 'blocking-proxy';
2import { promise as wdpromise, WebDriver, WebElement, WebElementPromise } from 'selenium-webdriver';
3import { ExtendedWebDriver } from 'webdriver-js-extender';
4import { DebugHelper } from './debugger';
5import { ElementArrayFinder, ElementFinder } from './element';
6import { ProtractorExpectedConditions } from './expectedConditions';
7import { Locator, ProtractorBy } from './locators';
8import { Plugins } from './plugins';
9export declare class AbstractWebDriver {
10}
11export interface AbstractWebDriver extends WebDriver {
12}
13export declare class AbstractExtendedWebDriver extends AbstractWebDriver {
14}
15export interface AbstractExtendedWebDriver extends ExtendedWebDriver {
16}
17export interface ElementHelper extends Function {
18 (locator: Locator): ElementFinder;
19 all: (locator: Locator) => ElementArrayFinder;
20}
21/**
22 * @alias browser
23 * @constructor
24 * @extends {webdriver_extensions.ExtendedWebDriver}
25 * @param {webdriver.WebDriver} webdriver
26 * @param {string=} opt_baseUrl A base URL to run get requests against.
27 * @param {string|webdriver.promise.Promise<string>=} opt_rootElement Selector element that has an
28 * ng-app in scope.
29 * @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
30 * stop tracking outstanding $timeouts.
31 */
32export declare class ProtractorBrowser extends AbstractExtendedWebDriver {
33 /**
34 * @type {ProtractorBy}
35 */
36 static By: ProtractorBy;
37 /**
38 * @type {ExpectedConditions}
39 */
40 ExpectedConditions: ProtractorExpectedConditions;
41 /**
42 * The wrapped webdriver instance. Use this to interact with pages that do
43 * not contain Angular (such as a log-in screen).
44 *
45 * @type {webdriver_extensions.ExtendedWebDriver}
46 */
47 driver: ExtendedWebDriver;
48 /**
49 * The client used to control the BlockingProxy. If unset, BlockingProxy is
50 * not being used and Protractor will handle client-side synchronization.
51 */
52 bpClient: BPClient;
53 /**
54 * Helper function for finding elements.
55 *
56 * @type {function(webdriver.Locator): ElementFinder}
57 */
58 element: ElementHelper;
59 /**
60 * Shorthand function for finding elements by css.
61 *
62 * @type {function(string): ElementFinder}
63 */
64 $: (query: string) => ElementFinder;
65 /**
66 * Shorthand function for finding arrays of elements by css.
67 *
68 * @type {function(string): ElementArrayFinder}
69 */
70 $$: (query: string) => ElementArrayFinder;
71 /**
72 * All get methods will be resolved against this base URL. Relative URLs are =
73 * resolved the way anchor tags resolve.
74 *
75 * @type {string}
76 */
77 baseUrl: string;
78 /**
79 * The css selector for an element on which to find Angular. This is usually
80 * 'body' but if your ng-app is on a subsection of the page it may be
81 * a subelement.
82 *
83 * This property is deprecated - please use angularAppRoot() instead.
84 *
85 * @deprecated
86 * @type {string}
87 */
88 rootEl: string;
89 private internalRootEl;
90 /**
91 * Set the css selector for an element on which to find Angular. This is usually
92 * 'body' but if your ng-app is on a subsection of the page it may be
93 * a subelement.
94 *
95 * The change will be made within WebDriver's control flow, so that commands after
96 * this method is called use the new app root. Pass nothing to get a promise that
97 * resolves to the value of the selector.
98 *
99 * @param {string|webdriver.promise.Promise<string>} value The new selector.
100 * @returns A promise that resolves with the value of the selector.
101 */
102 angularAppRoot(value?: string | wdpromise.Promise<string>): wdpromise.Promise<string>;
103 /**
104 * If true, Protractor will not attempt to synchronize with the page before
105 * performing actions. This can be harmful because Protractor will not wait
106 * until $timeouts and $http calls have been processed, which can cause
107 * tests to become flaky. This should be used only when necessary, such as
108 * when a page continuously polls an API using $timeout.
109 *
110 * Initialized to `false` by the runner.
111 *
112 * This property is deprecated - please use waitForAngularEnabled instead.
113 *
114 * @deprecated
115 * @type {boolean}
116 */
117 ignoreSynchronization: boolean;
118 private internalIgnoreSynchronization;
119 /**
120 * Timeout in milliseconds to wait for pages to load when calling `get`.
121 *
122 * @type {number}
123 */
124 getPageTimeout: number;
125 /**
126 * An object that holds custom test parameters.
127 *
128 * @type {Object}
129 */
130 params: any;
131 /**
132 * Resolved when the browser is ready for use. Resolves to the browser, so
133 * you can do:
134 *
135 * forkedBrowser = await browser.forkNewDriverInstance().ready;
136 *
137 * Set by the runner.
138 *
139 * @type {webdriver.promise.Promise.<ProtractorBrowser>}
140 */
141 ready: wdpromise.Promise<ProtractorBrowser>;
142 plugins_: Plugins;
143 /**
144 * The reset URL to use between page loads.
145 *
146 * @type {string}
147 */
148 resetUrl: string;
149 /**
150 * If true, Protractor will track outstanding $timeouts and report them in the
151 * error message if Protractor fails to synchronize with Angular in time.
152 * @private {boolean}
153 */
154 trackOutstandingTimeouts_: boolean;
155 allScriptsTimeout: number;
156 /**
157 * Information about mock modules that will be installed during every
158 * get().
159 *
160 * @type {Array<{name: string, script: function|string, args:
161 * Array.<string>}>}
162 */
163 mockModules_: {
164 name: string;
165 script: string | Function;
166 args: any[];
167 }[];
168 /**
169 * If specified, start a debugger server at specified port instead of repl
170 * when running element explorer.
171 * @public {number}
172 */
173 debuggerServerPort: number;
174 /**
175 * If true, Protractor will interpret any angular apps it comes across as
176 * hybrid angular1/angular2 apps.
177 *
178 * @type {boolean}
179 */
180 ng12Hybrid: boolean;
181 /**
182 * A helper that manages debugging tests.
183 */
184 debugHelper: DebugHelper;
185 [key: string]: any;
186 constructor(webdriverInstance: WebDriver, opt_baseUrl?: string, opt_rootElement?: string | wdpromise.Promise<string>, opt_untrackOutstandingTimeouts?: boolean, opt_blockingProxyUrl?: string);
187 /**
188 * If set to false, Protractor will not wait for Angular $http and $timeout
189 * tasks to complete before interacting with the browser. This can cause
190 * flaky tests, but should be used if, for instance, your app continuously
191 * polls an API with $timeout.
192 *
193 * Call waitForAngularEnabled() without passing a value to read the current
194 * state without changing it.
195 */
196 waitForAngularEnabled(enabled?: boolean | wdpromise.Promise<boolean>): wdpromise.Promise<boolean>;
197 /**
198 * Get the processed configuration object that is currently being run. This
199 * will contain the specs and capabilities properties of the current runner
200 * instance.
201 *
202 * Set by the runner.
203 *
204 * @returns {webdriver.promise.Promise} A promise which resolves to the
205 * capabilities object.
206 */
207 getProcessedConfig(): wdpromise.Promise<any>;
208 /**
209 * Fork another instance of browser for use in interactive tests.
210 *
211 * @example
212 * // Running with control flow enabled
213 * var fork = browser.forkNewDriverInstance();
214 * fork.get('page1'); // 'page1' gotten by forked browser
215 *
216 * // Running with control flow disabled
217 * var forked = await browser.forkNewDriverInstance().ready;
218 * await forked.get('page1'); // 'page1' gotten by forked browser
219 *
220 * @param {boolean=} useSameUrl Whether to navigate to current url on creation
221 * @param {boolean=} copyMockModules Whether to apply same mock modules on creation
222 * @param {boolean=} copyConfigUpdates Whether to copy over changes to `baseUrl` and similar
223 * properties initialized to values in the the config. Defaults to `true`
224 *
225 * @returns {ProtractorBrowser} A browser instance.
226 */
227 forkNewDriverInstance(useSameUrl?: boolean, copyMockModules?: boolean, copyConfigUpdates?: boolean): ProtractorBrowser;
228 /**
229 * Restart the browser. This is done by closing this browser instance and creating a new one.
230 * A promise resolving to the new instance is returned, and if this function was called on the
231 * global `browser` instance then Protractor will automatically overwrite the global `browser`
232 * variable.
233 *
234 * When restarting a forked browser, it is the caller's job to overwrite references to the old
235 * instance.
236 *
237 * This function behaves slightly differently depending on if the webdriver control flow is
238 * enabled. If the control flow is enabled, the global `browser` object is synchronously
239 * replaced. If the control flow is disabled, the global `browser` is replaced asynchronously
240 * after the old driver quits.
241 *
242 * Set by the runner.
243 *
244 * @example
245 * // Running against global browser, with control flow enabled
246 * browser.get('page1');
247 * browser.restart();
248 * browser.get('page2'); // 'page2' gotten by restarted browser
249 *
250 * // Running against global browser, with control flow disabled
251 * await browser.get('page1');
252 * await browser.restart();
253 * await browser.get('page2'); // 'page2' gotten by restarted browser
254 *
255 * // Running against forked browsers, with the control flow enabled
256 * // In this case, you may prefer `restartSync` (documented below)
257 * var forked = browser.forkNewDriverInstance();
258 * fork.get('page1');
259 * fork.restart().then(function(fork) {
260 * fork.get('page2'); // 'page2' gotten by restarted fork
261 * });
262 *
263 * // Running against forked browsers, with the control flow disabled
264 * var forked = await browser.forkNewDriverInstance().ready;
265 * await fork.get('page1');
266 * fork = await fork.restart();
267 * await fork.get('page2'); // 'page2' gotten by restarted fork
268 *
269 * // Unexpected behavior can occur if you save references to the global `browser`
270 * var savedBrowser = browser;
271 * browser.get('foo').then(function() {
272 * console.log(browser === savedBrowser); // false
273 * });
274 * browser.restart();
275 *
276 * @returns {webdriver.promise.Promise<ProtractorBrowser>} A promise resolving to the restarted
277 * browser
278 */
279 restart(): wdpromise.Promise<ProtractorBrowser>;
280 /**
281 * Like `restart`, but instead of returning a promise resolving to the new browser instance,
282 * returns the new browser instance directly. Can only be used when the control flow is enabled.
283 *
284 * @example
285 * // Running against global browser
286 * browser.get('page1');
287 * browser.restartSync();
288 * browser.get('page2'); // 'page2' gotten by restarted browser
289 *
290 * // Running against forked browsers
291 * var forked = browser.forkNewDriverInstance();
292 * fork.get('page1');
293 * fork = fork.restartSync();
294 * fork.get('page2'); // 'page2' gotten by restarted fork
295 *
296 * @throws {TypeError} Will throw an error if the control flow is not enabled
297 * @returns {ProtractorBrowser} The restarted browser
298 */
299 restartSync(): ProtractorBrowser;
300 /**
301 * Instead of using a single root element, search through all angular apps
302 * available on the page when finding elements or waiting for stability.
303 * Only compatible with Angular2.
304 */
305 useAllAngular2AppRoots(): void;
306 /**
307 * The same as {@code webdriver.WebDriver.prototype.executeScript},
308 * but with a customized description for debugging.
309 *
310 * @private
311 * @param {!(string|Function)} script The script to execute.
312 * @param {string} description A description of the command for debugging.
313 * @param {...*} var_args The arguments to pass to the script.
314 * @returns {!webdriver.promise.Promise.<T>} A promise that will resolve to
315 * the scripts return value.
316 * @template T
317 */
318 executeScriptWithDescription(script: string | Function, description: string, ...scriptArgs: any[]): wdpromise.Promise<any>;
319 /**
320 * The same as {@code webdriver.WebDriver.prototype.executeAsyncScript},
321 * but with a customized description for debugging.
322 *
323 * @private
324 * @param {!(string|Function)} script The script to execute.
325 * @param {string} description A description for debugging purposes.
326 * @param {...*} var_args The arguments to pass to the script.
327 * @returns {!webdriver.promise.Promise.<T>} A promise that will resolve to
328 * the
329 * scripts return value.
330 * @template T
331 */
332 private executeAsyncScript_(script, description, ...scriptArgs);
333 /**
334 * Instruct webdriver to wait until Angular has finished rendering and has
335 * no outstanding $http or $timeout calls before continuing.
336 * Note that Protractor automatically applies this command before every
337 * WebDriver action.
338 *
339 * @param {string=} opt_description An optional description to be added
340 * to webdriver logs.
341 * @returns {!webdriver.promise.Promise} A promise that will resolve to the
342 * scripts return value.
343 */
344 waitForAngular(opt_description?: string): wdpromise.Promise<any>;
345 /**
346 * Waits for Angular to finish rendering before searching for elements.
347 * @see webdriver.WebDriver.findElement
348 * @returns {!webdriver.WebElementPromise} A promise that will be resolved to
349 * the located {@link webdriver.WebElement}.
350 */
351 findElement(locator: Locator): WebElementPromise;
352 /**
353 * Waits for Angular to finish rendering before searching for elements.
354 * @see webdriver.WebDriver.findElements
355 * @returns {!webdriver.promise.Promise} A promise that will be resolved to an
356 * array of the located {@link webdriver.WebElement}s.
357 */
358 findElements(locator: Locator): wdpromise.Promise<WebElement[]>;
359 /**
360 * Tests if an element is present on the page.
361 * @see webdriver.WebDriver.isElementPresent
362 * @returns {!webdriver.promise.Promise} A promise that will resolve to whether
363 * the element is present on the page.
364 */
365 isElementPresent(locatorOrElement: Locator | WebElement | ElementFinder): wdpromise.Promise<any>;
366 /**
367 * Add a module to load before Angular whenever Protractor.get is called.
368 * Modules will be registered after existing modules already on the page,
369 * so any module registered here will override preexisting modules with the
370 * same name.
371 *
372 * @example
373 * browser.addMockModule('modName', function() {
374 * angular.module('modName', []).value('foo', 'bar');
375 * });
376 *
377 * @param {!string} name The name of the module to load or override.
378 * @param {!string|Function} script The JavaScript to load the module.
379 * Note that this will be executed in the browser context, so it cannot
380 * access variables from outside its scope.
381 * @param {...*} varArgs Any additional arguments will be provided to
382 * the script and may be referenced using the `arguments` object.
383 */
384 addMockModule(name: string, script: string | Function, ...moduleArgs: any[]): void;
385 /**
386 * Clear the list of registered mock modules.
387 */
388 clearMockModules(): void;
389 /**
390 * Remove a registered mock module.
391 *
392 * @example
393 * browser.removeMockModule('modName');
394 *
395 * @param {!string} name The name of the module to remove.
396 */
397 removeMockModule(name: string): void;
398 /**
399 * Get a list of the current mock modules.
400 *
401 * @returns {Array.<!string|Function>} The list of mock modules.
402 */
403 getRegisteredMockModules(): Array<string | Function>;
404 /**
405 * Add the base mock modules used for all Protractor tests.
406 *
407 * @private
408 */
409 private addBaseMockModules_();
410 /**
411 * @see webdriver.WebDriver.get
412 *
413 * Navigate to the given destination and loads mock modules before
414 * Angular. Assumes that the page being loaded uses Angular.
415 * If you need to access a page which does not have Angular on load, use
416 * the wrapped webdriver directly.
417 *
418 * @example
419 * browser.get('https://angularjs.org/');
420 * expect(browser.getCurrentUrl()).toBe('https://angularjs.org/');
421 *
422 * @param {string} destination Destination URL.
423 * @param {number=} opt_timeout Number of milliseconds to wait for Angular to
424 * start.
425 */
426 get(destination: string, timeout?: number): wdpromise.Promise<any>;
427 /**
428 * @see webdriver.WebDriver.refresh
429 *
430 * Makes a full reload of the current page and loads mock modules before
431 * Angular. Assumes that the page being loaded uses Angular.
432 * If you need to access a page which does not have Angular on load, use
433 * the wrapped webdriver directly.
434 *
435 * @param {number=} opt_timeout Number of milliseconds to wait for Angular to start.
436 */
437 refresh(opt_timeout?: number): wdpromise.Promise<any>;
438 /**
439 * Mixin navigation methods back into the navigation object so that
440 * they are invoked as before, i.e. driver.navigate().refresh()
441 */
442 navigate(): any;
443 /**
444 * Browse to another page using in-page navigation.
445 *
446 * @example
447 * browser.get('http://angular.github.io/protractor/#/tutorial');
448 * browser.setLocation('api');
449 * expect(browser.getCurrentUrl())
450 * .toBe('http://angular.github.io/protractor/#/api');
451 *
452 * @param {string} url In page URL using the same syntax as $location.url()
453 * @returns {!webdriver.promise.Promise} A promise that will resolve once
454 * page has been changed.
455 */
456 setLocation(url: string): wdpromise.Promise<any>;
457 /**
458 * Deprecated, use `browser.getCurrentUrl()` instead.
459 *
460 * Despite its name, this function will generally return `$location.url()`, though in some
461 * cases it will return `$location.absUrl()` instead. This function is only here for legacy
462 * users, and will probably be removed in Protractor 6.0.
463 *
464 * @deprecated Please use `browser.getCurrentUrl()`
465 * @example
466 * browser.get('http://angular.github.io/protractor/#/api');
467 * expect(browser.getLocationAbsUrl())
468 * .toBe('http://angular.github.io/protractor/#/api');
469 * @returns {webdriver.promise.Promise<string>} The current absolute url from
470 * AngularJS.
471 */
472 getLocationAbsUrl(): wdpromise.Promise<any>;
473 /**
474 * Adds a task to the control flow to pause the test and inject helper
475 * functions
476 * into the browser, so that debugging may be done in the browser console.
477 *
478 * This should be used under node in debug mode, i.e. with
479 * protractor debug <configuration.js>
480 *
481 * @example
482 * While in the debugger, commands can be scheduled through webdriver by
483 * entering the repl:
484 * debug> repl
485 * > element(by.input('user')).sendKeys('Laura');
486 * > browser.debugger();
487 * Press Ctrl + c to leave debug repl
488 * debug> c
489 *
490 * This will run the sendKeys command as the next task, then re-enter the
491 * debugger.
492 */
493 debugger(): wdpromise.Promise<void>;
494 /**
495 * See browser.explore().
496 */
497 enterRepl(opt_debugPort?: number): void;
498 /**
499 * Beta (unstable) explore function for entering the repl loop from
500 * any point in the control flow. Use browser.explore() in your test.
501 * Does not require changes to the command line (no need to add 'debug').
502 * Note, if you are wrapping your own instance of Protractor, you must
503 * expose globals 'browser' and 'protractor' for pause to work.
504 *
505 * @example
506 * element(by.id('foo')).click();
507 * browser.explore();
508 * // Execution will stop before the next click action.
509 * element(by.id('bar')).click();
510 *
511 * @param {number=} opt_debugPort Optional port to use for the debugging
512 * process
513 */
514 explore(opt_debugPort?: number): void;
515 /**
516 * Beta (unstable) pause function for debugging webdriver tests. Use
517 * browser.pause() in your test to enter the protractor debugger from that
518 * point in the control flow.
519 * Does not require changes to the command line (no need to add 'debug').
520 * Note, if you are wrapping your own instance of Protractor, you must
521 * expose globals 'browser' and 'protractor' for pause to work.
522 *
523 * @example
524 * element(by.id('foo')).click();
525 * browser.pause();
526 * // Execution will stop before the next click action.
527 * element(by.id('bar')).click();
528 *
529 * @param {number=} opt_debugPort Optional port to use for the debugging
530 * process
531 */
532 pause(opt_debugPort?: number): wdpromise.Promise<any>;
533 /**
534 * Determine if the control flow is enabled.
535 *
536 * @returns true if the control flow is enabled, false otherwise.
537 */
538 controlFlowIsEnabled(): any;
539}