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