Skip to content

Commit

Permalink
refactor(webdriverio): rewrite webdriverio to TS (dequelabs#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-siek authored Feb 23, 2021
1 parent 35eeb4f commit de25666
Show file tree
Hide file tree
Showing 24 changed files with 8,562 additions and 3,861 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
steps:
- checkout
- restore_dependency_cache
- run: npm run test --prefix=packages/webdriverio
- run: npm run coverage --prefix=packages/webdriverio

reporter-earl:
<<: *defaults
Expand Down
3 changes: 2 additions & 1 deletion .github/axe-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ exclude:
- packages/react/cypress/**/*
- packages/cli/test/**/*
- packages/cli/testutils/**/*
- packages/webdriverjs/src/test/fixtures/**
- packages/webdriverio/fixtures/**
- packages/webdriverjs/src/test/fixtures/**
11 changes: 3 additions & 8 deletions packages/webdriverio/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
module.exports = {
rules: {
'@typescript-eslint/no-empty-function': 'off',
'prefer-spread': 'off',
'prefer-rest-params': 'off'
},
overrides: [
{
files: 'tests/**/*.js',
env: {
jest: true
files: ['*.test.ts', '*.test.tsx'],
rules: {
'@typescript-eslint/no-explicit-any': 'off'
}
}
]
Expand Down
139 changes: 137 additions & 2 deletions packages/webdriverio/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,140 @@
# @axe-core/webdriverio

