Skip to content

fix: consider timeout for type and click sentence, #761 #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 47 additions & 12 deletions .github/workflows/uuv-github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ jobs:
with:
distribution: 'temurin'
java-version: '17'
- name: Installing Wine
run: sudo apt-get update -y && sudo apt install wine64
- name: Build artifacts
uses: ./.github/actions/nx-run-many
with:
node-version: ${{env.NODE_VERSION}}
target: "build"
exclude: "runner-flutter"
exclude: "assistant-electron,runner-flutter"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -80,6 +78,39 @@ jobs:
name: github-pages
path: packages/docs/build

build-electron:
runs-on: ubuntu-latest
needs: install
steps:
- uses: actions/checkout@v4
- name: Installing Wine
run: sudo apt-get update -y && sudo apt install wine64
- name: Cache node modules
uses: actions/cache@v4
with:
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./package-lock.json') }}
path: |
node_modules
packages/assistant/node_modules
packages/docs/node_modules
packages/a11y/node_modules
packages/runner-commons/node_modules
packages/runner-cypress/node_modules
packages/runner-playwright/node_modules
packages/vscode-extension/node_modules
- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- name: Build artifacts
run: npx nx build assistant-electron --verbose
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build-artifacts-electron
path: |
packages/assistant-electron/dist/uuv-assistant-win32-x64.zip

unit-tests:
runs-on: ubuntu-latest
needs: install
Expand All @@ -101,7 +132,7 @@ jobs:

unit-tests-a11y:
runs-on: ubuntu-latest
needs: [ lint, unit-tests, build ]
needs: [ lint, unit-tests, build, build-electron ]
steps:
- uses: actions/checkout@v4
- uses: browser-actions/setup-chrome@v1
Expand All @@ -121,7 +152,7 @@ jobs:

integration-tests-assistant:
runs-on: ubuntu-latest
needs: [ lint, unit-tests, build]
needs: [ lint, unit-tests, build, build-electron ]
steps:
- uses: actions/checkout@v4
- name: Running assistant integration tests
Expand All @@ -142,7 +173,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: cypress/browsers:node18.12.0-chrome107
needs: [ lint, unit-tests, build ]
needs: [ lint, unit-tests, build, build-electron ]
steps:
- uses: actions/checkout@v4
- name: Running cypress unit tests
Expand All @@ -167,7 +198,7 @@ jobs:

unit-tests-playwright:
runs-on: ubuntu-latest
needs: [ lint, unit-tests, build ]
needs: [ lint, unit-tests, build, build-electron ]
steps:
- uses: actions/checkout@v4
- name: Running playwright unit tests
Expand All @@ -192,7 +223,7 @@ jobs:

unit-tests-runner-flutter:
runs-on: ubuntu-latest
needs: [ lint, unit-tests, build ]
needs: [ lint, unit-tests, build, build-electron ]
steps:
- uses: actions/checkout@v3
- name: Running runner-flutter unit tests
Expand All @@ -206,7 +237,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: e2etesting/uuv
needs: [ lint, unit-tests, build ]
needs: [ lint, unit-tests, build, build-electron ]
steps:
- uses: actions/checkout@v4
- name: Cache node modules
Expand Down Expand Up @@ -258,7 +289,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: e2etesting/uuv
needs: [ lint, unit-tests, build ]
needs: [ lint, unit-tests, build, build-electron ]
steps:
- uses: actions/checkout@v4
- name: Cache node modules
Expand All @@ -278,8 +309,7 @@ jobs:
uses: actions/download-artifact@v4
with:
name: build-artifacts
path:
packages
path: packages
- run: npm ci
- name: Package runner-playwright
run: mkdir -p ./dist/packages && npx nx package a11y && npx nx package runner-commons && npx nx package runner-playwright
Expand Down Expand Up @@ -331,6 +361,11 @@ jobs:
with:
name: build-artifacts
path: packages
- name: Download build electron artifact
uses: actions/download-artifact@v4
with:
name: build-artifacts-electron
path: packages
- name: Release public packages
uses: ./.github/actions/nx-run-many
env:
Expand Down
3 changes: 1 addition & 2 deletions packages/docs/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"a11y",
"runner-cypress",
"runner-playwright",
"assistant",
"assistant-electron"
"assistant"
],
"targets": {
"semantic-release": {
Expand Down
6 changes: 6 additions & 0 deletions packages/runner-cypress/e2e/ko.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ 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://e2e-test-quest.github.io/simple-webapp/"
When I click on button named "Start timer"
And I set timeout with value 9000
Then I click on button named "Timer ended"
7 changes: 7 additions & 0 deletions packages/runner-cypress/e2e/timeout.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Timeout

Scenario: Click success with custom timeout
Given I visit path "https://e2e-test-quest.github.io/simple-webapp/"
When I click on button named "Start timer"
And I set timeout with value 15000
Then I click on button named "Timer ended"
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
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 \"Timer ended\"");
});
});
7 changes: 7 additions & 0 deletions packages/runner-playwright/e2e/ko.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ 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://e2e-test-quest.github.io/simple-webapp/"
When I click on button named "Start timer"
And I set timeout with value 9000
Then I click on button named "Timer ended"

7 changes: 7 additions & 0 deletions packages/runner-playwright/e2e/timeout.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Timeout

Scenario: click success with custom timeout
Given I visit path "https://e2e-test-quest.github.io/simple-webapp/"
When I click on button named "Start timer"
And I set timeout with value 15000
Then I click on button named "Timer ended"
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;
}
14 changes: 10 additions & 4 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 @@ -29,7 +29,13 @@ describe("Runner Playwright JunitReport", () => {

test("Should fail for test : Ko TownResearch - Bad textbox name", () => {
const testCase = JunitReportHelper.getTestCase(report, "ko.feature.spec.js", "Ko › TownResearch - Bad textbox name");
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 })");
expect(testCase?.failure._).toContain("Error: Timed out 6000ms waiting for expect(locator).toHaveCount(expected)");
expect(testCase?.failure._).toContain("Locator: getByRole('textbox', { name: 'Search for a town3', exact: 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: 'Timer ended', exact: true })");
});
});
Loading