From dd9f8ca9b48fb3aa5310e911a073c476ffcfa99b Mon Sep 17 00:00:00 2001 From: Louis Fredice NJAKO MOLOM <131726886+luifr10@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:45:50 +0200 Subject: [PATCH] fix: wip --- packages/runner-cypress/e2e/ko.feature | 8 ++++++ packages/runner-cypress/e2e/timeout.feature | 8 ++++++ .../cypress/base-check-engine.ts | 2 +- .../src/cypress/cypress.config.ts | 2 +- .../src/tests/report/report.spec.ts | 9 +++++-- packages/runner-playwright/e2e/ko.feature | 8 ++++++ .../runner-playwright/e2e/timeout.feature | 8 ++++++ .../playwright/base-check-engine.ts | 16 ++++++++---- .../playwright/based-role-check-engine.ts | 5 ++-- .../playwright/core-engine.ts | 25 +++++++++++++++++-- .../src/tests/report/report.spec.ts | 10 ++++++-- 11 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 packages/runner-cypress/e2e/timeout.feature create mode 100644 packages/runner-playwright/e2e/timeout.feature diff --git a/packages/runner-cypress/e2e/ko.feature b/packages/runner-cypress/e2e/ko.feature index 79cede3d2..b3c720b2b 100644 --- a/packages/runner-cypress/e2e/ko.feature +++ b/packages/runner-cypress/e2e/ko.feature @@ -53,3 +53,11 @@ Feature: Ko When I click on element with role "checkbox" and name "Allow automatic update" Then I should see a checkbox named "Allow automatic update" unchecked + @ko + Scenario: click failed with custom timeout + Given I visit path "https://vclock.com/timer/#countdown=00:00:10&enabled=0&seconds=0&title=Online+timer&sound=bells&loop=1" + When I click on button named "Consent" + When I click on button named "Start" + And I set timeout with value 9000 + Then I click on button named "Restart" + diff --git a/packages/runner-cypress/e2e/timeout.feature b/packages/runner-cypress/e2e/timeout.feature new file mode 100644 index 000000000..4d209972d --- /dev/null +++ b/packages/runner-cypress/e2e/timeout.feature @@ -0,0 +1,8 @@ +Feature: Debug + + Scenario: click success with custom timeout + Given I visit path "https://vclock.com/timer/#countdown=00:00:10&enabled=0&seconds=0&title=Online+timer&sound=bells&loop=1" + When I click on button named "Consent" + When I click on button named "Start" + And I set timeout with value 15000 + Then I click on button named "Restart" 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 fd476fa65..0237d5f4a 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 @@ -619,7 +619,7 @@ function click(role: string, name: string) { cy.uuvFindByRole(role, { name: name }).uuvFoundedElement().click(); cy.wrap(new Context()).as("context"); } else { - cy.findByRole(role, { name: name }).click(); + cy.findByRole(role, { name: name, ...context }).click(); } }); } diff --git a/packages/runner-cypress/src/cypress/cypress.config.ts b/packages/runner-cypress/src/cypress/cypress.config.ts index 8553fa801..59c69cfd8 100644 --- a/packages/runner-cypress/src/cypress/cypress.config.ts +++ b/packages/runner-cypress/src/cypress/cypress.config.ts @@ -17,7 +17,7 @@ export async function setupNodeEvents ( await addCucumberPreprocessorPlugin(on, config); - await UUVListenerHelper.build(); + // await UUVListenerHelper.build(); on( "file:preprocessor", diff --git a/packages/runner-cypress/src/tests/report/report.spec.ts b/packages/runner-cypress/src/tests/report/report.spec.ts index 0821d09ba..f4eee0628 100644 --- a/packages/runner-cypress/src/tests/report/report.spec.ts +++ b/packages/runner-cypress/src/tests/report/report.spec.ts @@ -10,8 +10,8 @@ describe("Runner Cypress JunitReport", () => { }); test("Should have good results", () => { - expect(report.testsuites.tests).toEqual("123"); - expect(report.testsuites.failures).toEqual("7"); + expect(report.testsuites.tests).toEqual("125"); + expect(report.testsuites.failures).toEqual("8"); expect(report.testsuites.errors).toBeUndefined(); expect(report.testsuites.skipped).toBeUndefined(); }); @@ -25,4 +25,9 @@ describe("Runner Cypress JunitReport", () => { const testCase = JunitReportHelper.getTestCase(report, "Ko", "Ko TownResearch - Bad textbox name"); expect(testCase?.failure._).toContain("Timed out retrying after 6000ms: Unable to find an accessible element with the role \"textbox\" and name \"Search for a town3\""); }); + + test("Should fail for test : Ko click failed with custom timeout", () => { + const testCase = JunitReportHelper.getTestCase(report, "Ko", "Ko click failed with custom timeout"); + expect(testCase?.failure._).toContain("Timed out retrying after 9000ms: Unable to find an accessible element with the role \"button\" and name \"Restart\""); + }); }); diff --git a/packages/runner-playwright/e2e/ko.feature b/packages/runner-playwright/e2e/ko.feature index 79cede3d2..b3c720b2b 100644 --- a/packages/runner-playwright/e2e/ko.feature +++ b/packages/runner-playwright/e2e/ko.feature @@ -53,3 +53,11 @@ Feature: Ko When I click on element with role "checkbox" and name "Allow automatic update" Then I should see a checkbox named "Allow automatic update" unchecked + @ko + Scenario: click failed with custom timeout + Given I visit path "https://vclock.com/timer/#countdown=00:00:10&enabled=0&seconds=0&title=Online+timer&sound=bells&loop=1" + When I click on button named "Consent" + When I click on button named "Start" + And I set timeout with value 9000 + Then I click on button named "Restart" + diff --git a/packages/runner-playwright/e2e/timeout.feature b/packages/runner-playwright/e2e/timeout.feature new file mode 100644 index 000000000..4d209972d --- /dev/null +++ b/packages/runner-playwright/e2e/timeout.feature @@ -0,0 +1,8 @@ +Feature: Debug + + Scenario: click success with custom timeout + Given I visit path "https://vclock.com/timer/#countdown=00:00:10&enabled=0&seconds=0&title=Online+timer&sound=bells&loop=1" + When I click on button named "Consent" + When I click on button named "Start" + And I set timeout with value 15000 + Then I click on button named "Restart" 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 a1393af0b..4144f5ff8 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 @@ -33,7 +33,9 @@ import { MockCookie, notFoundWithRoleAndName, SelectedElementCookie, - withinRoleAndName + TimeoutCookie, + withinRoleAndName, + getTimeout } from "./core-engine"; import { World } from "../../preprocessor/run/world"; import { ContextObject, RunOptions } from "axe-core"; @@ -115,6 +117,7 @@ When(`${key.when.withinElement.ariaLabel}`, async function(this: World, expected * */ When(`${key.when.resetContext}`, async function(this: World) { await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT); + await deleteCookieByName(this, COOKIE_NAME.TIMEOUT); }); /** @@ -175,7 +178,7 @@ When(`${key.when.keyboard.nextElement}`, async function(this: World) { * key.when.timeout.description * */ When(`${key.when.timeout}`, async function(this: World, newTimeout: number) { - await this.testInfo.setTimeout(newTimeout); + await addCookie(this, COOKIE_NAME.TIMEOUT, new TimeoutCookie("timeout", newTimeout)); }); /** @@ -602,9 +605,12 @@ async function pressKey(world: World, key: string) { async function click(world: World, role: any, name: string) { await getPageOrElement(world).then(async (element) => { - const byRole = element.getByRole(role, { name: name, includeHidden: true, exact: true }); - await expect(byRole).toHaveCount(1); - await byRole.click({ timeout: DEFAULT_TIMEOUT }); + const byRole = element.getByRole(role, { + name: name, + exact: true + }); + await expect(byRole).toHaveCount(1, {timeout: await getTimeout(world)}); + await byRole.click(); await world.page.waitForLoadState(); await deleteCookieByName(world, COOKIE_NAME.SELECTED_ELEMENT); }); diff --git a/packages/runner-playwright/src/cucumber/step_definitions/playwright/based-role-check-engine.ts b/packages/runner-playwright/src/cucumber/step_definitions/playwright/based-role-check-engine.ts index 77d2d1f55..5e8e5f2c8 100644 --- a/packages/runner-playwright/src/cucumber/step_definitions/playwright/based-role-check-engine.ts +++ b/packages/runner-playwright/src/cucumber/step_definitions/playwright/based-role-check-engine.ts @@ -22,6 +22,7 @@ import { findWithRoleAndNameAndContentDisable, findWithRoleAndNameAndContentEnable, findWithRoleAndNameAndUnchecked, findWithRoleAndNameFocused, getPageOrElement, + getTimeout, notFoundWithRoleAndName, withinRoleAndName } from "./core-engine"; @@ -62,8 +63,8 @@ Then( * */ When(`${key.when.type}`, async function(this: World, textToType: string, name: string) { await getPageOrElement(this).then(async (element) => { - const byRole = await element.getByRole("$roleId", { name: name, includeHidden: true, exact: true }); - await expect(byRole).toHaveCount(1); + const byRole = await element.getByRole("$roleId", { name: name, exact: true }); + await expect(byRole).toHaveCount(1, { timeout: await getTimeout(this) }); await byRole.type(textToType); await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT); }); 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 7605005db..a299afbdf 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 @@ -14,11 +14,13 @@ import { World } from "../../preprocessor/run/world"; import { Cookie, expect, Locator as LocatorTest } from "@playwright/test"; +import { DEFAULT_TIMEOUT } from "@uuv/runner-commons"; import { Locator, Page } from "playwright"; export enum COOKIE_NAME { - SELECTED_ELEMENT = "withinFocusedElement", - MOCK_URL = "mockUrl" + TIMEOUT = "uuv.timeout", + SELECTED_ELEMENT = "uuv.withinFocusedElement", + MOCK_URL = "uuv.mockUrl" } export enum COOKIE_VALUE { @@ -64,6 +66,11 @@ export class SelectedElementCookie implements CustomCookieValue { } } +export class TimeoutCookie implements CustomCookieValue { + constructor(public name: string, public value: number) { + } +} + export type FilterType = { name: FILTER_TYPE, value: any } export async function getPageOrElement(world: World): Promise { @@ -124,6 +131,9 @@ export async function addCookie(world: World, cookieName: COOKIE_NAME, newCookie case COOKIE_NAME.SELECTED_ELEMENT: cookieValue.push(newCookie); break; + case COOKIE_NAME.TIMEOUT: + cookieValue.push(newCookie); + break; } await world.context.addCookies([{ name: cookieNameStr, value: JSON.stringify(cookieValue), path: "/", domain: ".github.com" }]); } @@ -272,3 +282,14 @@ export async function checkTextContentLocator(locator: Locator, expectedTextCont } } } + +export async function getTimeout(world: World): Promise { + const cookieTimeout = await getCookie(world, COOKIE_NAME.TIMEOUT); + if (cookieTimeout?.isValid()) { + const timeoutCookies: TimeoutCookie[] = JSON.parse(cookieTimeout.value); + if (timeoutCookies.length > 0) { + return timeoutCookies[0].value; + } + } + return DEFAULT_TIMEOUT; +} diff --git a/packages/runner-playwright/src/tests/report/report.spec.ts b/packages/runner-playwright/src/tests/report/report.spec.ts index 114bd4db9..e36ca2efe 100644 --- a/packages/runner-playwright/src/tests/report/report.spec.ts +++ b/packages/runner-playwright/src/tests/report/report.spec.ts @@ -10,8 +10,8 @@ describe("Runner Playwright JunitReport", () => { }); test("Should have good results", () => { - expect(report.testsuites.tests).toEqual("120"); - expect(report.testsuites.failures).toEqual("7"); + expect(report.testsuites.tests).toEqual("122"); + expect(report.testsuites.failures).toEqual("8"); expect(report.testsuites.errors).toEqual("0"); expect(report.testsuites.skipped).toEqual("0"); }); @@ -32,4 +32,10 @@ describe("Runner Playwright JunitReport", () => { expect(testCase?.failure._).toContain("Error: Timed out 5000ms waiting for expect(locator).toHaveCount(expected)"); expect(testCase?.failure._).toContain("Locator: getByRole('textbox', { name: 'Search for a town3', exact: true, includeHidden: true })"); }); + + test("Should fail for test : Ko click failed with custom timeout", () => { + const testCase = JunitReportHelper.getTestCase(report, "ko.feature.spec.js", "Ko › click failed with custom timeout"); + expect(testCase?.failure._).toContain("Error: Timed out 9000ms waiting for expect(locator).toHaveCount(expected)"); + expect(testCase?.failure._).toContain("Locator: getByRole('button', { name: 'Restart', exact: true })"); + }); });