Skip to content

Commit

Permalink
fix: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luifr10 committed Aug 29, 2024
1 parent d18d925 commit dd9f8ca
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 15 deletions.
8 changes: 8 additions & 0 deletions packages/runner-cypress/e2e/ko.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

8 changes: 8 additions & 0 deletions packages/runner-cypress/e2e/timeout.feature
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runner-cypress/src/cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function setupNodeEvents (

await addCucumberPreprocessorPlugin(on, config);

await UUVListenerHelper.build();
// await UUVListenerHelper.build();

on(
"file:preprocessor",
Expand Down
9 changes: 7 additions & 2 deletions packages/runner-cypress/src/tests/report/report.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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\"");
});
});
8 changes: 8 additions & 0 deletions packages/runner-playwright/e2e/ko.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

8 changes: 8 additions & 0 deletions packages/runner-playwright/e2e/timeout.feature
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
});

/**
Expand Down Expand Up @@ -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));
});

/**
Expand Down Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
findWithRoleAndNameAndContentDisable,
findWithRoleAndNameAndContentEnable, findWithRoleAndNameAndUnchecked, findWithRoleAndNameFocused,
getPageOrElement,
getTimeout,
notFoundWithRoleAndName,
withinRoleAndName
} from "./core-engine";
Expand Down Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<any> {
Expand Down Expand Up @@ -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" }]);
}
Expand Down Expand Up @@ -272,3 +282,14 @@ export async function checkTextContentLocator(locator: Locator, expectedTextCont
}
}
}

export async function getTimeout(world: World): Promise<number> {
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;
}
10 changes: 8 additions & 2 deletions packages/runner-playwright/src/tests/report/report.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand All @@ -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 })");
});
});

0 comments on commit dd9f8ca

Please sign in to comment.