-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test page and test of test page (#7)
Sets up a test of a static page using selenium-webdriver * Adds a test page at src/index.html * Adds a test of it at tests/index.test.ts * Removes placeholder tests * Adds a yarn serve (I wanted it for testing purposes but thought it might be nice to keep) * Switches to windows-2019 vmImage for testing (because it has selenium webdriver binaries avaiable) * Remove code coverage (there is no non-test js/ts code to cover) * Switch to jest-standard-output reporter to work around jestjs/jest#5064 * Update documenation * Enable use of the CHROMEDRIVER env var in pipelines agents
- Loading branch information
Showing
9 changed files
with
237 additions
and
35 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
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,15 @@ | ||
<html lang="en-US"> | ||
<head> | ||
<title>Example page with some accessibility issues</title> | ||
</head> | ||
<body> | ||
<h1> | ||
This is a static sample page with some accessibility issues | ||
</h1> | ||
<ul> | ||
<li>This text box has no accessible label: <input type="text"></li> | ||
<li>This text's color contrast is too low: <span style="color: #A2A2A2">low-contrast text</span></li> | ||
<li>This text has an invalid "role" attribute: <span role="invalid">span with invalid role</a></li> | ||
</ul> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { Builder, By, until, ThenableWebDriver } from 'selenium-webdriver'; | ||
import * as chrome from 'selenium-webdriver/chrome'; | ||
import * as path from 'path'; | ||
|
||
describe('index.html', () => { | ||
let driver: ThenableWebDriver; | ||
|
||
// Starting a browser instance is time-consuming, so we share one browser instance between | ||
// all tests in the file (by initializing it in beforeAll rather than beforeEach) | ||
beforeAll(async () => { | ||
// The default timeout (5 seconds) is not always enough to start/quit a browser instance | ||
jest.setTimeout(30000); | ||
|
||
// This is for the benefit of the Azure Pipelines Hosted Windows agents, which come with | ||
// webdrivers preinstalled but not on the PATH where Selenium looks for them by default. | ||
// See https://docs.microsoft.com/en-us/azure/devops/pipelines/test/continuous-test-selenium#decide-how-you-will-deploy-and-test-your-app | ||
if (process.env.ChromeWebDriver) { | ||
const hostedAgentChromedriverPath = path.join(process.env.ChromeWebDriver, 'chromedriver.exe'); | ||
const chromeService = new chrome.ServiceBuilder(hostedAgentChromedriverPath).build(); | ||
chrome.setDefaultService(chromeService); | ||
} | ||
|
||
// Selenium supports many browsers, not just Chrome. | ||
// See https://www.npmjs.com/package/selenium-webdriver for examples. | ||
driver = new Builder() | ||
.forBrowser('chrome') | ||
.setChromeOptions(new chrome.Options().headless()) | ||
.build(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await driver.quit(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
// For simplicity, we're pointing our test browser directly to a static html file on disk. | ||
// | ||
// In a real project, you would probably use a localhost http server (Express.js, for example) | ||
// and point selenium-webdriver to a http://localhost link. | ||
// | ||
// See https://jestjs.io/docs/en/testing-frameworks for examples. | ||
const pageUnderTest = 'file://' + path.join(__dirname, '..', 'src', 'index.html'); | ||
await driver.get(pageUnderTest); | ||
}); | ||
|
||
it('renders the expected header text', async () => { | ||
const header = await driver.wait(until.elementLocated(By.css('h1'))); | ||
await driver.wait(until.elementIsVisible(header)); | ||
const headerText = await header.getText(); | ||
expect(headerText).toEqual('This is a static sample page with some accessibility issues'); | ||
}); | ||
}); |
Oops, something went wrong.