Skip to content

Commit

Permalink
fix(webdriverio): inject axe-core branding into all iframes (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-siek committed Apr 26, 2021
1 parent ea5f3ac commit 3f41c27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/webdriverio/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ export default class AxeBuilder {
return results;
}

/**
* Get axe-core source and configurations
* @returns {String}
*/

private get script(): string {
return `
${this.axeSource}
axe.configure({ branding: { application: 'webdriverio' }})
`;
}

/**
* Injects `axe-core` into all frames.
* @param {Element | null} browsingContext - defaults to null
Expand All @@ -179,7 +191,7 @@ export default class AxeBuilder {

private async inject(browsingContext: Element | null = null): Promise<void> {
await this.setBrowsingContext(browsingContext);
await this.client.execute(this.axeSource);
await this.client.execute(this.script);

const iframes = (await this.client.$$(this.iframeSelector())) || [];
if (!iframes.length) {
Expand Down
6 changes: 6 additions & 0 deletions packages/webdriverio/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ describe('@axe-core/webdriverio', () => {
*/
assert.strictEqual(executeSpy.callCount, 4);
});

it('injects into all iframes', async () => {
await client.url('http://qateam.dequecloud.com/attest/api/test.html');
const results = await new AxeBuilder({ client }).analyze();
assert.strictEqual(results.violations.length, 7);
});
});

describe('logOrRethrowError', () => {
Expand Down

0 comments on commit 3f41c27

Please sign in to comment.