@uuv/cypress
Version:
A solution to facilitate the writing and execution of E2E tests understandable by any human being using cucumber(BDD) and cypress
563 lines (562 loc) • 28.4 kB
JavaScript
;
/*******************************
NE PAS MODIFIER, FICHIER GENERE
*******************************/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Software Name : UUV
*
* SPDX-License-Identifier: MIT
*
* This software is distributed under the MIT License,
* see the "LICENSE" file for more details
*
* Authors: NJAKO MOLOM Louis Fredice & SERVICAL Stanley
* Software description: Make test writing fast, understandable by any human
* understanding English or French.
*/
const cypress_cucumber_preprocessor_1 = require("@badeball/cypress-cucumber-preprocessor");
const _context_1 = require("../_context");
require("../../../../cypress/commands");
const core_engine_1 = require("../core-engine");
const a11y_1 = require("@uuv/a11y");
const __common_1 = require("./../_.common");
/**
* Navigate to the Uri passed as a argument (full url consisting of the BASE_URL + Uri) or navigate to Url if begin with http:// or https://
* */
(0, cypress_cucumber_preprocessor_1.When)(`I visit path {string}`, function (siteUrl) {
if (siteUrl.match("^http:\\/\\/|https:\\/\\/")) {
cy.visit(`${siteUrl}`);
}
else {
cy.visit(`${Cypress.config().baseUrl}${siteUrl}`);
}
});
/**
* Triggers a click on the selected element.<br/>Make sure you've selected an element beforehand with the <strong>within...</strong> phrases.
* */
(0, cypress_cucumber_preprocessor_1.When)(`I click`, function () {
if (haveKeyBoardFocused()) {
cy.focused().click();
}
else {
cy.uuvCheckContextWithinFocusedElement().then(context => {
context.withinFocusedElement.click();
});
}
});
/**
* Triggers a click on the element with given role and specific name
* */
(0, cypress_cucumber_preprocessor_1.When)(`I click on element with role {string} and name {string}`, function (role, name) {
(0, core_engine_1.click)(role, name);
});
/**
* Writes the sentence passed as a parameter (useful for example to fill in a form field).<br/>Make sure you've selected an element beforehand with the <strong>within...</strong> phrases.
* */
(0, cypress_cucumber_preprocessor_1.When)(`I type the sentence {string}`, function (textToType) {
type(textToType);
});
/**
* Writes the sentence passed as a parameter (useful for example to fill in a form field).<br/>Make sure you've selected an element beforehand with the <strong>within...</strong> phrases.
* */
(0, cypress_cucumber_preprocessor_1.When)(`I enter the value {string}`, function (textToType) {
type(textToType);
});
/**
* Press specified key multiple times using | as: num|{key}
* */
(0, cypress_cucumber_preprocessor_1.When)(`I press {int} times on {string}`, function (nbTimes, key) {
for (let i = 1; i <= nbTimes; i++) {
(0, __common_1.pressKey)(key);
}
});
/**
* Press specified key: <table><thead><tr><th>Key</th><th>Description</th></tr></thead><tbody><tr><td>{tab}</td><td>Tabulation</td></tr><tr><td>{reverseTab}</td><td>Reverse tabulation</td></tr><tr><td>{down}</td><td>Arrow Down</td></tr><tr><td>{right}</td><td>Arrow Right</td></tr><tr><td>{left}</td><td>Arrow Left</td></tr><tr><td>{up}</td><td>Arrow Up</td></tr></tbody></table><br/>Make sure you've selected an element beforehand with the <strong>within...</strong> phrases.
* */
(0, cypress_cucumber_preprocessor_1.When)(`I press {string}`, function (key) {
(0, __common_1.pressKey)(key);
});
/**
* Move to the previous html element that can be reached with back Tab<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/en-keyboard.feature'>Examples</a>
* */
(0, cypress_cucumber_preprocessor_1.When)(`I go to previous keyboard element`, function () {
(0, __common_1.pressKey)("{reverseTab}");
});
/**
* Move to the next html element that can be reached with Tab<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/en-keyboard.feature'>Examples</a>
* */
(0, cypress_cucumber_preprocessor_1.When)(`I go to next keyboard element`, function () {
(0, __common_1.pressKey)("{tab}");
});
////////////////////////////////////////////
// Context ACTIONS
////////////////////////////////////////////
/**
* Sets the viewport dimensions with one of the presets defined by your runtime engine as Cypress: [Link](https://docs.cypress.io/api/commands/viewport#Arguments) or Playwright: [Link](https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json)
* */
(0, cypress_cucumber_preprocessor_1.Given)(`I set viewport to preset {string}`, function (viewportPreset) {
cy.viewport(viewportPreset);
});
/**
* Sets the viewport dimensions to the specified width and length
* */
(0, cypress_cucumber_preprocessor_1.Given)(`I set viewport with width {int} and height {int}`, function (width, height) {
cy.viewport(width, height);
});
/**
* Start a keyboard navigation session from the top of the page<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/en-keyboard.feature'>Examples</a>
* */
(0, cypress_cucumber_preprocessor_1.Given)(`I start a keyboard navigation from the top of the page`, function () {
cy.get("body").last().realClick({ x: 0.5, y: 0.5 });
});
/**
* Sets the timeout value (in millisecond) for finding element in the DOM <br />⚠ remember to deselect the element with <b>[I reset context](#i-reset-context)</b> if you're no longer acting on it
* */
(0, cypress_cucumber_preprocessor_1.When)(`I set timeout with value {int}`, function (newTimeout) {
cy.uuvPatchContext({
timeout: newTimeout
});
});
/**
* key.when.withinElement.description
* */
(0, cypress_cucumber_preprocessor_1.When)(`within the element with role {string} and name {string}`, function (role, name) {
(0, core_engine_1.withinRoleAndName)(role, name);
});
/**
* Selects the element whose aria-label is specified <br />⚠ remember to deselect the element with <b>[I reset context](#i-reset-context)</b> if you're no longer acting on it
* */
(0, cypress_cucumber_preprocessor_1.When)(`within the element with aria-label {string}`, function (expectedAriaLabel) {
const foundedElement = cy.uuvFindByLabelText(expectedAriaLabel, {})
.uuvFoundedElement()
.should("exist");
cy.uuvPatchContext({
withinFocusedElement: foundedElement
});
});
/**
* key.when.withinElement.description
* */
(0, cypress_cucumber_preprocessor_1.When)(`within the element with testId {string}`, function (testId) {
const foundedElement = cy.uuvFindByTestId(testId)
.uuvFoundedElement()
.should("exist");
cy.uuvPatchContext({
withinFocusedElement: foundedElement
});
});
/**
* Selects the element whose selector is specified <br />⚠ remember to deselect the element with <b>[I reset context](#i-reset-context)</b> if you're no longer acting on it
* */
(0, cypress_cucumber_preprocessor_1.When)(`within the element with selector {string}`, function (selector) {
const foundedElement = cy.uuvGetContext().then(context => {
const parentElement = context.withinFocusedElement;
if (parentElement) {
// console.log("parentElement: ", parentElement);
return parentElement.should("exist").within(() => {
cy.get(selector).as("foundedChildElement");
});
}
cy.wrap(null).as("foundedChildElement");
return cy.get(selector);
}).uuvFoundedElement()
.should("exist");
cy.uuvPatchContext({
withinFocusedElement: foundedElement
});
});
/**
* Deletes selected element and timeout
* */
(0, cypress_cucumber_preprocessor_1.When)(`I reset context`, function () {
cy.wrap(new _context_1.Context()).as("context");
if (haveKeyBoardFocused()) {
cy.focused().blur();
}
else {
cy.window().trigger("blur");
}
});
/**
* Mock a named API response with body. <i>If you use Playwright as runtime engine, <b>request</b> and <b>named</b> are unused.</i>
* */
(0, cypress_cucumber_preprocessor_1.When)(`I mock a request {} on url {string} named {string} with content {}`, function (verb, uri, name, body) {
cy
.intercept(verb, uri, {
body: body
})
.as(name);
});
/**
* Mock a named API response with status code
* */
(0, cypress_cucumber_preprocessor_1.When)(`I mock a request {} on url {string} named {string} with status code {int}`, function (verb, uri, name, statusCode) {
cy
.intercept(verb, uri, {
statusCode: statusCode
})
.as(name);
});
/**
* Mock a named API response with file's extension .json, .js, .coffee, .html, .txt, .csv, .png, .jpg, .jpeg, .gif, .tif, .tiff, .zip
* */
(0, cypress_cucumber_preprocessor_1.When)(`I mock a request {} on url {string} named {string} with fixture {}`, function (verb, uri, name, fixture) {
cy
.intercept(verb, uri, {
fixture: fixture
})
.as(name);
});
////////////////////////////////////////////
// INTERCEPTION
////////////////////////////////////////////
/**
* Sets one or more headers to the indicated http request and only for the Http method (GET / POST / etc...) passed as a argument.<i> If you use Playwright as execution engine, <b>method</b> isn't used.</i>
* */
(0, cypress_cucumber_preprocessor_1.When)(`I set header(s) for uri {string} and method {string}`, function (url, method, headersToSet) {
cy.intercept(method, url, (req) => {
req.headers = {
...req.headers,
...headersToSet.rowsHash()
};
req.continue();
});
});
/**
* Sets one or more headers to the indicated http request
* */
(0, cypress_cucumber_preprocessor_1.When)(`I set header(s) for uri {string}`, function (url, headersToSet) {
cy.intercept(url, (req) => {
req.headers = {
...req.headers,
...headersToSet.rowsHash()
};
req.continue();
});
});
////////////////////////////////////////////
// VALIDATION
////////////////////////////////////////////
/**
* Checks the current html page have the specified title
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see the page title {string}`, function (pageTitle) {
cy.title().should("eq", pageTitle);
});
/**
* Checks that an Html element exists with the specified content
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with content {string}`, function (textContent) {
cy.uuvFindByText(textContent, {})
.uuvFoundedElement()
.should("exist");
});
/**
* Checks that an Html element does not exists with the specified content
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not see an element with content {string}`, function (textContent) {
cy.uuvFindByText(textContent, {})
.should("not.exist");
});
/**
* Checks that an Html element exists with the specified data-testid attribute
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with testId {string}`, function (testId) {
cy.uuvFindByTestId(testId)
.uuvFoundedElement()
.should("exist");
});
/**
* Checks that an Html element does not exists with the specified data-testid attribute
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not see an element with testId {string}`, function (testId) {
cy.uuvFindByTestId(testId)
.should("not.exist");
});
/**
* Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/)
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with role {string} and name {string}`, function (role, name) {
(0, core_engine_1.findWithRoleAndName)(role, name);
});
/**
* Checks that an Html element does not exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/)
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not see an element with role {string} and name {string}`, function (role, name) {
(0, core_engine_1.notFoundWithRoleAndName)(role, name);
});
/**
* Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with role {string} and name {string} and content {string}`, function (expectedRole, name, expectedTextContent) {
(0, core_engine_1.findWithRoleAndNameAndContent)(expectedRole, name, expectedTextContent);
});
/**
* Checks that the Html element with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/) is focused<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/en-keyboard.feature'>Examples</a>
* */
(0, cypress_cucumber_preprocessor_1.Then)(`the element with role {string} and name {string} should be keyboard focused`, function (expectedRole, name) {
(0, core_engine_1.findWithRoleAndNameFocused)(expectedRole, name);
});
/**
* Checks that the Html element with the specified selector is focused<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/en-keyboard.feature'>Examples</a>
* */
(0, cypress_cucumber_preprocessor_1.Then)(`the element with selector {string} should be keyboard focused`, function (selector) {
cy.get(selector).then(foundElement => {
cy.focused().then(focusedElement => {
expect(foundElement?.get(0)).eq(focusedElement?.get(0));
});
});
});
/**
* Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content, and with the disabled attribute set to true
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with role {string} and name {string} and content {string} disabled`, function (expectedRole, name, expectedTextContent) {
(0, core_engine_1.findWithRoleAndNameAndContentDisable)(expectedRole, name, expectedTextContent);
});
/**
* Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content, and with the disabled attribute set to false
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with role {string} and name {string} and content {string} not disabled`, function (expectedRole, name, expectedTextContent) {
(0, core_engine_1.findWithRoleAndNameAndContentEnable)(expectedRole, name, expectedTextContent);
});
/**
* Checks that an Html element exists with the specified aria-label attribute
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with aria-label {string}`, function (expectedAriaLabel) {
cy.uuvFindByLabelText(expectedAriaLabel, {})
.uuvFoundedElement()
.should("exist");
});
/**
* Checks that an Html element does not exists with the specified aria-label attribute
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not see an element with aria-label {string}`, function (expectedAriaLabel) {
cy.uuvFindByLabelText(expectedAriaLabel, {})
.should("not.exist");
});
/**
* Checks that an Html element exists with the specified aria-label attribute and content
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with aria-label {string} and content {string}`, function (expectedAriaLabel, expectedTextContent) {
cy.uuvFindByLabelText(expectedAriaLabel, {})
.uuvFoundedElement()
.should("exist")
.then((response) => {
assert.equal(response.length, 1);
(0, core_engine_1.assertTextContent)(response, expectedTextContent);
});
});
/**
* Move to the previous html element that can be reached with Tab and checks that the Html element with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/) is focused<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/en-keyboard.feature'>Examples</a>
* */
(0, cypress_cucumber_preprocessor_1.When)(`the previous keyboard element focused should have name {string} and role {string}`, function (expectedRole, name) {
(0, __common_1.pressKey)("{reverseTab}");
(0, core_engine_1.findWithRoleAndNameFocused)(expectedRole, name);
});
/**
* "Move to the next html element that can be reached with Tab and checks that the Html element with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/) is focused<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/en-keyboard.feature'>Examples</a>
* */
(0, cypress_cucumber_preprocessor_1.When)(`the next keyboard element focused should have name {string} and role {string}`, function (expectedRole, name) {
(0, __common_1.pressKey)("{tab}");
(0, core_engine_1.findWithRoleAndNameFocused)(expectedRole, name);
});
/**
* Wait that a named mock has been consumed until timeout
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should consume a mock named {string}`, function (name) {
cy.wait([`@${name}`]);
});
/**
* key.when.click.withContext.description
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I wait {int} ms`, function (ms) {
cy.wait(ms);
});
/**
* Checks that there is a list with the specified [name](https://russmaxdesign.github.io/html-elements-names/) containing list items.<br/> <u>Example</u>\n```gherkin\nThen I should see a list named "test-list" and containing\n| First element |\n| Second element |\n| Third element |\n```
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see a list named {string} and containing`, function (expectedListName, expectedElementsOfList) {
cy.uuvFindByRole("list", { name: expectedListName })
.uuvFoundedElement()
.should("exist")
.within(() => {
return cy.findAllByRole("listitem", {}).then((listitem) => {
const foundedElement = [];
for (let i = 0; i < listitem.length; i++) {
foundedElement.push([listitem[i].textContent]);
}
assert.equal(listitem.length, expectedElementsOfList.raw().length);
assert.deepEqual(foundedElement, expectedElementsOfList.raw(), `expected [${foundedElement}] to be [${expectedElementsOfList.raw()}]`);
});
});
});
/**
* Checks that there is a grid with the specified [name](https://russmaxdesign.github.io/html-elements-names/) containing list items.<br/> <u>Example</u>\n```gherkin\nWhen I visit path "https://e2e-test-quest.github.io/simple-webapp/grid.html"\nThen I should see a grid named "HTML Grid Example" and containing\n| Make | Model | Price |\n| ------------ | ------- | ------ |\n| Toyota | Celica | 35000 |\n| Ford | Mondeo | 32000 |\n| Porsche | Boxster | 72000 |\n| BMW | M50 | 60000 |\n| Aston Martin | DBX | 190000 |\n```
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see a grid named {string} and containing`, function (expectedListName, pExpectedElementsOfList) {
const expectedElementsOfList = (0, __common_1.removeHeaderSeparatorLine)(pExpectedElementsOfList);
cy.uuvFindByRole("grid", { name: expectedListName })
.uuvFoundedElement()
.should("exist")
.within(() => {
(0, __common_1.expectTableToHaveContent)(expectedElementsOfList, "gridcell");
});
});
/**
* Checks that there is a treegrid with the specified [name](https://russmaxdesign.github.io/html-elements-names/) containing list items.<br/> <u>Example</u>\n```gherkin\nWhen I visit path "https://e2e-test-quest.github.io/simple-webapp/treegrid.html"\nThen I should see a treegrid named "HTML Treegrid Example" and containing\n| Make | Model | Price |\n| ------------ | ------- | ------ |\n| Toyota | Celica | 35000 |\n| Ford | Mondeo | 32000 |\n| Porsche | Boxster | 72000 |\n| BMW | M50 | 60000 |\n| Aston Martin | DBX | 190000 |\n```
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see a treegrid named {string} and containing`, function (expectedListName, pExpectedElementsOfList) {
const expectedElementsOfList = (0, __common_1.removeHeaderSeparatorLine)(pExpectedElementsOfList);
cy.uuvFindByRole("treegrid", { name: expectedListName })
.uuvFoundedElement()
.should("exist")
.within(() => {
(0, __common_1.expectTableToHaveContent)(expectedElementsOfList, "gridcell");
});
});
/**
* Checks that there is a table with the specified [name](https://russmaxdesign.github.io/html-elements-names/) containing list items.<br/> <u>Example</u>\n```gherkin\nWhen I visit path "https://e2e-test-quest.github.io/simple-webapp/table.html"\nThen I should see a table named "test-list" and containing\n| Company | Contact | Country |\n| ----------------------------- | ---------------- | ------- |\n| Alfreds Futterkiste | Maria Anders | Germany |\n| Centro comercial Moctezuma | Francisco Chang | Mexico |\n| Ernst Handel | Roland Mendel | Austria |\n| Island Trading | Helen Bennett | UK |\n| Laughing Bacchus Winecellars | Yoshi Tannamuri | Canada |\n| Magazzini Alimentari Riuniti | Giovanni Rovelli | Italy |\n```
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see a table named {string} and containing`, function (expectedListName, pExpectedElementsOfList) {
const expectedElementsOfList = (0, __common_1.removeHeaderSeparatorLine)(pExpectedElementsOfList);
cy.uuvFindByRole("table", { name: expectedListName })
.uuvFoundedElement()
.should("exist")
.within(() => {
(0, __common_1.expectTableToHaveContent)(expectedElementsOfList, "cell");
});
});
/**
* Checks Html attributes of the selected element
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see these attributes with values`, function (expectedAttributeList) {
cy.uuvCheckContextWithinFocusedElement().then((context) => {
const elementToSelect = context.withinFocusedElement;
for (const currentIndex in expectedAttributeList.raw()) {
const attributeName = expectedAttributeList.raw()[currentIndex][0];
const attributeValue = expectedAttributeList.raw()[currentIndex][1];
elementToSelect.then((response) => {
assert.equal(response[0].getAttribute(attributeName), attributeValue);
});
}
});
});
/**
* Checks that an Html element exists with the specified selector
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should see an element with selector {string}`, function (selector) {
cy.get(selector).should("exist");
});
/**
* Check that the current page have no accessibility issue for [axe-core](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md)
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not have any axe-core accessibility issue`, function () {
cy.injectUvvA11y();
cy.checkUvvA11y({
reference: a11y_1.A11yReferenceEnum.WCAG_WEB
});
});
/**
* Check that the current page have not critical accessibility issue for [axe-core](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md)
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not have any axe-core critical accessibility issue`, function () {
cy.injectUvvA11y();
cy.checkUvvA11y({
reference: a11y_1.A11yReferenceEnum.WCAG_WEB,
runnerOptions: {
includedImpacts: ["critical"]
}
});
});
/**
* Check that the current page have not accessibility issue for [axe-core](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md) with one or more impacts in: 'minor','moderate','serious','critical'
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not have any axe-core accessibility issue with {} impact(s)`, function (impacts) {
cy.injectUvvA11y();
cy.checkUvvA11y({
reference: a11y_1.A11yReferenceEnum.WCAG_WEB,
runnerOptions: {
includedImpacts: [impacts]
}
});
});
/**
* Check that the current page have not accessibility issue for [axe-core](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md) [with one or more Accessibility Standards](https://github.com/dequelabs/axe-core/blob/HEAD/doc/API.md#axe-core-tags)
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not have any axe-core accessibility issue with accessibility standard(s) {}`, function (tags) {
cy.injectUvvA11y();
cy.checkUvvA11y({
reference: a11y_1.A11yReferenceEnum.WCAG_WEB,
runnerOptions: {
runOnly: {
type: "tag",
values: [tags]
}
}
});
});
/**
* Check that the current page have no accessibility issue for [axe-core](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md) [with an option](https://github.com/dequelabs/axe-core/blob/HEAD/doc/API.md#options-parameter) on the specific [context](https://github.com/dequelabs/axe-core/blob/HEAD/doc/API.md#context-parameter)
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not have any axe-core accessibility issue with context json fixture {} and option json fixture {}`, function (context, option) {
cy.injectAxe();
cy.fixture(context).then(context => {
cy.fixture(option).then(option => {
cy.checkA11y(context, option);
});
});
});
/**
* Check that the current page have no accessibility issue for [axe-core](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md) [with an option](https://github.com/dequelabs/axe-core/blob/HEAD/doc/API.md#options-parameter)
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not have any axe-core accessibility issue with option json fixture {}`, function (option) {
cy.injectUvvA11y();
cy.fixture(option).then(data => {
cy.checkUvvA11y({
reference: a11y_1.A11yReferenceEnum.WCAG_WEB,
runnerOptions: data
});
});
});
/**
* Check that the current page have no [accessibility issue](https://accessibilite.numerique.gouv.fr/methode/criteres-et-tests/) based on RGAA standards
* */
(0, cypress_cucumber_preprocessor_1.Then)(`I should not have any rgaa accessibility issue`, function () {
cy.injectUvvA11y();
cy.checkUvvA11y({
reference: a11y_1.A11yReferenceEnum.RGAA
});
});
(0, cypress_cucumber_preprocessor_1.Then)(`I should have the following result based on the rgaa reference`, function (expectedResult) {
cy.injectUvvA11y();
cy.checkUvvA11y({
reference: a11y_1.A11yReferenceEnum.RGAA,
expectedResult: {
value: JSON.parse(expectedResult)
}
});
});
(0, cypress_cucumber_preprocessor_1.Then)(`I should have the following partial result based on the rgaa reference`, function (expectedResult) {
cy.injectUvvA11y();
cy.checkUvvA11y({
reference: a11y_1.A11yReferenceEnum.RGAA,
expectedResult: {
value: JSON.parse(expectedResult),
isContainsMode: true
}
});
});
function haveKeyBoardFocused() {
return Cypress.$(":focus").length > 0;
}
function type(textToType) {
cy.uuvCheckContextWithinFocusedElement(true).then((context) => {
if (context.withinFocusedElement) {
context.withinFocusedElement.type(textToType);
}
else if (haveKeyBoardFocused()) {
cy.focused().type(textToType);
}
});
}