-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Selenium + Code Checker example (#63)
* Add Selenium + Code Checker example * Fix knip configuration * Typo
- Loading branch information
Showing
9 changed files
with
189 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Accessibility Code Checker - Selenium integration | ||
|
||
This workspace demonstrate how to integrate Siteimprove's Accessibility Code Checker with Selenium. | ||
|
||
## Setup | ||
|
||
See [the generic instructions](../README.md#setup) for setting up the project. | ||
|
||
## Selenium | ||
|
||
All the code for checking the page reside in the [test/selenium.spec.ts](./test/selenium.spec.ts) file. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/package", | ||
"name": "code-checker-selenium", | ||
"description": "Demo of using Selenium with the Accessibility Code Checker", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"test": "node test/selenium.spec.js" | ||
}, | ||
"devDependencies": { | ||
"@siteimprove/alfa-selenium": "^0.74.2", | ||
"@siteimprove/alfa-test": "^0.93.8", | ||
"@siteimprove/alfa-test-utils": "^0.74.2", | ||
"@types/selenium-webdriver": "^4", | ||
"selenium-webdriver": "^4.25.0" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Selenium } from "@siteimprove/alfa-selenium"; | ||
import { Audit, Logging, SIP } from "@siteimprove/alfa-test-utils"; | ||
|
||
import { test } from "@siteimprove/alfa-test"; | ||
|
||
import { Browser, Builder, WebDriver } from "selenium-webdriver"; | ||
import chrome from "selenium-webdriver/chrome.js"; | ||
|
||
let driver: WebDriver | undefined; | ||
|
||
const options = new chrome.Options(); | ||
options.addArguments("--headless", "--no-sandbox", "--disable-dev-shm-usage"); | ||
|
||
test("Page should be accessible", async (t) => { | ||
// Create a browser instance | ||
driver = await new Builder() | ||
.forBrowser(Browser.CHROME) | ||
.setChromeOptions(options) | ||
.build(); | ||
|
||
// Navigate to the local web page | ||
// This suppose that the server is already started. See the demo-site folder. | ||
// TODO: Replace with your own page | ||
await driver.get("http://localhost:5173"); | ||
|
||
/* | ||
* Usual Selenium instructions can live here. | ||
* For example, navigating through the page, opening menus or modals, etc. | ||
*/ | ||
|
||
// Scrape the page | ||
const alfaPage = await Selenium.toPage(driver); | ||
|
||
// Close the driver | ||
await driver.close(); | ||
|
||
// Run the audit | ||
const alfaResult = await Audit.run(alfaPage); | ||
|
||
// Setup credentials from environment variables. | ||
const userName = process.env.SI_USER_EMAIL; | ||
const apiKey = process.env.SI_API_KEY; | ||
|
||
// Upload the result to Siteimprove Intelligence Platform, if credentials are provided | ||
const url = await SIP.upload(alfaResult, { | ||
userName, | ||
apiKey, | ||
testName: (git) => `{git.BranchName} – Selenium integration`, | ||
}); | ||
|
||
// Log the result to the console | ||
Logging.fromAudit(alfaResult, url).print(); | ||
|
||
// Check if some rule was failing. | ||
const failingRules = alfaResult.resultAggregates.filter( | ||
(aggregate) => aggregate.failed > 0, | ||
); | ||
|
||
// Fail the test if any rule failed. | ||
t.equal( | ||
failingRules.size, | ||
0, | ||
`The page has ${failingRules.size} failing rules`, | ||
); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/tsconfig", | ||
"extends": "../tsconfig.json", | ||
"files": ["test/selenium.spec.ts"] | ||
} |
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
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
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