Provides bindings for axe with webdriverio
> Provides a chainable axe API for WebdriverIO and automatically injects into all frames.
Previous versions of this program were maintained at [dequelabs/axe-webdriverio](https://github.com/dequelabs/axe-webdriverio).
## Getting Started

Install [Node.js](https://docs.npmjs.com/getting-started/installing-node) if you haven't already.

> Download and install any necessary browser drivers on your machine's PATH. [More on WebdriverIO setup](https://v6.webdriver.io/docs/gettingstarted.html#taking-the-first-step).
Install `@axe-core/webdriverio` and its dependencies:

NPM:

```console
npm install @axe-core/webdriverio
```

Yarn:

```console
yarn add @axe-core/webdriverio
```

## Usage

This module uses a chainable API to assist in injecting, configuring, and analyzing axe with WebdriverIO. As such, it is required to pass an instance of WebdriverIO.

Here is an example of a script that will drive WebdriverIO to a page, perform an analysis, and then log results to the console.

```js
const AxeBuilder = require('@axe-core/webdriverio').default;
const { remote } = require('webdriverio');

(async () => {
const client = await remote({
capabilities: {
browserName: 'firefox'
}
});

await client.url('https://dequeuniversity.com/demo/mars/');

const builder = new AxeBuilder({ client });
try {
const results = await builder.analyze();
console.log(results);
} catch (e) {
console.error(e);
}
})();
```

## AxeBuilder({ client: WebdriverIO.BrowserObject })

Constructor for the AxeBuilder helper. You must pass an instance of WebdriverIO as the first argument.

```js
const builder = new AxeBuilder({ client });
```

### AxeBuilder#include(selector: String)

Adds a CSS selector to the list of elements to include in analysis

```js
new AxeBuilder({ client }).include('.results-panel');
```

### AxeBuilder#exclude(selector: String)

Add a CSS selector to the list of elements to exclude from analysis

```js
new AxeBuilder({ client }).exclude('.another-element');
```

### AxeBuilder#options(options: [axe.RunOptions](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter))

Specifies options to be used by `axe.run`. Will override any other configured options. including calls to `AxeBuilder#withRules()` and `AxeBuilder#withTags()`. See [axe-core API documentation](https://github.com/dequelabs/axe-core/blob/master/doc/API.md) for information on its structure.

```js
new AxeBuilder({ client }).options({ checks: { 'valid-lang': ['orcish'] } });
```

### AxeBuilder#withRules(rules: String|Array)

Limits analysis to only those with the specified rule IDs. Accepts a String of a single rule ID or an Array of multiple rule IDs. Subsequent calls to `AxeBuilder#options`, `AxeBuilder#withRules` or `AxeBuilder#withRules` will override specified options.

```js
new AxeBuilder({ client }).withRules('html-lang');
```

```js
new AxeBuilder({ client }).withRules(['html-lang', 'image-alt']);
```

### AxeBuilder#withTags(tags: String|Array)

Limits analysis to only those with the specified rule IDs. Accepts a String of a single tag or an Array of multiple tags. Subsequent calls to `AxeBuilder#options`, `AxeBuilder#withRules` or `AxeBuilder#withRules` will override specified options.

```js
new AxeBuilder({ client }).withTags('wcag2a');
```

```js
new AxeBuilder({ client }).withTags(['wcag2a', 'wcag2aa']);
```

### AxeBuilder#disableRules(rules: String|Array)

Skips verification of the rules provided. Accepts a String of a single rule ID or an Array of multiple rule IDs. Subsequent calls to `AxeBuilder#options`, `AxeBuilder#disableRules` will override specified options.

```js
new AxeBuilder({ client }).disableRules('color-contrast');
```

### AxeBuilder#analyze(): Promise<axe.Results | Error>

Performs analysis and passes any encountered error and/or the result object.

```js
new AxeBuilder({ client }).analyze((err, results) => {
if (err) {
// Do something with error
}
console.log(results);
});
```

```js
new AxeBuilder({ client })
.analyze()
.then(results => {
console.log(results);
})
.catch(e => {
// Do something with error
});
```
11 changes: 11 additions & 0 deletions packages/webdriverio/fixtures/context.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Context Test</title>
</head>
<body>
<h1>Context Test</h1>
<div class="include">include me</div>
<div class="exclude">exclude me</div>
</body>
</html>
10 changes: 10 additions & 0 deletions packages/webdriverio/fixtures/frames/bar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Bar</title>
</head>
<body>
<h1>Bar</h1>
<iframe src="/frames/baz.html"></iframe>
</body>
</html>
9 changes: 9 additions & 0 deletions packages/webdriverio/fixtures/frames/baz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Baz</title>
</head>
<body>
<h1>Baz</h1>
</body>
</html>
10 changes: 10 additions & 0 deletions packages/webdriverio/fixtures/frames/foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Foo</title>
</head>
<body>
<h1>Foo</h1>
<iframe src="/frames/bar.html"></iframe>
</body>
</html>
10 changes: 10 additions & 0 deletions packages/webdriverio/fixtures/frames/recursive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Recursive</title>
</head>
<body>
<h1>Recursive</h1>
<iframe src="/frames/recursive.html"></iframe>
</body>
</html>
6 changes: 6 additions & 0 deletions packages/webdriverio/fixtures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
</html>
16 changes: 16 additions & 0 deletions packages/webdriverio/fixtures/multiple-frames.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- this page has 3 iframes each going to same src -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Multiple Frames</title>
</head>

<body>
<h1>this page has 3 iframes (no recursion)</h1>
<br /><br /><br />
<iframe src="/frames/baz.html"></iframe>
<iframe src="/frames/baz.html"></iframe>
<iframe src="/frames/baz.html"></iframe>
<iframe class="ignoredFrame" src="/frames/baz.html"></iframe>
</body>
</html>
11 changes: 11 additions & 0 deletions packages/webdriverio/fixtures/nested-frames.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Nested Frames</title>
</head>
<body>
<h1>This page has nested frames!</h1>
<br /><br /><br />
<iframe src="/frames/foo.html"></iframe>
</body>
</html>
12 changes: 12 additions & 0 deletions packages/webdriverio/fixtures/recursive-frames.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Recursive Frames</title>
</head>
<body>
<h1>This page has a weird recursive frams!</h1>
<br /><br /><br />
<iframe src="/frames/baz.html"></iframe>
<iframe src="/frames/recursive.html"></iframe>
</body>
</html>
51 changes: 0 additions & 51 deletions packages/webdriverio/lib/bindings.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/webdriverio/lib/index.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/webdriverio/lib/index.js

This file was deleted.

Loading

0 comments on commit de25666

Please sign in to comment.