From 24b1d717f453a2e9281b7c3201a8556da0a46792 Mon Sep 17 00:00:00 2001 From: yokra9 <53964890+yokra9@users.noreply.github.com> Date: Sun, 14 Mar 2021 13:43:09 +0900 Subject: [PATCH 1/3] Recursively find "frame"s and inject axe.js, not only "iframe"s --- packages/webdriverjs/src/axe-injector.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/webdriverjs/src/axe-injector.ts b/packages/webdriverjs/src/axe-injector.ts index 390521db..9c2d7b54 100644 --- a/packages/webdriverjs/src/axe-injector.ts +++ b/packages/webdriverjs/src/axe-injector.ts @@ -139,7 +139,9 @@ export default class AxeInjector { await this.driver.executeScript(this.script); - const frames = await this.driver.findElements({ tagName: 'iframe' }); + const ifs = await this.driver.findElements({ tagName: 'iframe' }); + const fs = await this.driver.findElements({ tagName: 'frame' }); + const frames = ifs.concat(fs); for (const childFrames of frames) { framePath.push(childFrames); @@ -171,8 +173,10 @@ export default class AxeInjector { // XXX: if this `executeScript` fails, we *want* to error, as we cannot run axe-core. await this.driver.executeScript(this.script); - // Get all of - + + + diff --git a/packages/webdriverjs/src/test/fixtures/frames/foo.html b/packages/webdriverjs/src/test/fixtures/frames/foo.html index 9ab66c76..d906571a 100644 --- a/packages/webdriverjs/src/test/fixtures/frames/foo.html +++ b/packages/webdriverjs/src/test/fixtures/frames/foo.html @@ -3,8 +3,7 @@ Foo - -

Foo

- - + + + diff --git a/packages/webdriverjs/src/test/fixtures/frames/recursive.html b/packages/webdriverjs/src/test/fixtures/frames/recursive.html index 3a3ce063..402f7f91 100644 --- a/packages/webdriverjs/src/test/fixtures/frames/recursive.html +++ b/packages/webdriverjs/src/test/fixtures/frames/recursive.html @@ -3,8 +3,7 @@ Recursive - -

Recursive

- - + + + diff --git a/packages/webdriverjs/src/test/fixtures/iframes/bar.html b/packages/webdriverjs/src/test/fixtures/iframes/bar.html new file mode 100644 index 00000000..594c0dc2 --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/iframes/bar.html @@ -0,0 +1,10 @@ + + + + Bar + + +

Bar

+ + + diff --git a/packages/webdriverjs/src/test/fixtures/iframes/baz.html b/packages/webdriverjs/src/test/fixtures/iframes/baz.html new file mode 100644 index 00000000..b5f94320 --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/iframes/baz.html @@ -0,0 +1,9 @@ + + + + Baz + + +

Baz

+ + diff --git a/packages/webdriverjs/src/test/fixtures/iframes/foo.html b/packages/webdriverjs/src/test/fixtures/iframes/foo.html new file mode 100644 index 00000000..86fe0d49 --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/iframes/foo.html @@ -0,0 +1,10 @@ + + + + Foo + + +

Foo

+ + + diff --git a/packages/webdriverjs/src/test/fixtures/iframes/recursive.html b/packages/webdriverjs/src/test/fixtures/iframes/recursive.html new file mode 100644 index 00000000..20627835 --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/iframes/recursive.html @@ -0,0 +1,10 @@ + + + + Recursive + + +

Recursive

+ + + diff --git a/packages/webdriverjs/src/test/fixtures/inner-configure-frame.html b/packages/webdriverjs/src/test/fixtures/inner-configure-frame.html new file mode 100644 index 00000000..c24cf9ab --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/inner-configure-frame.html @@ -0,0 +1,6 @@ + + + + Hello + + diff --git a/packages/webdriverjs/src/test/fixtures/multiple-frames.html b/packages/webdriverjs/src/test/fixtures/multiple-frames.html index 2547a902..4cf45788 100644 --- a/packages/webdriverjs/src/test/fixtures/multiple-frames.html +++ b/packages/webdriverjs/src/test/fixtures/multiple-frames.html @@ -1,16 +1,14 @@ - + Multiple Frames - -

this page has 3 iframes (no recursion)

-


- - - - - + + + + + + diff --git a/packages/webdriverjs/src/test/fixtures/multiple-iframes.html b/packages/webdriverjs/src/test/fixtures/multiple-iframes.html new file mode 100644 index 00000000..d776ce44 --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/multiple-iframes.html @@ -0,0 +1,16 @@ + + + + + Multiple Frames + + + +

this page has 3 iframes (no recursion)

+


+ + + + + + diff --git a/packages/webdriverjs/src/test/fixtures/nested-frames.html b/packages/webdriverjs/src/test/fixtures/nested-frames.html index 6f6f75b4..c9dd981b 100644 --- a/packages/webdriverjs/src/test/fixtures/nested-frames.html +++ b/packages/webdriverjs/src/test/fixtures/nested-frames.html @@ -3,9 +3,7 @@ Nested Frames - -

This page has nested frames!

-


- - + + + diff --git a/packages/webdriverjs/src/test/fixtures/nested-iframes.html b/packages/webdriverjs/src/test/fixtures/nested-iframes.html new file mode 100644 index 00000000..3a7a1433 --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/nested-iframes.html @@ -0,0 +1,11 @@ + + + + Nested Frames + + +

This page has nested frames!

+


+ + + diff --git a/packages/webdriverjs/src/test/fixtures/outer-configure-frame.html b/packages/webdriverjs/src/test/fixtures/outer-configure-frame.html index 6b5cb58c..f88d6b50 100644 --- a/packages/webdriverjs/src/test/fixtures/outer-configure-frame.html +++ b/packages/webdriverjs/src/test/fixtures/outer-configure-frame.html @@ -3,7 +3,7 @@ Configure Frame Test - - - + + + diff --git a/packages/webdriverjs/src/test/fixtures/outer-configure-iframe.html b/packages/webdriverjs/src/test/fixtures/outer-configure-iframe.html new file mode 100644 index 00000000..6b5cb58c --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/outer-configure-iframe.html @@ -0,0 +1,9 @@ + + + + Configure Frame Test + + + + + diff --git a/packages/webdriverjs/src/test/fixtures/recursive-frames.html b/packages/webdriverjs/src/test/fixtures/recursive-frames.html index 6725009f..f413660d 100644 --- a/packages/webdriverjs/src/test/fixtures/recursive-frames.html +++ b/packages/webdriverjs/src/test/fixtures/recursive-frames.html @@ -3,10 +3,8 @@ Recursive Frames - -

This page has a weird recursive frams!

-


- - - + + + + diff --git a/packages/webdriverjs/src/test/fixtures/recursive-iframes.html b/packages/webdriverjs/src/test/fixtures/recursive-iframes.html new file mode 100644 index 00000000..42f9deb6 --- /dev/null +++ b/packages/webdriverjs/src/test/fixtures/recursive-iframes.html @@ -0,0 +1,12 @@ + + + + Recursive Frames + + +

This page has a weird recursive frams!

+


+ + + + diff --git a/packages/webdriverjs/src/test/test.ts b/packages/webdriverjs/src/test/test.ts index 865a6efa..04fea3fc 100644 --- a/packages/webdriverjs/src/test/test.ts +++ b/packages/webdriverjs/src/test/test.ts @@ -83,6 +83,26 @@ describe('@axe-core/webdriverjs', () => { }); describe('configure', () => { + it('should find configured violations in all iframes', async () => { + await driver.get(`${addr}/outer-configure-iframe.html`); + const results = await new AxeBuilder(driver) + .options({ + rules: { + 'landmark-one-main': { enabled: false }, + 'page-has-heading-one': { enabled: false }, + region: { enabled: false }, + 'html-lang-valid': { enabled: false }, + bypass: { enabled: false } + } + }) + .configure(json) + .analyze(); + + assert.equal(results.violations[0].id, 'dylang'); + // the second violation is in a iframe + assert.equal(results.violations[0].nodes.length, 2); + }); + it('should find configured violations in all frames', async () => { await driver.get(`${addr}/outer-configure-frame.html`); const results = await new AxeBuilder(driver) @@ -135,6 +155,22 @@ describe('@axe-core/webdriverjs', () => { }); describe('iframe tests', () => { + it('injects into nested iframes', async () => { + await driver.get(`${addr}/nested-iframes.html`); + const executeSpy = sinon.spy(driver, 'executeScript'); + await new AxeBuilder(driver).analyze(); + /** + * Ensure we called execute 4 times + * 1. nested-iframes.html + * 2. iframes/foo.html + * 3. iframes/bar.html + * 4. iframes/baz.html + */ + assert.strictEqual(executeSpy.callCount, 4); + }); + }); + + describe('frame tests', () => { it('injects into nested frames', async () => { await driver.get(`${addr}/nested-frames.html`); const executeSpy = sinon.spy(driver, 'executeScript'); @@ -142,9 +178,9 @@ describe('@axe-core/webdriverjs', () => { /** * Ensure we called execute 4 times * 1. nested-frames.html - * 2. foo.html - * 3. bar.html - * 4. baz.html + * 2. frames/foo.html + * 3. frames/bar.html + * 4. frames/baz.html */ assert.strictEqual(executeSpy.callCount, 4); }); From f39a9eef2b1c67503b7899eb4e77023829d435b7 Mon Sep 17 00:00:00 2001 From: yokra9 <53964890+yokra9@users.noreply.github.com> Date: Tue, 6 Apr 2021 22:05:51 +0900 Subject: [PATCH 3/3] refactor(webdriverjs): remove unused test fixtures --- .../src/test/fixtures/frames/recursive.html | 9 --------- .../src/test/fixtures/iframes/recursive.html | 10 ---------- .../src/test/fixtures/multiple-frames.html | 14 -------------- .../src/test/fixtures/multiple-iframes.html | 16 ---------------- .../src/test/fixtures/recursive-frames.html | 10 ---------- .../src/test/fixtures/recursive-iframes.html | 12 ------------ 6 files changed, 71 deletions(-) delete mode 100644 packages/webdriverjs/src/test/fixtures/frames/recursive.html delete mode 100644 packages/webdriverjs/src/test/fixtures/iframes/recursive.html delete mode 100644 packages/webdriverjs/src/test/fixtures/multiple-frames.html delete mode 100644 packages/webdriverjs/src/test/fixtures/multiple-iframes.html delete mode 100644 packages/webdriverjs/src/test/fixtures/recursive-frames.html delete mode 100644 packages/webdriverjs/src/test/fixtures/recursive-iframes.html diff --git a/packages/webdriverjs/src/test/fixtures/frames/recursive.html b/packages/webdriverjs/src/test/fixtures/frames/recursive.html deleted file mode 100644 index 402f7f91..00000000 --- a/packages/webdriverjs/src/test/fixtures/frames/recursive.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - Recursive - - - - - diff --git a/packages/webdriverjs/src/test/fixtures/iframes/recursive.html b/packages/webdriverjs/src/test/fixtures/iframes/recursive.html deleted file mode 100644 index 20627835..00000000 --- a/packages/webdriverjs/src/test/fixtures/iframes/recursive.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - Recursive - - -

Recursive

- - - diff --git a/packages/webdriverjs/src/test/fixtures/multiple-frames.html b/packages/webdriverjs/src/test/fixtures/multiple-frames.html deleted file mode 100644 index 4cf45788..00000000 --- a/packages/webdriverjs/src/test/fixtures/multiple-frames.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - Multiple Frames - - - - - - - - - diff --git a/packages/webdriverjs/src/test/fixtures/multiple-iframes.html b/packages/webdriverjs/src/test/fixtures/multiple-iframes.html deleted file mode 100644 index d776ce44..00000000 --- a/packages/webdriverjs/src/test/fixtures/multiple-iframes.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Multiple Frames - - - -

this page has 3 iframes (no recursion)

-


- - - - - - diff --git a/packages/webdriverjs/src/test/fixtures/recursive-frames.html b/packages/webdriverjs/src/test/fixtures/recursive-frames.html deleted file mode 100644 index f413660d..00000000 --- a/packages/webdriverjs/src/test/fixtures/recursive-frames.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - Recursive Frames - - - - - - diff --git a/packages/webdriverjs/src/test/fixtures/recursive-iframes.html b/packages/webdriverjs/src/test/fixtures/recursive-iframes.html deleted file mode 100644 index 42f9deb6..00000000 --- a/packages/webdriverjs/src/test/fixtures/recursive-iframes.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - Recursive Frames - - -

This page has a weird recursive frams!

-


- - - -