Skip to content

Commit

Permalink
update findElements to queryElements in tests, remove unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
smhigley committed Feb 24, 2020
1 parent 9ae7547 commit 87954aa
Show file tree
Hide file tree
Showing 53 changed files with 1,168 additions and 1,882 deletions.
68 changes: 27 additions & 41 deletions test/tests/accordion_accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { ariaTest } = require('..');
const { By, Key } = require('selenium-webdriver');
const assertAttributeValues = require('../util/assertAttributeValues');
const assertAriaControls = require('../util/assertAriaControls');
const assertAriaLabelledby = require('../util/assertAriaLabelledby');

Expand Down Expand Up @@ -45,9 +44,8 @@ const focusMatchesElement = async function (t, selector) {
// Attributes

ariaTest('h3 element should wrap accordion button', exampleFile, 'h3-element', async (t) => {
t.plan(3);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);

for (let button of buttons) {
t.is(
Expand All @@ -59,9 +57,8 @@ ariaTest('h3 element should wrap accordion button', exampleFile, 'h3-element', a
});

ariaTest('aria-expanded on button element', exampleFile, 'button-aria-expanded', async (t) => {
t.plan(9);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);

for (let expandIndex = 0; expandIndex < buttons.length; expandIndex++) {

Expand All @@ -81,15 +78,13 @@ ariaTest('aria-expanded on button element', exampleFile, 'button-aria-expanded',
});

ariaTest('aria-controls on button element', exampleFile, 'button-aria-controls', async (t) => {
t.plan(1);


await assertAriaControls(t, ex.buttonSelector);
});

ariaTest('"aria-disabled" set on expanded sections', exampleFile, 'button-aria-disabled', async (t) => {
t.plan(9);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);

for (let expandIndex = 0; expandIndex < buttons.length; expandIndex++) {

Expand All @@ -109,9 +104,8 @@ ariaTest('"aria-disabled" set on expanded sections', exampleFile, 'button-aria-d
});

ariaTest('role "region" exists on accordion panels', exampleFile, 'region-role', async (t) => {
t.plan(3);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);
const panelIds = [];
for (let button of buttons) {
panelIds.push(await button.getAttribute('aria-controls'));
Expand All @@ -127,18 +121,16 @@ ariaTest('role "region" exists on accordion panels', exampleFile, 'region-role',
});

ariaTest('"aria-labelledby" on region', exampleFile, 'region-aria-labelledby', async (t) => {
t.plan(1);
await assertAriaLabelledby(t, ex.panelSelector);
await assertAriaLabelledby(t, ex.panelSelector);
});


// Keys

ariaTest('ENTER key expands section', exampleFile, 'key-enter-or-space', async (t) => {
t.plan(12);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));
const panels = await t.context.session.findElements(By.css(ex.panelSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);
const panels = await t.context.queryElements(t, ex.panelSelector);

for (let expandIndex of [1, 2, 0]) {
await buttons[expandIndex].sendKeys(Key.ENTER);
Expand Down Expand Up @@ -170,10 +162,9 @@ ariaTest('ENTER key expands section', exampleFile, 'key-enter-or-space', async (
});

ariaTest('SPACE key expands section', exampleFile, 'key-enter-or-space', async (t) => {
t.plan(12);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));
const panels = await t.context.session.findElements(By.css(ex.panelSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);
const panels = await t.context.queryElements(t, ex.panelSelector);

for (let expandIndex of [1, 2, 0]) {
await buttons[expandIndex].sendKeys(Key.SPACE);
Expand Down Expand Up @@ -205,9 +196,8 @@ ariaTest('SPACE key expands section', exampleFile, 'key-enter-or-space', async (
});

ariaTest('TAB moves focus between headers and displayed inputs', exampleFile, 'key-tab', async (t) => {
t.plan(22);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);

// Open a panel
await buttons[0].click();
Expand Down Expand Up @@ -280,9 +270,8 @@ ariaTest('TAB moves focus between headers and displayed inputs', exampleFile, 'k
});

ariaTest('SHIFT+TAB moves focus between headers and displayed inputs', exampleFile, 'key-shift-tab', async (t) => {
t.plan(22);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);

// Open a panel
await buttons[0].click();
Expand Down Expand Up @@ -358,9 +347,8 @@ ariaTest('SHIFT+TAB moves focus between headers and displayed inputs', exampleFi
});

ariaTest('DOWN ARROW moves focus between headers', exampleFile, 'key-down-arrow', async (t) => {
t.plan(3);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);

// Confirm focus moves through remaining items
for (let index = 0; index < ex.buttonsInOrder.length - 1; index++) {
Expand All @@ -387,7 +375,7 @@ ariaTest('DOWN ARROW moves focus between headers', exampleFile, 'key-down-arrow'

ariaTest('UP ARROW moves focus between headers', exampleFile, 'key-up-arrow', async (t) => {

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));
const buttons = await t.context.queryElements(t, ex.buttonSelector);

// Confirm focus moves through remaining items
for (let index = ex.buttonsInOrder.length - 1; index > 0; index--) {
Expand All @@ -413,9 +401,8 @@ ariaTest('UP ARROW moves focus between headers', exampleFile, 'key-up-arrow', as
});

ariaTest('HOME key will always move focus to first button', exampleFile, 'key-home', async (t) => {
t.plan(3);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);
const lastIndex = ex.buttonsInOrder.length - 1;

// Confirm focus moves through remaining items
Expand All @@ -433,9 +420,8 @@ ariaTest('HOME key will always move focus to first button', exampleFile, 'key-ho
});

ariaTest('END key will always move focus to last button', exampleFile, 'key-end', async (t) => {
t.plan(3);

const buttons = await t.context.session.findElements(By.css(ex.buttonSelector));

const buttons = await t.context.queryElements(t, ex.buttonSelector);
const lastIndex = ex.buttonsInOrder.length - 1;

// Confirm focus moves through remaining items
Expand Down
5 changes: 2 additions & 3 deletions test/tests/alert_alert.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { ariaTest } = require('..');
const { By, Key } = require('selenium-webdriver');
const { By } = require('selenium-webdriver');

const exampleFile = 'alert/alert.html';

Expand All @@ -13,8 +13,7 @@ const ex = {
// Attributes

ariaTest('role="alert" on alert element', exampleFile, 'alert-role', async (t) => {
t.plan(2);


t.false(
await t.context.session.findElement(By.css(ex.alertSelector)).isDisplayed(),
'[role="alert"] element found and should not be displayed on pageload'
Expand Down
10 changes: 4 additions & 6 deletions test/tests/breadcrumb_index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { ariaTest } = require('..');
const { By, Key } = require('selenium-webdriver');
const { By } = require('selenium-webdriver');
const assertAriaLabelExists = require('../util/assertAriaLabelExists');

const exampleFile = 'breadcrumb/index.html';
Expand All @@ -13,15 +13,13 @@ const ex = {
// Attributes

ariaTest('aria-label attribute on nav element', exampleFile, 'aria-label', async (t) => {
t.plan(1);
await assertAriaLabelExists(t, ex.breadcrumbSelector);
await assertAriaLabelExists(t, ex.breadcrumbSelector);
});

ariaTest('aria-current element should exist on relevent link', exampleFile, 'aria-current', async (t) => {
t.plan(2);


let navElement = await t.context.session.findElement(By.css(ex.breadcrumbSelector));
let currentElement = await navElement.findElements(By.css('[aria-current]'));
let currentElement = await t.context.queryElements(t, '[aria-current]', navElement);

t.is(
currentElement.length,
Expand Down
15 changes: 5 additions & 10 deletions test/tests/button_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const ex = {
// Attributes

ariaTest('Example elements should have role="button" set', exampleFile, 'button-role', async (t) => {
t.plan(4);


for (let button of ex.buttons) {
let buttonEl = await t.context.session.findElement(By.id(button.id));

Expand All @@ -42,8 +41,7 @@ ariaTest('Example elements should have role="button" set', exampleFile, 'button-
});

ariaTest('Button examples should have tabindex="0"', exampleFile, 'button-tabindex', async (t) => {
t.plan(2);


for (let button of ex.buttons) {
let buttonEl = await t.context.session.findElement(By.id(button.id));

Expand All @@ -56,8 +54,7 @@ ariaTest('Button examples should have tabindex="0"', exampleFile, 'button-tabind
});

ariaTest('"aria-pressed" reflects button state', exampleFile, 'button-aria-pressed', async (t) => {
t.plan(3);


let toggleButtonSelector = '#' + ex.buttons[1].id;

let ariaPressedExists = await t.context.session.executeScript(async function () {
Expand Down Expand Up @@ -93,8 +90,7 @@ ariaTest('"aria-pressed" reflects button state', exampleFile, 'button-aria-press
});

ariaTest('key ENTER activates button', exampleFile, 'key-enter', async (t) => {
t.plan(3);


let toggleButtonSelector = '#' + ex.buttons[1].id;
let toggleButtonEl = await t.context.session.findElement(By.css(toggleButtonSelector));

Expand Down Expand Up @@ -149,8 +145,7 @@ ariaTest('key ENTER activates button', exampleFile, 'key-enter', async (t) => {
});

ariaTest('key SPACE activates button', exampleFile, 'key-space', async (t) => {
t.plan(3);


let toggleButtonSelector = '#' + ex.buttons[1].id;
let toggleButtonEl = await t.context.session.findElement(By.css(toggleButtonSelector));

Expand Down
43 changes: 14 additions & 29 deletions test/tests/carousel_carousel-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { ariaTest } = require('..');
const { By, Key } = require('selenium-webdriver');
const assertAttributeDNE = require('../util/assertAttributeDNE');
const assertAttributeValues = require('../util/assertAttributeValues');
const assertAriaControls = require('../util/assertAriaControls');
const assertAriaLabelExists = require('../util/assertAriaLabelExists');
Expand Down Expand Up @@ -33,8 +32,7 @@ const ex = {
// Attributes

ariaTest('section element used to contain slider', exampleFile, 'carousel-region-role', async (t) => {
t.plan(1);


// This test primarially tests that the ex.landmarkSelector points to a `section` element
const landmarkEl = await t.context.session.findElement(By.css(ex.landmarkSelector));
t.is(
Expand All @@ -45,21 +43,18 @@ ariaTest('section element used to contain slider', exampleFile, 'carousel-region
});

ariaTest('section has aria-roledescription set to carousel', exampleFile, 'carousel-region-aria-roledescription', async (t) => {
t.plan(1);


// check the aria-roledescrption set to carousel
await assertAttributeValues(t, ex.landmarkSelector, 'aria-roledescription', 'carousel');
});

ariaTest('section has aria-label', exampleFile, 'carousel-region-aria-label', async (t) => {
t.plan(1);


await assertAriaLabelExists(t, ex.landmarkSelector);
});

ariaTest('slide container have aria-live initially set to off', exampleFile, 'carousel-aria-live', async (t) => {
t.plan(4);


// On page load, `aria-level` is `off`
await assertAttributeValues(t, ex.slideContainerSelector, 'aria-live', 'off');

Expand All @@ -79,44 +74,37 @@ ariaTest('slide container have aria-live initially set to off', exampleFile, 'ca
});

ariaTest('pause, previous and next buttons have aria-label', exampleFile, 'carousel-button-aria-label', async (t) => {
t.plan(1);
await assertAriaLabelExists(t, ex.buttonSelector);
await assertAriaLabelExists(t, ex.buttonSelector);
});

ariaTest('previous and next buttons have aria-controls', exampleFile, 'carousel-button-aria-controls', async (t) => {
t.plan(2);
await assertAriaControls(t, ex.previousButtonSelector);
await assertAriaControls(t, ex.previousButtonSelector);
await assertAriaControls(t, ex.nextButtonSelector);
});

ariaTest('slides have role group', exampleFile, 'carousel-group-role', async (t) => {
t.plan(1);
await assertAriaRoles(t, 'myCarousel', 'group', 6, 'div');
await assertAriaRoles(t, 'myCarousel', 'group', 6, 'div');
});

ariaTest('slides have aria-label', exampleFile, 'carousel-group-aria-label', async (t) => {
t.plan(1);
await assertAriaLabelExists(t, ex.slideSelector);
await assertAriaLabelExists(t, ex.slideSelector);
});

ariaTest('slides have aria-roledescription set to slide', exampleFile, 'carousel-group-aria-roledescription', async (t) => {
t.plan(1);


// check the aria-roledescrption set to carousel
await assertAttributeValues(t, ex.slideSelector, 'aria-roledescription', 'slide');
});

// Keyboard interaction

ariaTest('TAB moves key through buttons', exampleFile, 'carousel-key-tab', async (t) => {
t.plan(1);


await assertTabOrder(t, ex.allFocusableItems);
});

ariaTest('ENTER pause and start carousel motion', exampleFile, 'carousel-enter-or-space-toggle', async (t) => {
t.plan(2);


let activeElement = await t.context.session.findElement(By.css(ex.activeCarouselItem)).getAttribute('aria-label');

await t.context.session.findElement(By.css(ex.pausePlayButtonSelector)).sendKeys(Key.ENTER);
Expand Down Expand Up @@ -151,8 +139,7 @@ ariaTest('ENTER pause and start carousel motion', exampleFile, 'carousel-enter-o


ariaTest('SPACE pause and start carousel motion', exampleFile, 'carousel-enter-or-space-toggle', async (t) => {
t.plan(2);


let activeElement = await t.context.session.findElement(By.css(ex.activeCarouselItem)).getAttribute('aria-label');

await t.context.session.findElement(By.css(ex.pausePlayButtonSelector)).sendKeys(Key.SPACE);
Expand Down Expand Up @@ -186,8 +173,7 @@ ariaTest('SPACE pause and start carousel motion', exampleFile, 'carousel-enter-o


ariaTest('SPACE on previous and next', exampleFile, 'carousel-key-enter-or-space-move', async (t) => {
t.plan(2);


let activeElement = await t.context.session.findElement(By.css(ex.activeCarouselItem))
.getAttribute('aria-label');

Expand Down Expand Up @@ -219,8 +205,7 @@ ariaTest('SPACE on previous and next', exampleFile, 'carousel-key-enter-or-space
});

ariaTest('ENTER on previous and next', exampleFile, 'carousel-key-enter-or-space-move', async (t) => {
t.plan(2);


let activeElement = await t.context.session.findElement(By.css(ex.activeCarouselItem))
.getAttribute('aria-label');

Expand Down
Loading

0 comments on commit 87954aa

Please sign in to comment.