@uuv/cypress
Version:
A solution to facilitate the writing and execution of E2E tests understandable by any human being using cucumber(BDD) and cypress
185 lines (158 loc) • 7.82 kB
text/typescript
/*******************************
NE PAS MODIFIER, FICHIER GENERE
*******************************/
/**
* 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.
*/
import { Then, When, } from "@badeball/cypress-cucumber-preprocessor";
import "../../../../../../cypress/commands";
import {
click,
findWithRoleAndName,
findWithRoleAndNameAndAttribute,
findWithRoleAndNameAndContent,
findWithRoleAndNameAndContentDisabled,
findWithRoleAndNameAndContentEnabled,
findWithRoleAndNameDisabled,
findWithRoleAndNameEnabled,
findWithRoleAndNameFocused,
notFoundWithRoleAndName,
withinRoleAndName
} from "../../../core-engine";
import { pressKey } from "../../../_.common";
// Begin of General Section
/**
* Selects the element whose [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and accessible [name](https://russmaxdesign.github.io/html-elements-names/) are specified <br />⚠ remember to deselect the element with <b>[I reset context](#i-reset-context)</b> if you're no longer acting on it
* */
When(`within a text box named {string}`, function(name: string) {
withinRoleAndName("textbox", 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) and [name](https://russmaxdesign.github.io/html-elements-names/)
* */
Then(`I should see a text box named {string}`, function(name: string) {
findWithRoleAndName("textbox", 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/)
* */
Then(
`I should not see a text box named {string}`,
function(name: string) {
notFoundWithRoleAndName("textbox", name);
}
);
// End of General Section
// Begin of Type Section
/**
* Writes the sentence given as a parameter inside the specified field (useful for example to fill in a form field)
* */
When(`I type the sentence {string} in the text box named {string}`, function(textToType: string, name: string) {
cy.uuvFindByRole("textbox", { name: name }).uuvFoundedElement().type(textToType);
});
/**
* Writes the sentence given as a parameter inside the specified field (useful for example to fill in a form field)
* */
When(`I enter the value {string} in the text box named {string}`, function(textToType: string, name: string) {
cy.uuvFindByRole("textbox", { name: name }).uuvFoundedElement().type(textToType);
});
/**
* Checks that an Form element(input) 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 specified value
* */
Then(
`I should see a text box named {string} with value {string}`,
function(name: string, expectedValue: string) {
cy.uuvFindByRole("textbox", { name: name })
.uuvFoundedElement()
.should("exist")
.should("have.value", expectedValue);
}
);
// End of Type Section
// Begin of Content Section
/**
* 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
* */
Then(
`I should see a text box named {string} and containing {string}`,
function(name: string, expectedTextContent: string) {
findWithRoleAndNameAndContent("textbox", 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 true
* */
Then(
`I should see a text box named {string} and containing {string} disabled`,
function(name: string, expectedTextContent: string) {
findWithRoleAndNameAndContentDisabled("textbox", 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
* */
Then(
`I should see a text box named {string} and containing {string} enabled`,
function(name: string, expectedTextContent: string) {
findWithRoleAndNameAndContentEnabled("textbox", 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 with the disabled attribute set to true
* */
Then(
`I should see a text box named {string} disabled`,
function(name: string) {
findWithRoleAndNameDisabled("textbox", 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 with the disabled attribute set to false
* */
Then(
`I should see a text box named {string} enabled`,
function(name: string) {
findWithRoleAndNameEnabled("textbox", name);
}
);
// End of Content Section
// Begin of Keyboard Section
/**
* 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>
* */
Then(
`I should see a text box named {string} keyboard focused`,
function(name: string) {
findWithRoleAndNameFocused("textbox", name);
}
);
/**
* 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>
* */
Then(
`the previous keyboard element focused should be a text box named {string}`,
function(name: string) {
pressKey("{reverseTab}");
findWithRoleAndNameFocused("textbox", 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>
* */
Then(
`the next keyboard element focused should be a text box named {string}`,
function(name: string) {
pressKey("{tab}");
findWithRoleAndNameFocused("textbox", name);
}
);
// End of Keyboard Section