Last active
June 4, 2020 18:46
-
-
Save drc-nloftsgard/588ddfef8d7fdd42cb7df4a50ecda884 to your computer and use it in GitHub Desktop.
script to run alfa-scrapper against a provided URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Awaiter, Scraper, Screenshot } from '@siteimprove/alfa-scraper'; | |
import { Audit, Outcome, Rule } from '@siteimprove/alfa-act'; | |
import { Rules } from '@siteimprove/alfa-rules'; | |
import { Iterable } from '@siteimprove/alfa-iterable'; | |
import { Timeout } from '@siteimprove/alfa-time'; | |
// has to be this path otherwise build error complains about private properties not matching | |
import { Page } from '@siteimprove/alfa-scraper/node_modules/@siteimprove/alfa-web/src/page'; | |
import * as path from 'path'; | |
async function runTests(name: string, url: string) { | |
let outputDir = path.join(__dirname, `alfa-${name}.png`); | |
const scraper = await Scraper.of(); | |
scraper | |
.scrape(url, { | |
awaiter: Awaiter.duration(3000), | |
screenshot: Screenshot.of(outputDir), | |
timeout: Timeout.of(20000), | |
}) | |
.then( result => { | |
if (result.isErr()) { | |
throw result.getErr(); | |
} else { | |
const page = result.get(); | |
if (page.response.status !== 200) { | |
throw Error('page did not respond with 200 OK'); | |
} else { | |
return page; | |
} | |
} | |
}) | |
.then( (page: Page) => { | |
const reducedAudit = Rules.reduce( | |
(audit: Audit<Page>, rule: Rule<Page, any, any>) => { | |
return audit.add(rule); | |
}, | |
Audit.of(page) | |
); | |
return reducedAudit.evaluate().then( (outcomes: Iterable<Outcome<Page, any, any>>) => { | |
// getting 'inapplicable' for every outcome | |
for (const outcome of outcomes) { | |
console.log('outcome', outcome); | |
} | |
}); | |
}) | |
.catch(e => { | |
console.error(e); | |
return scraper.close(); | |
}) | |
.then(() => { | |
return scraper.close(); | |
}); | |
} | |
runTests('drc.com', 'https://www.datarecognitioncorp.com/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment