@axe-core/playwright 4.2.3-alpha.188 → 4.2.3-alpha.192
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/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/error-handling.md +43 -0
- package/package.json +2 -2
- package/src/index.ts +16 -1
- package/tests/axe-playwright.spec.ts +43 -0
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var fs = require("fs");
|
|
40
|
+
var assert = require("assert");
|
|
40
41
|
var utils_1 = require("./utils");
|
|
41
42
|
var browser_1 = require("./browser");
|
|
42
43
|
var AxePartialRunner_1 = require("./AxePartialRunner");
|
|
@@ -147,7 +148,7 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
147
148
|
*/
|
|
148
149
|
AxeBuilder.prototype.analyze = function () {
|
|
149
150
|
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
-
var context, _a, page, options, runPartialDefined, results, partialResults, partials;
|
|
151
|
+
var context, _a, page, options, runPartialDefined, results, partialResults, partials, error_1;
|
|
151
152
|
return __generator(this, function (_b) {
|
|
152
153
|
switch (_b.label) {
|
|
153
154
|
case 0:
|
|
@@ -168,7 +169,15 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
168
169
|
return [4 /*yield*/, partialResults.getPartials()];
|
|
169
170
|
case 5:
|
|
170
171
|
partials = _b.sent();
|
|
171
|
-
|
|
172
|
+
_b.label = 6;
|
|
173
|
+
case 6:
|
|
174
|
+
_b.trys.push([6, 8, , 9]);
|
|
175
|
+
return [4 /*yield*/, this.finishRun(partials)];
|
|
176
|
+
case 7: return [2 /*return*/, _b.sent()];
|
|
177
|
+
case 8:
|
|
178
|
+
error_1 = _b.sent();
|
|
179
|
+
throw new Error(error_1.message + "\n Please check out https://github.com/dequelabs/axe-core-npm/blob/develop/packages/playwright/error-handling.md");
|
|
180
|
+
case 9: return [2 /*return*/];
|
|
172
181
|
}
|
|
173
182
|
});
|
|
174
183
|
});
|
|
@@ -313,6 +322,7 @@ var AxeBuilder = /** @class */ (function () {
|
|
|
313
322
|
return [4 /*yield*/, context.newPage()];
|
|
314
323
|
case 1:
|
|
315
324
|
blankPage = _b.sent();
|
|
325
|
+
assert(blankPage, 'Please make sure that you have popup blockers disabled.');
|
|
316
326
|
blankPage.evaluate(this.script());
|
|
317
327
|
return [4 /*yield*/, blankPage
|
|
318
328
|
.evaluate(browser_1.axeFinishRun, {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAyB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAyB;AACzB,+BAAiC;AAQjC,iCAAwD;AAExD,qCAKmB;AACnB,uDAAkD;AAElD;IAQE,oBAAY,EAAwC;YAAtC,IAAI,UAAA,EAAE,SAAS,eAAA;QAFrB,eAAU,GAAG,KAAK,CAAC;QAGzB,IAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,SAAS,IAAI,MAAM,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IAEI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;wBAC9C,KAA4B,IAAI,EAA9B,IAAI,UAAA,EAAU,OAAO,YAAA,CAAU;wBACjC,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,qBAAM,OAAO,CAAC,OAAO,EAAE,EAAA;;wBAAnC,SAAS,GAAG,SAAuB;wBAEzC,MAAM,CACJ,SAAS,EACT,yDAAyD,CAC1D,CAAC;wBAEF,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;wBAE3B,qBAAM,SAAS;iCACnB,QAAQ,CAAC,sBAAY,EAAE;gCACtB,cAAc,gBAAA;gCACd,OAAO,SAAA;6BACR,CAAC;iCACD,OAAO,CAAC;gCACP,SAAS,CAAC,KAAK,EAAE,CAAC;4BACpB,CAAC,CAAC,EAAA;4BAPJ,sBAAO,SAOH,EAAC;;;;KACN;IACH,iBAAC;AAAD,CAAC,AAnRD,IAmRC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Error Handling
|
|
2
|
+
|
|
3
|
+
## Table of Content
|
|
4
|
+
|
|
5
|
+
1. [Having Popup blockers enabled](#having-popup-blockers-enabled)
|
|
6
|
+
2. [AxeBuilder.setLegacyMode(legacy: boolean)](#axebuildersetlegacymodelegacy-boolean)
|
|
7
|
+
|
|
8
|
+
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.
|
|
9
|
+
|
|
10
|
+
### Having Popup blockers enabled
|
|
11
|
+
|
|
12
|
+
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.
|
|
13
|
+
|
|
14
|
+
### AxeBuilder.setLegacyMode(legacy: boolean)
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
**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.
|
|
19
|
+
|
|
20
|
+
#### Example:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
const AxeBuilder = require('@axe-core/playwright').default;
|
|
24
|
+
const playwright = require('playwright');
|
|
25
|
+
|
|
26
|
+
(async () => {
|
|
27
|
+
const browser = await playwright.chromium.launch();
|
|
28
|
+
const context = await browser.newContext();
|
|
29
|
+
const page = await context.newPage();
|
|
30
|
+
await page.goto('https://dequeuniversity.com/demo/mars/');
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const results = await new AxeBuilder({ page })
|
|
34
|
+
// enables legacy mode
|
|
35
|
+
.setLegacyMode()
|
|
36
|
+
.analyze();
|
|
37
|
+
console.log(results);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
// do something with the error
|
|
40
|
+
}
|
|
41
|
+
await browser.close();
|
|
42
|
+
})();
|
|
43
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axe-core/playwright",
|
|
3
|
-
"version": "4.2.3-alpha.
|
|
3
|
+
"version": "4.2.3-alpha.192+d49359f",
|
|
4
4
|
"description": "Provides a method to inject and analyze web pages using axe",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"functions": 100,
|
|
78
78
|
"lines": 95
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "d49359f3e105cabf9b2c9ca7883f872a1e7ed694"
|
|
81
81
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
|
+
import * as assert from 'assert';
|
|
2
3
|
import type { Page, Frame, ElementHandle } from 'playwright';
|
|
3
4
|
import type {
|
|
4
5
|
RunOptions,
|
|
@@ -161,7 +162,14 @@ export default class AxeBuilder {
|
|
|
161
162
|
context
|
|
162
163
|
);
|
|
163
164
|
const partials = await partialResults.getPartials();
|
|
164
|
-
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
return await this.finishRun(partials);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`${error.message}\n Please check out https://github.com/dequelabs/axe-core-npm/blob/develop/packages/playwright/error-handling.md`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
165
173
|
}
|
|
166
174
|
|
|
167
175
|
/**
|
|
@@ -267,7 +275,14 @@ export default class AxeBuilder {
|
|
|
267
275
|
const { page, option: options } = this;
|
|
268
276
|
const context = page.context();
|
|
269
277
|
const blankPage = await context.newPage();
|
|
278
|
+
|
|
279
|
+
assert(
|
|
280
|
+
blankPage,
|
|
281
|
+
'Please make sure that you have popup blockers disabled.'
|
|
282
|
+
);
|
|
283
|
+
|
|
270
284
|
blankPage.evaluate(this.script());
|
|
285
|
+
|
|
271
286
|
return await blankPage
|
|
272
287
|
.evaluate(axeFinishRun, {
|
|
273
288
|
partialResults,
|
|
@@ -415,6 +415,49 @@ describe('@axe-core/playwright', () => {
|
|
|
415
415
|
});
|
|
416
416
|
});
|
|
417
417
|
|
|
418
|
+
describe('axe.finishRun errors', () => {
|
|
419
|
+
const finishRunThrows = `;axe.finishRun = () => { throw new Error("No finishRun")}`;
|
|
420
|
+
|
|
421
|
+
it('throws an error if axe.finishRun throws', async () => {
|
|
422
|
+
await page.goto(`${addr}/external/index.html`);
|
|
423
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
424
|
+
//@ts-ignore
|
|
425
|
+
delete page.context().newPage;
|
|
426
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
427
|
+
//@ts-ignore
|
|
428
|
+
page.context().newPage = () => {
|
|
429
|
+
return null;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
try {
|
|
433
|
+
await new AxeBuilder({
|
|
434
|
+
page,
|
|
435
|
+
axeSource: axeSource
|
|
436
|
+
}).analyze();
|
|
437
|
+
assert.fail('Should have thrown');
|
|
438
|
+
} catch (err) {
|
|
439
|
+
assert.match(
|
|
440
|
+
err.message,
|
|
441
|
+
/Please make sure that you have popup blockers disabled./
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('throws an error if axe.finishRun throws', async () => {
|
|
447
|
+
await page.goto(`${addr}/external/index.html`);
|
|
448
|
+
|
|
449
|
+
try {
|
|
450
|
+
await new AxeBuilder({
|
|
451
|
+
page,
|
|
452
|
+
axeSource: axeSource + finishRunThrows
|
|
453
|
+
}).analyze();
|
|
454
|
+
assert.fail('Should have thrown');
|
|
455
|
+
} catch (err) {
|
|
456
|
+
assert.match(err.message, /Please check out/);
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
|
|
418
461
|
describe('setLegacyMode', () => {
|
|
419
462
|
const runPartialThrows = `;axe.runPartial = () => { throw new Error("No runPartial")}`;
|
|
420
463
|
it('runs legacy mode when used', async () => {
|