@axe-core/webdriverjs 4.3.3-alpha.242 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +13 -0
- package/README.md +2 -24
- package/dist/axe-injector.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +9 -11
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -3
- package/dist/utils/index.d.ts +1 -2
- package/dist/utils/index.js +11 -9
- package/dist/utils/index.js.map +1 -1
- package/error-handling.md +52 -0
- package/example-with-callback.js +15 -0
- package/example.js +13 -0
- package/package.json +10 -13
- package/src/axe-injector.ts +191 -0
- package/src/browser.ts +142 -0
- package/src/index.ts +262 -0
- package/src/types.ts +27 -0
- package/src/utils/index.ts +23 -0
- package/tests/axe-webdriverjs.spec.ts +676 -0
- package/tests/fixtures/context.html +11 -0
- package/tests/test-utils.ts +49 -0
- package/tsconfig.json +15 -0
package/.eslintrc.js
ADDED
package/README.md
CHANGED
|
@@ -6,25 +6,13 @@ Previous versions of this program were maintained at [dequelabs/axe-webdriverjs]
|
|
|
6
6
|
|
|
7
7
|
## Getting Started
|
|
8
8
|
|
|
9
|
-
Install [Node.js](https://docs.npmjs.com/getting-started/installing-node) if you haven't already.
|
|
9
|
+
Install [Node.js](https://docs.npmjs.com/getting-started/installing-node) if you haven't already. For running axe-webdriverjs tests read more about [setting up your environment](CONTRIBUTING.md).
|
|
10
10
|
|
|
11
11
|
> Download and install any necessary browser drivers on your machine's PATH. [More on Webdriver setup](https://www.selenium.dev/documentation/en/webdriver/).
|
|
12
12
|
|
|
13
13
|
Install Selenium Webdriver: `npm install selenium-webdriver --no-save`
|
|
14
14
|
|
|
15
|
-
Install @axe-core/webdriverjs and its dependencies:
|
|
16
|
-
|
|
17
|
-
NPM:
|
|
18
|
-
|
|
19
|
-
```console
|
|
20
|
-
npm install @axe-core/webdriverjs
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Yarn:
|
|
24
|
-
|
|
25
|
-
```console
|
|
26
|
-
yarn add @axe-core/webdriverjs
|
|
27
|
-
```
|
|
15
|
+
Install @axe-core/webdriverjs and its dependencies: `npm install @axe-core/webdriverjs`
|
|
28
16
|
|
|
29
17
|
## Usage
|
|
30
18
|
|
|
@@ -174,13 +162,3 @@ const axe = new AxeBuilder(driver).setLegacyMode();
|
|
|
174
162
|
const result = await axe.analyze();
|
|
175
163
|
axe.setLegacyMode(false); // Disables legacy mode
|
|
176
164
|
```
|
|
177
|
-
|
|
178
|
-
### WebdriverJS Example
|
|
179
|
-
|
|
180
|
-
We have created an example [test suite](https://github.com/dequelabs/axe-core-npm/tree/develop/packages/webdriverjs/tests/examples/webdriverjs-example.ts) showcasing the functionality of axe-core WebdriverJS.
|
|
181
|
-
|
|
182
|
-
To run the test:
|
|
183
|
-
|
|
184
|
-
- Navigate to: `/webdriverjs/tests/example`
|
|
185
|
-
- Install node modules: `npm install`
|
|
186
|
-
- Run tests: `npm test`
|
package/dist/axe-injector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axe-injector.js","sourceRoot":"","sources":["../src/axe-injector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yDAA2C;AAC3C,qCAAkC;AAE1B,IAAA,0BAA0B,GAAK,0BAAK,2BAAV,CAAW;AAE7C;IAME,2BAAY,EAKQ;YAJlB,MAAM,YAAA,EACN,SAAS,eAAA,EACT,cAAc,oBAAA,EACd,MAAM,YAAA;QAEN,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,iBAAM,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,cAAc,IAAI,EAAE,C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AAO,CAAC,SAAS,EAAtB,wBAAsB;wBACxB,8EAA8E;wBAC9E,qBAAM,IAAI,CAAC,aAAa,EAAE,EAAA;;wBAD1B,8EAA8E;wBAC9E,SAA0B,CAAC;;;oBAG7B,uCAAuC;oBACvC,qFAAqF;oBACrF,qBAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAA;;wBAF5C,uCAAuC;wBACvC,qFAAqF;wBACrF,SAA4C,CAAC;wBAGjC,qBAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAA;;wBAA3D,GAAG,GAAG,SAAqD;wBACtD,qBAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAA;;wBAAzD,EAAE,GAAG,SAAoD;wBACzD,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;8BAGC,EAAN,iBAAM;;;6BAAN,CAAA,oBAAM,CAAA;wBAApB,UAAU;;;;wBAEjB,qBAAM,IAAI,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,CAAC,EAAA;;wBAApC,SAAoC,CAAC;;;;wBAErC,IAAI,CAAC,YAAY,CAAC,KAAG,CAAC,CAAC;;;wBAJF,IAAM,CAAA;;;oBAQ/B,kCAAkC;oBAClC,sBAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,cAAc,EAAE,EAAC;;;;KAChD;IACH,wBAAC;AAAD,CAAC,AAxLD,IAwLC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WebDriver } from 'selenium-webdriver';
|
|
2
2
|
import { RunOptions, Spec, AxeResults } from 'axe-core';
|
|
3
|
-
import { CallbackFunction, BuilderOptions
|
|
3
|
+
import { CallbackFunction, BuilderOptions } from './types';
|
|
4
4
|
declare class AxeBuilder {
|
|
5
5
|
private driver;
|
|
6
6
|
private axeSource;
|
|
@@ -15,12 +15,12 @@ declare class AxeBuilder {
|
|
|
15
15
|
* Selector to include in analysis.
|
|
16
16
|
* This may be called any number of times.
|
|
17
17
|
*/
|
|
18
|
-
include(selector:
|
|
18
|
+
include(selector: string): this;
|
|
19
19
|
/**
|
|
20
20
|
* Selector to exclude in analysis.
|
|
21
21
|
* This may be called any number of times.
|
|
22
22
|
*/
|
|
23
|
-
exclude(selector:
|
|
23
|
+
exclude(selector: string): this;
|
|
24
24
|
/**
|
|
25
25
|
* Set options to be passed into axe-core
|
|
26
26
|
*/
|
|
@@ -55,7 +55,7 @@ declare class AxeBuilder {
|
|
|
55
55
|
* axe.finishRun() which is called in a blank page. This uses axe.run() instead,
|
|
56
56
|
* but with the restriction that cross-origin frames will not be tested.
|
|
57
57
|
*/
|
|
58
|
-
setLegacyMode(legacyMode?: boolean):
|
|
58
|
+
setLegacyMode(legacyMode?: boolean): AxeBuilder;
|
|
59
59
|
/**
|
|
60
60
|
* Analyzes the page, returning a promise
|
|
61
61
|
*/
|
package/dist/index.js
CHANGED
|
@@ -68,7 +68,6 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
68
68
|
* This may be called any number of times.
|
|
69
69
|
*/
|
|
70
70
|
AxeBuilder.prototype.include = function (selector) {
|
|
71
|
-
selector = Array.isArray(selector) ? selector : [selector];
|
|
72
71
|
this.includes.push(selector);
|
|
73
72
|
return this;
|
|
74
73
|
};
|
|
@@ -77,7 +76,6 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
77
76
|
* This may be called any number of times.
|
|
78
77
|
*/
|
|
79
78
|
AxeBuilder.prototype.exclude = function (selector) {
|
|
80
|
-
selector = Array.isArray(selector) ? selector : [selector];
|
|
81
79
|
this.excludes.push(selector);
|
|
82
80
|
return this;
|
|
83
81
|
};
|
|
@@ -151,7 +149,7 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
151
149
|
.catch(function (err) {
|
|
152
150
|
// When using a callback, do *not* reject the wrapping Promise. This prevents having to handle the same error twice.
|
|
153
151
|
if (callback) {
|
|
154
|
-
callback(err, null);
|
|
152
|
+
callback(err.message, null);
|
|
155
153
|
}
|
|
156
154
|
else {
|
|
157
155
|
reject(err);
|
|
@@ -182,11 +180,11 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
182
180
|
return __generator(this, function (_a) {
|
|
183
181
|
switch (_a.label) {
|
|
184
182
|
case 0:
|
|
185
|
-
context =
|
|
183
|
+
context = index_1.normalizeContext(this.includes, this.excludes);
|
|
186
184
|
return [4 /*yield*/, this.driver.switchTo().defaultContent()];
|
|
187
185
|
case 1:
|
|
188
186
|
_a.sent();
|
|
189
|
-
return [4 /*yield*/,
|
|
187
|
+
return [4 /*yield*/, browser_1.axeSourceInject(this.driver, this.axeSource, this.config)];
|
|
190
188
|
case 2:
|
|
191
189
|
runPartialSupported = (_a.sent()).runPartialSupported;
|
|
192
190
|
if (runPartialSupported !== true || this.legacyMode) {
|
|
@@ -219,7 +217,7 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
219
217
|
case 0:
|
|
220
218
|
_a = this, driver = _a.driver, axeSource = _a.axeSource, builderOptions = _a.builderOptions;
|
|
221
219
|
config = this.config;
|
|
222
|
-
if (this.legacyMode
|
|
220
|
+
if (!this.legacyMode) {
|
|
223
221
|
config = __assign(__assign({}, (config || {})), { allowedOrigins: ['<unsafe_all_origins>'] });
|
|
224
222
|
}
|
|
225
223
|
injector = new axe_injector_1.default({
|
|
@@ -231,7 +229,7 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
231
229
|
return [4 /*yield*/, injector.injectIntoAllFrames()];
|
|
232
230
|
case 1:
|
|
233
231
|
_b.sent();
|
|
234
|
-
return [2 /*return*/,
|
|
232
|
+
return [2 /*return*/, browser_1.axeRunLegacy(this.driver, context, this.option, this.config)];
|
|
235
233
|
}
|
|
236
234
|
});
|
|
237
235
|
});
|
|
@@ -247,14 +245,14 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
247
245
|
switch (_f.label) {
|
|
248
246
|
case 0:
|
|
249
247
|
if (!!initiator) return [3 /*break*/, 2];
|
|
250
|
-
return [4 /*yield*/,
|
|
248
|
+
return [4 /*yield*/, browser_1.axeSourceInject(this.driver, this.axeSource, this.config)];
|
|
251
249
|
case 1:
|
|
252
250
|
_f.sent();
|
|
253
251
|
_f.label = 2;
|
|
254
|
-
case 2: return [4 /*yield*/,
|
|
252
|
+
case 2: return [4 /*yield*/, browser_1.axeGetFrameContext(this.driver, context)];
|
|
255
253
|
case 3:
|
|
256
254
|
frameContexts = _f.sent();
|
|
257
|
-
return [4 /*yield*/,
|
|
255
|
+
return [4 /*yield*/, browser_1.axeRunPartial(this.driver, context, this.option)];
|
|
258
256
|
case 4:
|
|
259
257
|
partials = [
|
|
260
258
|
_f.sent()
|
|
@@ -332,7 +330,7 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
332
330
|
case 7:
|
|
333
331
|
error_2 = _b.sent();
|
|
334
332
|
throw new Error("switchTo failed. Are you using updated browser drivers? \nDriver reported:\n" + error_2);
|
|
335
|
-
case 8: return [4 /*yield*/,
|
|
333
|
+
case 8: return [4 /*yield*/, browser_1.axeFinishRun(driver, axeSource, config, partials, option)];
|
|
336
334
|
case 9:
|
|
337
335
|
res = _b.sent();
|
|
338
336
|
return [4 /*yield*/, driver.close()];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,qCAAkC;AAElC,uCAAiD;AACjD,+CAAyC;AACzC,qCAMmB;AACnB,+BAAiC;AAEjC;IAUE,oBACE,MAAiB,EACjB,SAAyB,EACzB,cAA+B;QALzB,eAAU,GAAG,KAAK,CAAC;QAOzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,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|
3
3
|
import * as axe from 'axe-core';
|
|
4
4
|
export interface Options {
|
|
5
5
|
driver: WebDriver;
|
|
@@ -13,7 +13,6 @@ export interface BuilderOptions {
|
|
|
13
13
|
export interface AxeInjectorParams extends Options {
|
|
14
14
|
config?: Spec | null;
|
|
15
15
|
}
|
|
16
|
-
export declare type CallbackFunction = (error:
|
|
16
|
+
export declare type CallbackFunction = (error: string | null, results: AxeResults | null) => void;
|
|
17
17
|
export declare type InjectCallback = (err?: Error) => void;
|
|
18
18
|
export declare type PartialResults = Parameters<typeof axe.finishRun>[0];
|
|
19
|
-
export declare type Selector = BaseSelector | BaseSelector[];
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ContextObject } from 'axe-core';
|
|
2
|
-
import { Selector } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* Get running context
|
|
5
4
|
*/
|
|
6
|
-
export declare const normalizeContext: (include:
|
|
5
|
+
export declare const normalizeContext: (include: string[], exclude: string[]) => ContextObject;
|
package/dist/utils/index.js
CHANGED
|
@@ -5,17 +5,19 @@ exports.normalizeContext = void 0;
|
|
|
5
5
|
* Get running context
|
|
6
6
|
*/
|
|
7
7
|
var normalizeContext = function (include, exclude) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(_a = base.exclude).push.apply(_a, exclude);
|
|
8
|
+
if (!exclude.length) {
|
|
9
|
+
if (!include.length) {
|
|
10
|
+
return { exclude: [] };
|
|
11
|
+
}
|
|
12
|
+
return { include: include };
|
|
14
13
|
}
|
|
15
|
-
if (include.length) {
|
|
16
|
-
|
|
14
|
+
if (!include.length) {
|
|
15
|
+
return { exclude: exclude };
|
|
17
16
|
}
|
|
18
|
-
return
|
|
17
|
+
return {
|
|
18
|
+
include: include,
|
|
19
|
+
exclude: exclude
|
|
20
|
+
};
|
|
19
21
|
};
|
|
20
22
|
exports.normalizeContext = normalizeContext;
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACI,IAAM,gBAAgB,GAAG,UAC9B,OAAiB,EACjB,OAAiB;IAEjB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACnB,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;SACxB;QACD,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC;KACpB;IACD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC;KACpB;IACD,OAAO;QACL,OAAO,SAAA;QACP,OAAO,SAAA;KACR,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,gBAAgB,oBAiB3B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Error Handling
|
|
2
|
+
|
|
3
|
+
## Table of Content
|
|
4
|
+
|
|
5
|
+
1. [Having an Out-of-date Driver](#having-an-out-of-date-driver)
|
|
6
|
+
2. [Having Popup blockers enabled](#having-popup-blockers-enabled)
|
|
7
|
+
3. [AxeBuilder.setLegacyMode(legacy: boolean)](#axebuildersetlegacymodelegacy-boolean)
|
|
8
|
+
|
|
9
|
+
Version 4.3.0 and above of the axe-core integrations use a new technique when calling `AxeBuilder.analyze()` which opens a new window at the end of a run. Many of the issues outlined in this document address common problems with this technique and their potential solutions.
|
|
10
|
+
|
|
11
|
+
### Having an Out-of-date Driver
|
|
12
|
+
|
|
13
|
+
A common problem is having an out-of-date driver. To fix this issue make sure that your local install of [geckodriver](https://github.com/mozilla/geckodriver/releases) or [chromedriver](https://chromedriver.chromium.org/downloads) is up-to-date.
|
|
14
|
+
|
|
15
|
+
An example error message for this problem will include a message about `switchToWindow`.
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
|
|
19
|
+
```console
|
|
20
|
+
(node:17566) UnhandledPromiseRejectionWarning: Error: Malformed type for "handle" parameter of command switchToWindow
|
|
21
|
+
Expected: string
|
|
22
|
+
Actual: undefined
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Having Popup blockers enabled
|
|
26
|
+
|
|
27
|
+
Popup blockers prevent us from opening the new window when calling `AxeBuilder.analyze()`. The default configuration for most automation testing libraries should allow popups. Please make sure that you do not explicitly enable popup blockers which may cause an issue while running the tests.
|
|
28
|
+
|
|
29
|
+
### AxeBuilder.setLegacyMode(legacy: boolean)
|
|
30
|
+
|
|
31
|
+
If for some reason you are unable to run the new `AxeBuilder.analyze` technique without errors, axe provides a new chainable method that allows you to run the legacy version of `AxeBuilder.analyze`. When using this method axe excludes accessibility issues that may occur in cross-domain frames and iframes.
|
|
32
|
+
|
|
33
|
+
**Please Note:** `AxeBuilder.setLegacyMode` is deprecated and will be removed in v5.0. Please report any errors you may have while running `AxeBuilder.analyze` so that they can be fixed before the legacy version is removed.
|
|
34
|
+
|
|
35
|
+
#### Example:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const AxeBuilder = require('@axe-core/webdriverjs');
|
|
39
|
+
const WebDriver = require('selenium-webdriver');
|
|
40
|
+
(async () => {
|
|
41
|
+
const driver = new WebDriver.Builder().forBrowser('chrome').build();
|
|
42
|
+
await driver.get('https://dequeuniversity.com/demo/mars/');
|
|
43
|
+
const results = await new AxeBuilder(driver, null, {
|
|
44
|
+
noSandbox: true
|
|
45
|
+
})
|
|
46
|
+
// enables legacy mode
|
|
47
|
+
.setLegacyMode()
|
|
48
|
+
.analyze();
|
|
49
|
+
console.log(results);
|
|
50
|
+
await driver.quit();
|
|
51
|
+
})();
|
|
52
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const AxeBuilder = require('@axe-core/webdriverjs');
|
|
2
|
+
const WebDriver = require('selenium-webdriver');
|
|
3
|
+
|
|
4
|
+
const driver = new WebDriver.Builder().forBrowser('chrome').build();
|
|
5
|
+
|
|
6
|
+
driver.get('https://html5-sandbox.glitch.me/').then(() => {
|
|
7
|
+
const axe = new AxeBuilder(driver, null, { noSandbox: true });
|
|
8
|
+
axe.analyze(async (err, results) => {
|
|
9
|
+
if (err) {
|
|
10
|
+
// Handle error somehow
|
|
11
|
+
}
|
|
12
|
+
console.log(results);
|
|
13
|
+
await driver.quit();
|
|
14
|
+
});
|
|
15
|
+
});
|
package/example.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const AxeBuilder = require('@axe-core/webdriverjs');
|
|
2
|
+
const WebDriver = require('selenium-webdriver');
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
5
|
+
(async () => {
|
|
6
|
+
const driver = new WebDriver.Builder().forBrowser('chrome').build();
|
|
7
|
+
await driver.get('https://html5-sandbox.glitch.me/');
|
|
8
|
+
const results = await new AxeBuilder(driver, null, {
|
|
9
|
+
noSandbox: true
|
|
10
|
+
}).analyze();
|
|
11
|
+
console.log(results);
|
|
12
|
+
await driver.quit();
|
|
13
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axe-core/webdriverjs",
|
|
3
|
-
"version": "4.3.3
|
|
3
|
+
"version": "4.3.3",
|
|
4
4
|
"description": "Provides a method to inject and analyze web pages using axe",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
@@ -27,9 +27,6 @@
|
|
|
27
27
|
"name": "Michael Siek (me@michaelsiek.com)"
|
|
28
28
|
}
|
|
29
29
|
],
|
|
30
|
-
"files": [
|
|
31
|
-
"/dist"
|
|
32
|
-
],
|
|
33
30
|
"repository": {
|
|
34
31
|
"type": "git",
|
|
35
32
|
"url": "https://github.com/dequelabs/axe-core-npm.git"
|
|
@@ -57,34 +54,34 @@
|
|
|
57
54
|
"webdriverjs"
|
|
58
55
|
],
|
|
59
56
|
"devDependencies": {
|
|
60
|
-
"@types/chai": "^4.2.
|
|
57
|
+
"@types/chai": "^4.2.21",
|
|
61
58
|
"@types/chromedriver": "^81.0.0",
|
|
62
59
|
"@types/express": "^4.17.13",
|
|
63
60
|
"@types/http-server": "^0.10.1",
|
|
64
61
|
"@types/mocha": "^8.2.3",
|
|
65
|
-
"@types/node": "^14.17.
|
|
66
|
-
"@types/selenium-webdriver": "^4.0.
|
|
62
|
+
"@types/node": "^14.17.9",
|
|
63
|
+
"@types/selenium-webdriver": "^4.0.15",
|
|
67
64
|
"@types/sinon": "^9.0.10",
|
|
68
65
|
"@types/test-listen": "^1.1.0",
|
|
69
66
|
"axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1",
|
|
70
67
|
"chai": "^4.3.0",
|
|
71
68
|
"chaimocha": "^1.10.0",
|
|
72
|
-
"chromedriver": "^
|
|
69
|
+
"chromedriver": "^106.0.1",
|
|
73
70
|
"delay": "^5.0.0",
|
|
74
71
|
"express": "^4.17.1",
|
|
75
72
|
"http-server": "^0.12.3",
|
|
76
|
-
"is-ci": "^3.0.
|
|
73
|
+
"is-ci": "^3.0.0",
|
|
77
74
|
"mocha": "^8.4.0",
|
|
78
75
|
"nyc": "^15.1.0",
|
|
79
76
|
"rimraf": "^3.0.2",
|
|
80
|
-
"selenium-webdriver": "^4.0.0",
|
|
77
|
+
"selenium-webdriver": "^4.0.0-beta.4",
|
|
81
78
|
"sinon": "^9.2.4",
|
|
82
79
|
"test-listen": "^1.1.0",
|
|
83
80
|
"ts-node": "^9.1.1",
|
|
84
|
-
"typescript": "^4.
|
|
81
|
+
"typescript": "^4.3.5"
|
|
85
82
|
},
|
|
86
83
|
"dependencies": {
|
|
87
|
-
"axe-core": "^4.
|
|
84
|
+
"axe-core": "^4.3.3"
|
|
88
85
|
},
|
|
89
86
|
"peerDependencies": {
|
|
90
87
|
"selenium-webdriver": ">3.0.0-beta || >=2.53.1 || >4.0.0-alpha"
|
|
@@ -108,5 +105,5 @@
|
|
|
108
105
|
"functions": 85,
|
|
109
106
|
"lines": 85
|
|
110
107
|
},
|
|
111
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "71572a674d4b42b05d8aeff3b8bae30de410c95c"
|
|
112
109
|
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { WebDriver, WebElement } from 'selenium-webdriver';
|
|
2
|
+
import { error } from 'selenium-webdriver';
|
|
3
|
+
import { source } from 'axe-core';
|
|
4
|
+
import type { AxeInjectorParams, BuilderOptions } from './types';
|
|
5
|
+
const { StaleElementReferenceError } = error;
|
|
6
|
+
|
|
7
|
+
export default class AxeInjectorLegacy {
|
|
8
|
+
private driver: WebDriver;
|
|
9
|
+
private axeSource: string;
|
|
10
|
+
private options: BuilderOptions;
|
|
11
|
+
private config: string;
|
|
12
|
+
private didLogError: boolean;
|
|
13
|
+
constructor({
|
|
14
|
+
driver,
|
|
15
|
+
axeSource,
|
|
16
|
+
builderOptions,
|
|
17
|
+
config
|
|
18
|
+
}: AxeInjectorParams) {
|
|
19
|
+
this.driver = driver;
|
|
20
|
+
this.axeSource = axeSource || source;
|
|
21
|
+
this.config = config ? JSON.stringify(config) : '';
|
|
22
|
+
this.options = builderOptions || {};
|
|
23
|
+
this.didLogError = false;
|
|
24
|
+
|
|
25
|
+
this.options.noSandbox =
|
|
26
|
+
typeof this.options.noSandbox === 'boolean'
|
|
27
|
+
? this.options.noSandbox
|
|
28
|
+
: false;
|
|
29
|
+
|
|
30
|
+
this.options.logIframeErrors =
|
|
31
|
+
typeof this.options.logIframeErrors === 'boolean'
|
|
32
|
+
? this.options.logIframeErrors
|
|
33
|
+
: false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Checks to make sure that the error thrown was not a stale iframe
|
|
38
|
+
* @param {Error} error
|
|
39
|
+
* @returns {void}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
private errorHandler(err: Error): void {
|
|
43
|
+
// We've already "warned" the user. No need to do it again (mostly for backwards compatibility)
|
|
44
|
+
if (this.didLogError) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.didLogError = true;
|
|
49
|
+
let msg;
|
|
50
|
+
if (err instanceof StaleElementReferenceError) {
|
|
51
|
+
msg =
|
|
52
|
+
'Tried to inject into a removed iframe. This will not affect the analysis of the rest of the page but you might want to ensure the page has finished updating before starting the analysis.';
|
|
53
|
+
} else {
|
|
54
|
+
msg = 'Failed to inject axe-core into one of the iframes!';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.options.logIframeErrors) {
|
|
58
|
+
console.error(msg);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
throw new Error(msg);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get axe-core source and configurations
|
|
67
|
+
* @returns {String}
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
private get script(): string {
|
|
71
|
+
return `
|
|
72
|
+
${this.axeSource}
|
|
73
|
+
${this.config ? `axe.configure(${this.config})` : ''}
|
|
74
|
+
axe.configure({
|
|
75
|
+
branding: { application: 'webdriverjs' }
|
|
76
|
+
})
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Removes the `sandbox` attribute from iFrames
|
|
82
|
+
* @returns {Promise<void>}
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
private async sandboxBuster(): Promise<void> {
|
|
86
|
+
// outer promise needed because `executeAsyncScript`
|
|
87
|
+
// does not return a "real promise" (ManagedPromise)
|
|
88
|
+
// and we want to await it.
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
/* eslint-disable no-undef */
|
|
91
|
+
this.driver
|
|
92
|
+
// https://github.com/vercel/pkg/issues/676
|
|
93
|
+
// we need to pass a string vs a function so we manually stringified the function
|
|
94
|
+
.executeAsyncScript(
|
|
95
|
+
`
|
|
96
|
+
var callback = arguments[arguments.length - 1];
|
|
97
|
+
var iframes = Array.from(
|
|
98
|
+
document.querySelectorAll('iframe[sandbox]')
|
|
99
|
+
);
|
|
100
|
+
var removeSandboxAttr = clone => attr => {
|
|
101
|
+
if (attr.name === 'sandbox') return;
|
|
102
|
+
clone.setAttribute(attr.name, attr.value);
|
|
103
|
+
};
|
|
104
|
+
var replaceSandboxedIframe = iframe => {
|
|
105
|
+
var clone = document.createElement('iframe');
|
|
106
|
+
var promise = new Promise(
|
|
107
|
+
iframeLoaded => (clone.onload = iframeLoaded)
|
|
108
|
+
);
|
|
109
|
+
Array.from(iframe.attributes).forEach(removeSandboxAttr(clone));
|
|
110
|
+
iframe.parentElement.replaceChild(clone, iframe);
|
|
111
|
+
return promise;
|
|
112
|
+
};
|
|
113
|
+
Promise.all(iframes.map(replaceSandboxedIframe)).then(callback);
|
|
114
|
+
`
|
|
115
|
+
)
|
|
116
|
+
// resolve the outer promise
|
|
117
|
+
.then(() => resolve())
|
|
118
|
+
.catch(e => reject(e));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Injects into the provided `frame` and its child `frames`
|
|
124
|
+
* @param {WebElement[]} framePath
|
|
125
|
+
* @returns {Promise<void>}
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
private async handleFrame(framePath: WebElement[]): Promise<void> {
|
|
129
|
+
await this.driver.switchTo().defaultContent();
|
|
130
|
+
|
|
131
|
+
for (const frame of framePath) {
|
|
132
|
+
await this.driver.switchTo().frame(frame);
|
|
133
|
+
}
|
|
134
|
+
if (this.options.noSandbox) {
|
|
135
|
+
await this.sandboxBuster();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
await this.driver.executeScript(this.script);
|
|
139
|
+
|
|
140
|
+
const ifs = await this.driver.findElements({ tagName: 'iframe' });
|
|
141
|
+
const fs = await this.driver.findElements({ tagName: 'frame' });
|
|
142
|
+
const frames = ifs.concat(fs);
|
|
143
|
+
|
|
144
|
+
for (const childFrames of frames) {
|
|
145
|
+
framePath.push(childFrames);
|
|
146
|
+
try {
|
|
147
|
+
await this.handleFrame(framePath);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
this.errorHandler(error);
|
|
150
|
+
} finally {
|
|
151
|
+
framePath.pop();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Injects into all frames
|
|
158
|
+
* @returns {Promise<void>}
|
|
159
|
+
*/
|
|
160
|
+
public async injectIntoAllFrames(): Promise<void> {
|
|
161
|
+
// Ensure we're "starting" our loop at the top-most frame
|
|
162
|
+
await this.driver.switchTo().defaultContent();
|
|
163
|
+
|
|
164
|
+
// By default we do not remove the sandbox attr from iframe unless user specifies
|
|
165
|
+
if (this.options.noSandbox) {
|
|
166
|
+
// reinject any sandboxed iframes without the sandbox attribute so we can scan
|
|
167
|
+
await this.sandboxBuster();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Inject the script into the top-level
|
|
171
|
+
// XXX: if this `executeScript` fails, we *want* to error, as we cannot run axe-core.
|
|
172
|
+
await this.driver.executeScript(this.script);
|
|
173
|
+
|
|
174
|
+
// Get all of <iframe>s and <frame>s at this level
|
|
175
|
+
const ifs = await this.driver.findElements({ tagName: 'iframe' });
|
|
176
|
+
const fs = await this.driver.findElements({ tagName: 'frame' });
|
|
177
|
+
const frames = ifs.concat(fs);
|
|
178
|
+
|
|
179
|
+
// Inject the script into all child frames. Handle errors to ensure we don't stop execution if we fail to inject.
|
|
180
|
+
for (const childFrame of frames) {
|
|
181
|
+
try {
|
|
182
|
+
await this.handleFrame([childFrame]);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
this.errorHandler(err);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Move back to the top-most frame
|
|
189
|
+
return this.driver.switchTo().defaultContent();
|
|
190
|
+
}
|
|
191
|
+
}
|