Skip to content

Commit

Permalink
Update docs and types for axe commands. (#3996)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Jan 24, 2024
1 parent c5331d2 commit 98c4c44
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 68 deletions.
11 changes: 5 additions & 6 deletions lib/api/client-commands/axeInject.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Injects the [axe-core](https://github.com/dequelabs/axe-core) js library into the current page (using the .executeScript() command).
* Injects the [axe-core](https://github.com/dequelabs/axe-core) js library into the current page (using the `.executeScript()` command).
* To be paired with `.axeRun()` to evaluate the axe-core accessibility rules.
*
* @example
* describe('accessibility testing', function() {
*
* it('accessibility rule subset', function(browser) {
* describe('accessibility testing', function () {
* it('accessibility rule subset', function (browser) {
* browser
* .url('https://www.w3.org/WAI/demos/bad/after/home.html')
* .assert.titleEquals('Welcome to CityLights! [Accessible Home Page]')
Expand All @@ -13,10 +13,9 @@
* runOnly: ['color-contrast', 'image-alt'],
* });
* });
* })
* });
*
* @method axeInject
* @link https://github.com/dequelabs/axe-core
* @syntax browser.axeInject()
* @api protocol.accessibility
* @since 2.3.6
Expand Down
16 changes: 7 additions & 9 deletions lib/api/client-commands/axeRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
* Analyzes the current page against applied axe rules.
*
* @example
* describe('accessibility testing', function() {
*
* it('accessibility rule subset', function(browser) {
* describe('accessibility testing', function () {
* it('accessibility rule subset', function (browser) {
* browser
* .url('https://www.w3.org/WAI/demos/bad/after/home.html')
* .assert.titleEquals('Welcome to CityLights! [Accessible Home Page]')
Expand All @@ -13,17 +12,16 @@
* runOnly: ['color-contrast', 'image-alt'],
* });
* });
* })
* });
*
* @method axeRun
* @link https://github.com/dequelabs/axe-core
* @syntax browser.axeRun('body')
* @param {string} selector The CSS selector used to locate the element.
* @param {object} options Object containing rules configuration to use when performing the analysis
* @see https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter
* @param {function} [callback] Optional callback function which is called with the results
* @param {*} [context] Defines the scope of the analysis, will cascade to child elements. See [axe-core docs](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#context-parameter) for more details.
* @param {object} [options] Object containing rules configuration to use when performing the analysis. See [axe-core docs](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#options-parameter) for more details.
* @param {function} [callback] Optional callback function which is called with the results.
* @api protocol.accessibility
* @since 2.3.6
* @see https://www.deque.com/axe/core-documentation/api-documentation/#api-name-axerun
*/
module.exports = class AxeInject {
static get allowOverride() {
Expand Down
83 changes: 44 additions & 39 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2516,16 +2516,21 @@ export interface ClientCommands extends ChromiumClientCommands {
): Awaitable<this, undefined>;

/**
* Injects the axe-core js library into the current page (using the .executeScript() command) to be paired
* with axeRun to evaluate the axe-core accessibility rules.
* Injects the [axe-core](https://github.com/dequelabs/axe-core) js library into the current page (using the `.executeScript()` command).
* To be paired with `.axeRun()` to evaluate the axe-core accessibility rules.
*
* @example
* this.demoTest = function () {
* browser
* .url('https://nightwatchjs.org')
* .axeInject()
* .axeRun();
* };
* describe('accessibility testing', function () {
* it('accessibility rule subset', function (browser) {
* browser
* .url('https://www.w3.org/WAI/demos/bad/after/home.html')
* .assert.titleEquals('Welcome to CityLights! [Accessible Home Page]')
* .axeInject()
* .axeRun('body', {
* runOnly: ['color-contrast', 'image-alt'],
* });
* });
* });
*
* @see https://nightwatchjs.org/api/axeInject.html
*/
Expand All @@ -2535,46 +2540,46 @@ export interface ClientCommands extends ChromiumClientCommands {
* Analyzes the current page against applied axe rules.
*
* @example
* this.demoTest = function () {
* browser
* .url('https://nightwatchjs.org')
* .axeInject()
* .axeRun(
* 'body',
* { runOnly: ['color-contrast', 'image-alt'] }
* );
* };
*
* @example
* this.demoTest = function () {
* browser
* .url('https://nightwatchjs.org')
* .axeInject()
* .axeRun(
* 'body',
* {
* 'color-contrast': {
* enabled: false
* }
* },
* }
* );
* };
* describe('accessibility testing', function () {
* it('accessibility rule subset', function (browser) {
* browser
* .url('https://www.w3.org/WAI/demos/bad/after/home.html')
* .assert.titleEquals('Welcome to CityLights! [Accessible Home Page]')
* .axeInject()
* .axeRun('body', {
* runOnly: ['color-contrast', 'image-alt'],
* });
* });
*
* it('accessibility rule subset 2', function (browser) {
* browser
* .url('https://nightwatchjs.org')
* .axeInject()
* .axeRun(['#navBar', 'nav'], {
* rules: {
* 'color-contrast': { enabled: false },
* }
* });
* });
* });
*
* @param selector - CSS selector to scope rule analysis against, will cascade to child elements
* @param options - Allows configuration of what rules will be run (accessibility standard or rules to enable/disable)
* @see {@link https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter}
* @param context - Defines the scope of the analysis, will cascade to child elements. See
* [axe-core docs](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#context-parameter) for more details.
* @param options - Allows configuration of what rules will be run (accessibility standard or rules to enable/disable).
* See [axe-core docs](https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter) for more details.
* @param callback - Optional callback function which is called with the results.
*
* @see {@link https://nightwatchjs.org/api/axeRun.html}
* @see {@link https://github.com/dequelabs/axe-core/blob/master/doc/API.md#api-name-axerun}
*/
axeRun(
selector?: string,
context?: unknown,
options?: { [key: string]: any },
callback?: (
this: NightwatchAPI,
result: NightwatchCallbackResult<null>
result: NightwatchCallbackResult<{[key: string]: any}>
) => void
): Awaitable<this, null>;
): Awaitable<this, {[key: string]: any}>;
}

export interface ElementCommands {
Expand Down
24 changes: 10 additions & 14 deletions types/tests/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,18 @@ const testGeneral: NightwatchTests = {

'Can run accessibility tests': () => {
browser
.url('https://www.google.com')
.url('https://nightwatchjs.org')
.axeInject()
.axeRun(
'body',
{
rules: {
'color-contrast': {
enabled: false,
},
region: {
enabled: false,
},
},
.axeRun(['#navBar', 'nav'], {
rules: {
'color-contrast': { enabled: false },
region: { enabled: false }
},
(results) => {}
);
}, (result) => {
if (result.status === 0) {
expectType<{[key: string]: any}>(result.value);
}
});
},

'step one: navigate to google': () => {
Expand Down

0 comments on commit 98c4c44

Please sign in to comment.