|  | 
|  | 1 | +/* Puppeteer tests for the A11y. */ | 
|  | 2 | +const { AxePuppeteer } = require('axe-puppeteer'); | 
|  | 3 | +const puppeteer = require('puppeteer'); | 
|  | 4 | + | 
|  | 5 | +describe("Puppeteer accessibility tests for the Python Editor.", function() { | 
|  | 6 | +    'use strict'; | 
|  | 7 | + | 
|  | 8 | +    const editorURL = 'http://localhost:5000/editor.html'; | 
|  | 9 | +    const helpURL = 'http://localhost:5000/help.html'; | 
|  | 10 | +    let browser = null; | 
|  | 11 | + | 
|  | 12 | +    beforeAll(async () => { | 
|  | 13 | +        // Setup a headless Chromium browser. | 
|  | 14 | +        // Flags allow Puppeteer to run within a container. | 
|  | 15 | +        browser = await puppeteer.launch({ | 
|  | 16 | +            headless: true, | 
|  | 17 | +            args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage"] | 
|  | 18 | +        }); | 
|  | 19 | +    }); | 
|  | 20 | + | 
|  | 21 | +    afterAll(async () => { | 
|  | 22 | +        browser.close(); | 
|  | 23 | +    }); | 
|  | 24 | + | 
|  | 25 | +    test( 'Checks the editor.html page with Axe', async () => { | 
|  | 26 | +        // First, run some code which loads the content of the page. | 
|  | 27 | +        const page = await browser.newPage(); | 
|  | 28 | +        await page.goto(editorURL); | 
|  | 29 | +        await new AxePuppeteer(page).analyze(); | 
|  | 30 | +        await expect(page).toPassAxeTests({ | 
|  | 31 | +            // disable tab-index as we have values greater than 0 | 
|  | 32 | +            // and h1 as we aren't using this heading | 
|  | 33 | +            disabledRules: [ 'tabindex', 'page-has-heading-one' ], | 
|  | 34 | +        }); | 
|  | 35 | +        await page.close(); | 
|  | 36 | +    }); | 
|  | 37 | + | 
|  | 38 | +    test( 'Checks the Load/Save modal with Axe', async () => { | 
|  | 39 | +        const page = await browser.newPage(); | 
|  | 40 | +        await page.goto(editorURL); | 
|  | 41 | +        await page.waitForSelector("#command-files"); | 
|  | 42 | +        await page.click("#command-files"); | 
|  | 43 | +        await new AxePuppeteer(page).analyze(); | 
|  | 44 | +        await expect(page).toPassAxeTests({ | 
|  | 45 | +            // exclude everything else in main | 
|  | 46 | +            exclude: '.main', | 
|  | 47 | +            // disable checking for h1 as we aren't using this heading | 
|  | 48 | +            disabledRules: [ 'page-has-heading-one' ], | 
|  | 49 | +        }); | 
|  | 50 | +        await page.close(); | 
|  | 51 | +    }); | 
|  | 52 | + | 
|  | 53 | +    test( 'Checks the Load/Save modal with Axe', async () => { | 
|  | 54 | +        const page = await browser.newPage(); | 
|  | 55 | +        await page.goto(editorURL); | 
|  | 56 | +        await page.waitForSelector("#command-snippet"); | 
|  | 57 | +        await page.click("#command-snippet"); | 
|  | 58 | +        await new AxePuppeteer(page).analyze(); | 
|  | 59 | +        await expect(page).toPassAxeTests({ | 
|  | 60 | +            // exclude everything else in main | 
|  | 61 | +            exclude: '.main', | 
|  | 62 | +            // disable checking for h1 as we aren't using this heading | 
|  | 63 | +            disabledRules: [ 'page-has-heading-one' ], | 
|  | 64 | +        }); | 
|  | 65 | +        await page.close(); | 
|  | 66 | +    }); | 
|  | 67 | + | 
|  | 68 | +    test( 'Checks the help.html page with Axe', async () => { | 
|  | 69 | +        const page = await browser.newPage(); | 
|  | 70 | +        await page.goto(helpURL); | 
|  | 71 | +        await new AxePuppeteer(page).analyze(); | 
|  | 72 | +        await expect(page).toPassAxeTests({     | 
|  | 73 | +            // exclude code highlighter         | 
|  | 74 | +            exclude: '.hljs-comment', | 
|  | 75 | +            // disable checking for h1 as we aren't using this heading | 
|  | 76 | +            disabledRules: [ 'page-has-heading-one' ], | 
|  | 77 | +        }); | 
|  | 78 | +        await page.close(); | 
|  | 79 | +    }); | 
|  | 80 | +}); | 
0 commit comments