1 | /// <reference types="q" />
|
2 | import * as q from 'q';
|
3 | import * as webdriver from 'selenium-webdriver';
|
4 | import { ProtractorBrowser } from './browser';
|
5 | import { Config } from './config';
|
6 | export declare enum PromiseType {
|
7 | Q = 0,
|
8 | WEBDRIVER = 1,
|
9 | }
|
10 | export interface PluginConfig {
|
11 | path?: string;
|
12 | package?: string;
|
13 | inline?: ProtractorPlugin;
|
14 | name?: string;
|
15 | [key: string]: any;
|
16 | }
|
17 | export interface ProtractorPlugin {
|
18 | /**
|
19 | * Sets up plugins before tests are run. This is called after the WebDriver
|
20 | * session has been started, but before the test framework has been set up.
|
21 | *
|
22 | * @this {Object} bound to module.exports.
|
23 | *
|
24 | * @throws {*} If this function throws an error, a failed assertion is added to
|
25 | * the test results.
|
26 | *
|
27 | * @return {Promise=} Can return a promise, in which case protractor will wait
|
28 | * for the promise to resolve before continuing. If the promise is
|
29 | * rejected, a failed assertion is added to the test results.
|
30 | */
|
31 | setup?(): void | Promise<void>;
|
32 | /**
|
33 | * This is called before the test have been run but after the test framework has
|
34 | * been set up. Analogous to a config file's `onPrepare`.
|
35 | *
|
36 | * Very similar to using `setup`, but allows you to access framework-specific
|
37 | * variables/functions (e.g. `jasmine.getEnv().addReporter()`).
|
38 | *
|
39 | * @this {Object} bound to module.exports.
|
40 | *
|
41 | * @throws {*} If this function throws an error, a failed assertion is added to
|
42 | * the test results.
|
43 | *
|
44 | * @return {Promise=} Can return a promise, in which case protractor will wait
|
45 | * for the promise to resolve before continuing. If the promise is
|
46 | * rejected, a failed assertion is added to the test results.
|
47 | */
|
48 | onPrepare?(): void | Promise<void>;
|
49 | /**
|
50 | * This is called after the tests have been run, but before the WebDriver
|
51 | * session has been terminated.
|
52 | *
|
53 | * @this {Object} bound to module.exports.
|
54 | *
|
55 | * @throws {*} If this function throws an error, a failed assertion is added to
|
56 | * the test results.
|
57 | *
|
58 | * @return {Promise=} Can return a promise, in which case protractor will wait
|
59 | * for the promise to resolve before continuing. If the promise is
|
60 | * rejected, a failed assertion is added to the test results.
|
61 | */
|
62 | teardown?(): void | Promise<void>;
|
63 | /**
|
64 | * Called after the test results have been finalized and any jobs have been
|
65 | * updated (if applicable).
|
66 | *
|
67 | * @this {Object} bound to module.exports.
|
68 | *
|
69 | * @throws {*} If this function throws an error, it is outputted to the console.
|
70 | * It is too late to add a failed assertion to the test results.
|
71 | *
|
72 | * @return {Promise=} Can return a promise, in which case protractor will wait
|
73 | * for the promise to resolve before continuing. If the promise is
|
74 | * rejected, an error is logged to the console.
|
75 | */
|
76 | postResults?(): void | Promise<void>;
|
77 | /**
|
78 | * Called after each test block (in Jasmine, this means an `it` block)
|
79 | * completes.
|
80 | *
|
81 | * @param {boolean} passed True if the test passed.
|
82 | * @param {Object} testInfo information about the test which just ran.
|
83 | *
|
84 | * @this {Object} bound to module.exports.
|
85 | *
|
86 | * @throws {*} If this function throws an error, a failed assertion is added to
|
87 | * the test results.
|
88 | *
|
89 | * @return {Promise=} Can return a promise, in which case protractor will wait
|
90 | * for the promise to resolve before outputting test results. Protractor
|
91 | * will *not* wait before executing the next test; however, if the promise
|
92 | * is rejected, a failed assertion is added to the test results.
|
93 | */
|
94 | postTest?(passed: boolean, testInfo: any): void | Promise<void>;
|
95 | /**
|
96 | * This is called inside browser.get() directly after the page loads, and before
|
97 | * angular bootstraps.
|
98 | *
|
99 | * @param {ProtractorBrowser} browser The browser instance which is loading a page.
|
100 | *
|
101 | * @this {Object} bound to module.exports.
|
102 | *
|
103 | * @throws {*} If this function throws an error, a failed assertion is added to
|
104 | * the test results.
|
105 | *
|
106 | * @return {webdriver.promise.Promise=} Can return a promise, in which case
|
107 | * protractor will wait for the promise to resolve before continuing. If
|
108 | * the promise is rejected, a failed assertion is added to the test results.
|
109 | */
|
110 | onPageLoad?(browser: ProtractorBrowser): void | webdriver.promise.Promise<void>;
|
111 | /**
|
112 | * This is called inside browser.get() directly after angular is done
|
113 | * bootstrapping/synchronizing. If `browser.ignoreSynchronization` is `true`,
|
114 | * this will not be called.
|
115 | *
|
116 | * @param {ProtractorBrowser} browser The browser instance which is loading a page.
|
117 | *
|
118 | * @this {Object} bound to module.exports.
|
119 | *
|
120 | * @throws {*} If this function throws an error, a failed assertion is added to
|
121 | * the test results.
|
122 | *
|
123 | * @return {webdriver.promise.Promise=} Can return a promise, in which case
|
124 | * protractor will wait for the promise to resolve before continuing. If
|
125 | * the promise is rejected, a failed assertion is added to the test results.
|
126 | */
|
127 | onPageStable?(browser: ProtractorBrowser): void | webdriver.promise.Promise<void>;
|
128 | /**
|
129 | * Between every webdriver action, Protractor calls browser.waitForAngular() to
|
130 | * make sure that Angular has no outstanding $http or $timeout calls.
|
131 | * You can use waitForPromise() to have Protractor additionally wait for your
|
132 | * custom promise to be resolved inside of browser.waitForAngular().
|
133 | *
|
134 | * @param {ProtractorBrowser} browser The browser instance which needs invoked `waitForAngular`.
|
135 | *
|
136 | * @this {Object} bound to module.exports.
|
137 | *
|
138 | * @throws {*} If this function throws an error, a failed assertion is added to
|
139 | * the test results.
|
140 | *
|
141 | * @return {webdriver.promise.Promise=} Can return a promise, in which case
|
142 | * protractor will wait for the promise to resolve before continuing. If the
|
143 | * promise is rejected, a failed assertion is added to the test results, and
|
144 | * protractor will continue onto the next command. If nothing is returned or
|
145 | * something other than a promise is returned, protractor will continue
|
146 | * onto the next command.
|
147 | */
|
148 | waitForPromise?(browser: ProtractorBrowser): webdriver.promise.Promise<void>;
|
149 | /**
|
150 | * Between every webdriver action, Protractor calls browser.waitForAngular() to
|
151 | * make sure that Angular has no outstanding $http or $timeout calls.
|
152 | * You can use waitForCondition() to have Protractor additionally wait for your
|
153 | * custom condition to be truthy. If specified, this function will be called
|
154 | * repeatedly until truthy.
|
155 | *
|
156 | * @param {ProtractorBrowser} browser The browser instance which needs invoked `waitForAngular`.
|
157 | *
|
158 | * @this {Object} bound to module.exports.
|
159 | *
|
160 | * @throws {*} If this function throws an error, a failed assertion is added to
|
161 | * the test results.
|
162 | *
|
163 | * @return {webdriver.promise.Promise<boolean>|boolean} If truthy, Protractor
|
164 | * will continue onto the next command. If falsy, webdriver will
|
165 | * continuously re-run this function until it is truthy. If a rejected promise
|
166 | * is returned, a failed assertion is added to the test results, and Protractor
|
167 | * will continue onto the next command.
|
168 | */
|
169 | waitForCondition?(browser: ProtractorBrowser): webdriver.promise.Promise<boolean> | boolean;
|
170 | /**
|
171 | * Used to turn off default checks for angular stability
|
172 | *
|
173 | * Normally Protractor waits for all $timeout and $http calls to be processed
|
174 | * before executing the next command. This can be disabled using
|
175 | * browser.ignoreSynchronization, but that will also disable any
|
176 | * <Plugin>.waitForPromise or <Plugin>.waitForCondition checks. If you want
|
177 | * to disable synchronization with angular, but leave intact any custom plugin
|
178 | * synchronization, this is the option for you.
|
179 | *
|
180 | * This is used by plugin authors who want to replace Protractor's
|
181 | * synchronization code with their own.
|
182 | *
|
183 | * @type {boolean}
|
184 | */
|
185 | skipAngularStability?: boolean;
|
186 | /**
|
187 | * The name of the plugin. Used when reporting results.
|
188 | *
|
189 | * If you do not specify this property, it will be filled in with something
|
190 | * reasonable (e.g. the plugin's path) by Protractor at runtime.
|
191 | *
|
192 | * @type {string}
|
193 | */
|
194 | name?: string;
|
195 | /**
|
196 | * The plugin's configuration object.
|
197 | *
|
198 | * Note: this property is added by Protractor at runtime. Any pre-existing
|
199 | * value will be overwritten.
|
200 | *
|
201 | * Note: that this is not the entire Protractor config object, just the entry
|
202 | * in the `plugins` array for this plugin.
|
203 | *
|
204 | * @type {Object}
|
205 | */
|
206 | config?: PluginConfig;
|
207 | /**
|
208 | * Adds a failed assertion to the test's results.
|
209 | *
|
210 | * Note: this property is added by Protractor at runtime. Any pre-existing
|
211 | * value will be overwritten.
|
212 | *
|
213 | * @param {string} message The error message for the failed assertion
|
214 | * @param {specName: string, stackTrace: string} options Some optional extra
|
215 | * information about the assertion:
|
216 | * - specName The name of the spec which this assertion belongs to.
|
217 | * Defaults to `PLUGIN_NAME + ' Plugin Tests'`.
|
218 | * - stackTrace The stack trace for the failure. Defaults to undefined.
|
219 | * Defaults to `{}`.
|
220 | *
|
221 | * @throws {Error} Throws an error if called after results have been reported
|
222 | */
|
223 | addFailure?(message?: string, info?: {
|
224 | specName?: string;
|
225 | stackTrace?: string;
|
226 | }): void;
|
227 | /**
|
228 | * Adds a passed assertion to the test's results.
|
229 | *
|
230 | * Note: this property is added by Protractor at runtime. Any pre-existing
|
231 | * value will be overwritten.
|
232 | *
|
233 | * @param {specName: string} options Extra information about the assertion:
|
234 | * - specName The name of the spec which this assertion belongs to.
|
235 | * Defaults to `PLUGIN_NAME + ' Plugin Tests'`.
|
236 | * Defaults to `{}`.
|
237 | *
|
238 | * @throws {Error} Throws an error if called after results have been reported
|
239 | */
|
240 | addSuccess?(info?: {
|
241 | specName?: string;
|
242 | }): void;
|
243 | /**
|
244 | * Warns the user that something is problematic.
|
245 | *
|
246 | * Note: this property is added by Protractor at runtime. Any pre-existing
|
247 | * value will be overwritten.
|
248 | *
|
249 | * @param {string} message The message to warn the user about
|
250 | * @param {specName: string} options Extra information about the assertion:
|
251 | * - specName The name of the spec which this assertion belongs to.
|
252 | * Defaults to `PLUGIN_NAME + ' Plugin Tests'`.
|
253 | * Defaults to `{}`.
|
254 | */
|
255 | addWarning?(message?: string, info?: {
|
256 | specName?: string;
|
257 | }): void;
|
258 | }
|
259 | /**
|
260 | * The plugin API for Protractor. Note that this API is unstable. See
|
261 | * plugins/README.md for more information.
|
262 | *
|
263 | * @constructor
|
264 | * @param {Object} config parsed from the config file
|
265 | */
|
266 | export declare class Plugins {
|
267 | pluginObjs: ProtractorPlugin[];
|
268 | assertions: {
|
269 | [key: string]: AssertionResult[];
|
270 | };
|
271 | resultsReported: boolean;
|
272 | constructor(config: Config);
|
273 | /**
|
274 | * Adds properties to a plugin's object
|
275 | *
|
276 | * @see docs/plugins.md#provided-properties-and-functions
|
277 | */
|
278 | private annotatePluginObj(obj, conf, i);
|
279 | private printPluginResults(specResults);
|
280 | /**
|
281 | * Gets the tests results generated by any plugins
|
282 | *
|
283 | * @see lib/frameworks/README.md#requirements for a complete description of what
|
284 | * the results object must look like
|
285 | *
|
286 | * @return {Object} The results object
|
287 | */
|
288 | getResults(): {
|
289 | failedCount: number;
|
290 | specResults: SpecResult[];
|
291 | };
|
292 | /**
|
293 | * Returns true if any loaded plugin has skipAngularStability enabled.
|
294 | *
|
295 | * @return {boolean}
|
296 | */
|
297 | skipAngularStability(): boolean;
|
298 | /**
|
299 | * @see docs/plugins.md#writing-plugins for information on these functions
|
300 | */
|
301 | setup: (...args: any[]) => q.Promise<any[]>;
|
302 | onPrepare: (...args: any[]) => q.Promise<any[]>;
|
303 | teardown: (...args: any[]) => q.Promise<any[]>;
|
304 | postResults: (...args: any[]) => q.Promise<any[]>;
|
305 | postTest: (...args: any[]) => q.Promise<any[]>;
|
306 | onPageLoad: (...args: any[]) => webdriver.promise.Promise<any[]>;
|
307 | onPageStable: (...args: any[]) => webdriver.promise.Promise<any[]>;
|
308 | waitForPromise: (...args: any[]) => webdriver.promise.Promise<any[]>;
|
309 | waitForCondition: (...args: any[]) => webdriver.promise.Promise<any[]>;
|
310 | /**
|
311 | * Calls a function from a plugin safely. If the plugin's function throws an
|
312 | * exception or returns a rejected promise, that failure will be logged as a
|
313 | * failed test result instead of crashing protractor. If the tests results have
|
314 | * already been reported, the failure will be logged to the console.
|
315 | *
|
316 | * @param {Object} pluginObj The plugin object containing the function to be run
|
317 | * @param {string} funName The name of the function we want to run
|
318 | * @param {*[]} args The arguments we want to invoke the function with
|
319 | * @param {PromiseType} promiseType The type of promise (WebDriver or Q) that
|
320 | * should be used
|
321 | * @param {boolean} resultsReported If the results have already been reported
|
322 | * @param {*} failReturnVal The value to return if the function fails
|
323 | *
|
324 | * @return {webdriver.promise.Promise|Q.Promise} A promise which resolves to the
|
325 | * function's return value
|
326 | */
|
327 | private safeCallPluginFun(pluginObj, funName, args, promiseType, failReturnVal);
|
328 | /**
|
329 | * Generates the handler for a plugin function (e.g. the setup() function)
|
330 | *
|
331 | * @param {string} funName The name of the function to make a handler for
|
332 | * @param {PromiseType} promiseType The type of promise (WebDriver or Q) that should be used
|
333 | * @param {boolean=} failReturnVal The value that the function should return if the plugin crashes
|
334 | *
|
335 | * @return The handler
|
336 | */
|
337 | private pluginFunFactory(funName, promiseType, failReturnVal?);
|
338 | private pluginFunFactory(funName, promiseType, failReturnVal?);
|
339 | }
|
340 | export interface SpecResult {
|
341 | description: string;
|
342 | assertions: AssertionResult[];
|
343 | }
|
344 | export interface AssertionResult {
|
345 | passed: boolean;
|
346 | errorMsg?: string;
|
347 | stackTrace?: string;
|
348 | }
|