diff --git a/packages/runner-cypress/e2e/en-step-definition.feature b/packages/runner-cypress/e2e/en-step-definition.feature index 0a2b4f6c3..66b59e930 100644 --- a/packages/runner-cypress/e2e/en-step-definition.feature +++ b/packages/runner-cypress/e2e/en-step-definition.feature @@ -80,7 +80,7 @@ Feature: English Test Step Definition And within the element with role "textbox" and name "Last name" When I type the sentence "Toto" And I reset context - Then I should see an element with role "textbox" and name "Last name" and content "TotoDoe" + Then I should see an element with role "textbox" and name "Last name" and content "DoeToto" Scenario: key.given.within.selector Then within the element with selector '[data-testid="fieldset"]' diff --git a/packages/runner-cypress/e2e/en-within-and-type.feature b/packages/runner-cypress/e2e/en-within-and-type.feature new file mode 100644 index 000000000..d9067cf78 --- /dev/null +++ b/packages/runner-cypress/e2e/en-within-and-type.feature @@ -0,0 +1,25 @@ +Feature: Within and type + Scenario: key.when.withinElement.withRoleBased and click + Given I visit path "https://e2e-test-quest.github.io/weather-app/?isStarted=true" + And I click on button named "Add new town" + When within the element with selector "#new-town-name" + And I type the sentence "why always me ?" + And I reset context + And I should see a text box named "Town name" and containing "why always me ?" + And within a spin button named "Latitude" + And I enter the value "15" + And I reset context + Then I should see a spin button named "Latitude" and containing "15" + + + Scenario: key.when.withinElement.selector and click + Given I visit path "https://e2e-test-quest.github.io/weather-app/?isStarted=true" + And I click on button named "Add new town" + When within the element with selector "#new-town-name" + And I type the sentence "why always me ?" + And I reset context + And I should see a text box named "Town name" and containing "why always me ?" + And within the element with selector "#new-town-latitude" + And I enter the value "15" + And I reset context + Then I should see a spin button named "Latitude" and containing "15" diff --git a/packages/runner-cypress/e2e/fr-step-definition.feature b/packages/runner-cypress/e2e/fr-step-definition.feature index fe4bd61ca..deb78e82a 100644 --- a/packages/runner-cypress/e2e/fr-step-definition.feature +++ b/packages/runner-cypress/e2e/fr-step-definition.feature @@ -86,7 +86,7 @@ Fonctionnalité: Dictionnaire français de phrases de base utilisant cypress Et je vais à l'intérieur de l'élément ayant pour rôle "textbox" et pour nom "Last name" Quand je saisie les mots "Toto" Et je reinitialise le contexte - Alors je dois voir un élément avec le rôle "textbox" et le nom "Last name" et pour contenu "TotoDoe" + Alors je dois voir un élément avec le rôle "textbox" et le nom "Last name" et pour contenu "DoeToto" Règle: Other Scénario: key.given.within.selector diff --git a/packages/runner-cypress/e2e/fr-within-and-type.feature b/packages/runner-cypress/e2e/fr-within-and-type.feature new file mode 100644 index 000000000..bd1b47a12 --- /dev/null +++ b/packages/runner-cypress/e2e/fr-within-and-type.feature @@ -0,0 +1,27 @@ +#language: fr +Fonctionnalité: Within and type + Scénario: key.when.withinElement.withRoleBased and click + Etant donné que je visite l'Url "https://e2e-test-quest.github.io/weather-app/?isStarted=true" + Et je clique sur le bouton nommé "Add new town" + Quand je vais à l'intérieur de l'élément ayant pour sélecteur "#new-town-name" + Et je saisie les mots "why always me ?" + Et je reinitialise le contexte + Et je dois voir une boîte à texte nommée "Town name" et contenant "why always me ?" + Et je vais à l'intérieur du bouton rotatif nommé "Latitude" + Et j'entre la valeur "15" + Et je reinitialise le contexte + Alors je dois voir un bouton rotatif nommé "Latitude" et contenant "15" + + + Scénario: key.when.withinElement.selector and click + Etant donné que je visite l'Url "https://e2e-test-quest.github.io/weather-app/?isStarted=true" + Et je clique sur le bouton nommé "Add new town" + Quand je vais à l'intérieur de l'élément ayant pour sélecteur "#new-town-name" + Et je saisie les mots "why always me ?" + Et je reinitialise le contexte + Et je dois voir une boîte à texte nommée "Town name" et contenant "why always me ?" + Et je vais à l'intérieur de l'élément ayant pour sélecteur "#new-town-latitude" + Et j'entre la valeur "15" + Et je reinitialise le contexte + Alors je dois voir un bouton rotatif nommé "Latitude" et contenant "15" + diff --git a/packages/runner-cypress/src/cucumber/step_definitions/cypress/_.common.ts b/packages/runner-cypress/src/cucumber/step_definitions/cypress/_.common.ts index a603e91fb..8e63b3f32 100644 --- a/packages/runner-cypress/src/cucumber/step_definitions/cypress/_.common.ts +++ b/packages/runner-cypress/src/cucumber/step_definitions/cypress/_.common.ts @@ -33,10 +33,10 @@ export const uuvGetContext = (): Chainable => { return cy.get(`@${contextAlias}`); }; -export function uuvCheckContextWithinFocusedElement(): Cypress.Chainable { +export function uuvCheckContextWithinFocusedElement(dontThrowError = false): Cypress.Chainable { return cy.get(`@${contextAlias}`) .then(context => { - if (!context.withinFocusedElement) { + if (!context.withinFocusedElement && !dontThrowError) { throw new Error("No element currently selected"); } return context; diff --git a/packages/runner-cypress/src/cucumber/step_definitions/cypress/base-check-engine.ts b/packages/runner-cypress/src/cucumber/step_definitions/cypress/base-check-engine.ts index ff3ddcfaf..6d8bcbc99 100644 --- a/packages/runner-cypress/src/cucumber/step_definitions/cypress/base-check-engine.ts +++ b/packages/runner-cypress/src/cucumber/step_definitions/cypress/base-check-engine.ts @@ -611,12 +611,11 @@ function haveKeyBoardFocused() { } function type(textToType: string) { - if (haveKeyBoardFocused()) { - cy.focused().type(textToType); - } else { - cy.uuvCheckContextWithinFocusedElement().then((context) => { - context.withinFocusedElement!.focus(); - context.withinFocusedElement!.type(textToType); - }); + cy.uuvCheckContextWithinFocusedElement(true).then((context) => { + if (context.withinFocusedElement) { + context.withinFocusedElement!.type(textToType); + } else if (haveKeyBoardFocused()) { + cy.focused().type(textToType); } + }); } diff --git a/packages/runner-cypress/src/cypress/commands.ts b/packages/runner-cypress/src/cypress/commands.ts index 8269be421..b785796d6 100644 --- a/packages/runner-cypress/src/cypress/commands.ts +++ b/packages/runner-cypress/src/cypress/commands.ts @@ -41,7 +41,7 @@ declare global { interface Chainable { uuvGetContext(contextName?: string): Cypress.Chainable; - uuvCheckContextWithinFocusedElement(): Cypress.Chainable; + uuvCheckContextWithinFocusedElement(dontThrowError?: boolean): Cypress.Chainable; uuvCheckContextKeyboardFocusedElement(): Cypress.Chainable; diff --git a/packages/runner-cypress/src/tests/report/report.spec.ts b/packages/runner-cypress/src/tests/report/report.spec.ts index 42742a166..cf83e855a 100644 --- a/packages/runner-cypress/src/tests/report/report.spec.ts +++ b/packages/runner-cypress/src/tests/report/report.spec.ts @@ -10,7 +10,7 @@ describe("Runner Cypress JunitReport", () => { }); test("Should have good results", () => { - expect(report.testsuites.tests).toEqual("110"); + expect(report.testsuites.tests).toEqual("114"); expect(report.testsuites.failures).toEqual("2"); expect(report.testsuites.errors).toBeUndefined(); expect(report.testsuites.skipped).toBeUndefined(); diff --git a/packages/runner-playwright/e2e/en-within-and-type.feature b/packages/runner-playwright/e2e/en-within-and-type.feature new file mode 100644 index 000000000..d9067cf78 --- /dev/null +++ b/packages/runner-playwright/e2e/en-within-and-type.feature @@ -0,0 +1,25 @@ +Feature: Within and type + Scenario: key.when.withinElement.withRoleBased and click + Given I visit path "https://e2e-test-quest.github.io/weather-app/?isStarted=true" + And I click on button named "Add new town" + When within the element with selector "#new-town-name" + And I type the sentence "why always me ?" + And I reset context + And I should see a text box named "Town name" and containing "why always me ?" + And within a spin button named "Latitude" + And I enter the value "15" + And I reset context + Then I should see a spin button named "Latitude" and containing "15" + + + Scenario: key.when.withinElement.selector and click + Given I visit path "https://e2e-test-quest.github.io/weather-app/?isStarted=true" + And I click on button named "Add new town" + When within the element with selector "#new-town-name" + And I type the sentence "why always me ?" + And I reset context + And I should see a text box named "Town name" and containing "why always me ?" + And within the element with selector "#new-town-latitude" + And I enter the value "15" + And I reset context + Then I should see a spin button named "Latitude" and containing "15" diff --git a/packages/runner-playwright/e2e/fr-within-and-type.feature b/packages/runner-playwright/e2e/fr-within-and-type.feature new file mode 100644 index 000000000..bd1b47a12 --- /dev/null +++ b/packages/runner-playwright/e2e/fr-within-and-type.feature @@ -0,0 +1,27 @@ +#language: fr +Fonctionnalité: Within and type + Scénario: key.when.withinElement.withRoleBased and click + Etant donné que je visite l'Url "https://e2e-test-quest.github.io/weather-app/?isStarted=true" + Et je clique sur le bouton nommé "Add new town" + Quand je vais à l'intérieur de l'élément ayant pour sélecteur "#new-town-name" + Et je saisie les mots "why always me ?" + Et je reinitialise le contexte + Et je dois voir une boîte à texte nommée "Town name" et contenant "why always me ?" + Et je vais à l'intérieur du bouton rotatif nommé "Latitude" + Et j'entre la valeur "15" + Et je reinitialise le contexte + Alors je dois voir un bouton rotatif nommé "Latitude" et contenant "15" + + + Scénario: key.when.withinElement.selector and click + Etant donné que je visite l'Url "https://e2e-test-quest.github.io/weather-app/?isStarted=true" + Et je clique sur le bouton nommé "Add new town" + Quand je vais à l'intérieur de l'élément ayant pour sélecteur "#new-town-name" + Et je saisie les mots "why always me ?" + Et je reinitialise le contexte + Et je dois voir une boîte à texte nommée "Town name" et contenant "why always me ?" + Et je vais à l'intérieur de l'élément ayant pour sélecteur "#new-town-latitude" + Et j'entre la valeur "15" + Et je reinitialise le contexte + Alors je dois voir un bouton rotatif nommé "Latitude" et contenant "15" + diff --git a/packages/runner-playwright/src/cucumber/step_definitions/playwright/base-check-engine.ts b/packages/runner-playwright/src/cucumber/step_definitions/playwright/base-check-engine.ts index dd7bd2ed1..479d1901d 100644 --- a/packages/runner-playwright/src/cucumber/step_definitions/playwright/base-check-engine.ts +++ b/packages/runner-playwright/src/cucumber/step_definitions/playwright/base-check-engine.ts @@ -99,7 +99,11 @@ When(`${key.when.click.withRole}`, async function(this: World, role: string, nam * */ When(`${key.when.withinElement.ariaLabel}`, async function(this: World, expectedAriaLabel: string) { const sanitizedExpectedAriaLabel = encodeURIComponent(expectedAriaLabel).replaceAll("%20", " "); - await getPageOrElement(this).then((element) => expect(element.getByLabel(sanitizedExpectedAriaLabel, { exact: true })).toHaveCount(1)); + await getPageOrElement(this).then(async (element) => { + const locator = element.getByLabel(sanitizedExpectedAriaLabel, { exact: true }); + await expect(locator).toHaveCount(1); + await locator.focus({ timeout: 10000 }); + }); await addCookie(this, COOKIE_NAME.SELECTED_ELEMENT, new SelectedElementCookie(FILTER_TYPE.ARIA_LABEL, sanitizedExpectedAriaLabel)); }); @@ -114,6 +118,11 @@ When(`${key.when.resetContext}`, async function(this: World) { * key.when.withinElement.selector.description * */ When(`${key.when.withinElement.selector}`, async function(this: World, selector: string) { + await getPageOrElement(this).then(async (element) => { + const locator = element.locator(selector); + await expect(locator).toHaveCount(1); + await locator.focus({ timeout: 10000 }); + }); await getPageOrElement(this).then((element) => expect(element.locator(selector)).toHaveCount(1)); await addCookie(this, COOKIE_NAME.SELECTED_ELEMENT, new SelectedElementCookie(FILTER_TYPE.SELECTOR, selector)); }); @@ -181,7 +190,11 @@ When(`${key.when.withinElement.roleAndName}`, async function(this: World, role: * */ When(`${key.when.withinElement.testId}`, async function(this: World, testId: string) { testId = encodeURIComponent(testId); - await getPageOrElement(this).then(async (element) => await expect(element.getByTestId(testId)).toHaveCount(1)); + await getPageOrElement(this).then(async (element) => { + const locator = element.getByTestId(testId); + await expect(locator).toHaveCount(1); + await locator.focus({ timeout: 10000 }); + }); await addCookie(this, COOKIE_NAME.SELECTED_ELEMENT, new SelectedElementCookie(FILTER_TYPE.TEST_ID, testId)); }); diff --git a/packages/runner-playwright/src/cucumber/step_definitions/playwright/core-engine.ts b/packages/runner-playwright/src/cucumber/step_definitions/playwright/core-engine.ts index 92a56fa73..4efedbc74 100644 --- a/packages/runner-playwright/src/cucumber/step_definitions/playwright/core-engine.ts +++ b/packages/runner-playwright/src/cucumber/step_definitions/playwright/core-engine.ts @@ -158,7 +158,7 @@ export async function findWithRoleAndName(world: World, role: string, name: stri } export async function withinRoleAndName(world: World, role: string, name: string) { - await findWithRoleAndNameAndContent(world, role, name); + await findWithRoleAndNameAndContent(world, role, name, undefined, true); await addCookie(world, COOKIE_NAME.SELECTED_ELEMENT, new SelectedElementCookie(FILTER_TYPE.SELECTOR, `role=${role}[name="${name}"]`)); } @@ -173,7 +173,7 @@ export async function notFoundWithRoleAndName(world: World, role: string, name: } -export async function findWithRoleAndNameAndContent(world: World, expectedRole: string, name: string, expectedTextContent: string | undefined = undefined): Promise { +export async function findWithRoleAndNameAndContent(world: World, expectedRole: string, name: string, expectedTextContent: string | undefined = undefined, setFocus = false): Promise { expectedRole = encodeURIComponent(expectedRole); await getPageOrElement(world).then(async (element) => { const byRole = await element.getByRole(expectedRole, { name: name, includeHidden: true, exact: true }); @@ -181,6 +181,7 @@ export async function findWithRoleAndNameAndContent(world: World, expectedRole: if (expectedTextContent !== undefined) { await checkTextContentLocator(byRole, expectedTextContent); } + await byRole.focus({ timeout: 10000 }); }); } diff --git a/packages/runner-playwright/src/tests/report/report.spec.ts b/packages/runner-playwright/src/tests/report/report.spec.ts index 75b367110..e63139a6e 100644 --- a/packages/runner-playwright/src/tests/report/report.spec.ts +++ b/packages/runner-playwright/src/tests/report/report.spec.ts @@ -10,7 +10,7 @@ describe("Runner Playwright JunitReport", () => { }); test("Should have good results", () => { - expect(report.testsuites.tests).toEqual("108"); + expect(report.testsuites.tests).toEqual("112"); expect(report.testsuites.failures).toEqual("3"); expect(report.testsuites.errors).toEqual("0"); expect(report.testsuites.skipped).toEqual("0");