Skip to content

Commit 1120a53

Browse files
committed
fix: consider timeout for type and click sentence, #761
1 parent d18d925 commit 1120a53

File tree

12 files changed

+130
-30
lines changed

12 files changed

+130
-30
lines changed

.github/workflows/uuv-github-ci.yml

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ jobs:
4949
with:
5050
distribution: 'temurin'
5151
java-version: '17'
52-
- name: Installing Wine
53-
run: sudo apt-get update -y && sudo apt install wine64
5452
- name: Build artifacts
5553
uses: ./.github/actions/nx-run-many
5654
with:
5755
node-version: ${{env.NODE_VERSION}}
5856
target: "build"
59-
exclude: "runner-flutter"
57+
exclude: "assistant-electron,runner-flutter"
6058
- name: Upload build artifact
6159
uses: actions/upload-artifact@v4
6260
with:
@@ -80,6 +78,39 @@ jobs:
8078
name: github-pages
8179
path: packages/docs/build
8280

81+
build-electron:
82+
runs-on: ubuntu-latest
83+
needs: install
84+
steps:
85+
- uses: actions/checkout@v4
86+
- name: Installing Wine
87+
run: sudo apt-get update -y && sudo apt install wine64
88+
- name: Cache node modules
89+
uses: actions/cache@v4
90+
with:
91+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./package-lock.json') }}
92+
path: |
93+
node_modules
94+
packages/assistant/node_modules
95+
packages/docs/node_modules
96+
packages/a11y/node_modules
97+
packages/runner-commons/node_modules
98+
packages/runner-cypress/node_modules
99+
packages/runner-playwright/node_modules
100+
packages/vscode-extension/node_modules
101+
- name: Use Node.js ${{ inputs.node-version }}
102+
uses: actions/setup-node@v4
103+
with:
104+
node-version: ${{ inputs.node-version }}
105+
- name: Build artifacts
106+
run: npx nx build assistant-electron --verbose
107+
- name: Upload build artifact
108+
uses: actions/upload-artifact@v4
109+
with:
110+
name: build-artifacts-electron
111+
path: |
112+
packages/assistant-electron/dist/uuv-assistant-win32-x64.zip
113+
83114
unit-tests:
84115
runs-on: ubuntu-latest
85116
needs: install
@@ -101,7 +132,7 @@ jobs:
101132

102133
unit-tests-a11y:
103134
runs-on: ubuntu-latest
104-
needs: [ lint, unit-tests, build ]
135+
needs: [ lint, unit-tests, build, build-electron ]
105136
steps:
106137
- uses: actions/checkout@v4
107138
- uses: browser-actions/setup-chrome@v1
@@ -121,7 +152,7 @@ jobs:
121152

122153
integration-tests-assistant:
123154
runs-on: ubuntu-latest
124-
needs: [ lint, unit-tests, build]
155+
needs: [ lint, unit-tests, build, build-electron ]
125156
steps:
126157
- uses: actions/checkout@v4
127158
- name: Running assistant integration tests
@@ -142,7 +173,7 @@ jobs:
142173
runs-on: ubuntu-latest
143174
container:
144175
image: cypress/browsers:node18.12.0-chrome107
145-
needs: [ lint, unit-tests, build ]
176+
needs: [ lint, unit-tests, build, build-electron ]
146177
steps:
147178
- uses: actions/checkout@v4
148179
- name: Running cypress unit tests
@@ -167,7 +198,7 @@ jobs:
167198

168199
unit-tests-playwright:
169200
runs-on: ubuntu-latest
170-
needs: [ lint, unit-tests, build ]
201+
needs: [ lint, unit-tests, build, build-electron ]
171202
steps:
172203
- uses: actions/checkout@v4
173204
- name: Running playwright unit tests
@@ -192,7 +223,7 @@ jobs:
192223

193224
unit-tests-runner-flutter:
194225
runs-on: ubuntu-latest
195-
needs: [ lint, unit-tests, build ]
226+
needs: [ lint, unit-tests, build, build-electron ]
196227
steps:
197228
- uses: actions/checkout@v3
198229
- name: Running runner-flutter unit tests
@@ -206,7 +237,7 @@ jobs:
206237
runs-on: ubuntu-latest
207238
container:
208239
image: e2etesting/uuv
209-
needs: [ lint, unit-tests, build ]
240+
needs: [ lint, unit-tests, build, build-electron ]
210241
steps:
211242
- uses: actions/checkout@v4
212243
- name: Cache node modules
@@ -258,7 +289,7 @@ jobs:
258289
runs-on: ubuntu-latest
259290
container:
260291
image: e2etesting/uuv
261-
needs: [ lint, unit-tests, build ]
292+
needs: [ lint, unit-tests, build, build-electron ]
262293
steps:
263294
- uses: actions/checkout@v4
264295
- name: Cache node modules
@@ -278,8 +309,7 @@ jobs:
278309
uses: actions/download-artifact@v4
279310
with:
280311
name: build-artifacts
281-
path:
282-
packages
312+
path: packages
283313
- run: npm ci
284314
- name: Package runner-playwright
285315
run: mkdir -p ./dist/packages && npx nx package a11y && npx nx package runner-commons && npx nx package runner-playwright
@@ -331,6 +361,11 @@ jobs:
331361
with:
332362
name: build-artifacts
333363
path: packages
364+
- name: Download build electron artifact
365+
uses: actions/download-artifact@v4
366+
with:
367+
name: build-artifacts-electron
368+
path: packages
334369
- name: Release public packages
335370
uses: ./.github/actions/nx-run-many
336371
env:

packages/docs/project.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"a11y",
99
"runner-cypress",
1010
"runner-playwright",
11-
"assistant",
12-
"assistant-electron"
11+
"assistant"
1312
],
1413
"targets": {
1514
"semantic-release": {

packages/runner-cypress/e2e/ko.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ Feature: Ko
5353
When I click on element with role "checkbox" and name "Allow automatic update"
5454
Then I should see a checkbox named "Allow automatic update" unchecked
5555

56+
@ko
57+
Scenario: click failed with custom timeout
58+
Given I visit path "https://e2e-test-quest.github.io/simple-webapp/"
59+
When I click on button named "Start timer"
60+
And I set timeout with value 9000
61+
Then I click on button named "Timer ended"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature: Timeout
2+
3+
Scenario: Click success with custom timeout
4+
Given I visit path "https://e2e-test-quest.github.io/simple-webapp/"
5+
When I click on button named "Start timer"
6+
And I set timeout with value 15000
7+
Then I click on button named "Timer ended"

packages/runner-cypress/src/cucumber/step_definitions/cypress/base-check-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ function click(role: string, name: string) {
619619
cy.uuvFindByRole(role, { name: name }).uuvFoundedElement().click();
620620
cy.wrap(new Context()).as("context");
621621
} else {
622-
cy.findByRole(role, { name: name }).click();
622+
cy.findByRole(role, { name: name, ...context }).click();
623623
}
624624
});
625625
}

packages/runner-cypress/src/tests/report/report.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe("Runner Cypress JunitReport", () => {
1010
});
1111

1212
test("Should have good results", () => {
13-
expect(report.testsuites.tests).toEqual("123");
14-
expect(report.testsuites.failures).toEqual("7");
13+
expect(report.testsuites.tests).toEqual("125");
14+
expect(report.testsuites.failures).toEqual("8");
1515
expect(report.testsuites.errors).toBeUndefined();
1616
expect(report.testsuites.skipped).toBeUndefined();
1717
});
@@ -25,4 +25,9 @@ describe("Runner Cypress JunitReport", () => {
2525
const testCase = JunitReportHelper.getTestCase(report, "Ko", "Ko TownResearch - Bad textbox name");
2626
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\"");
2727
});
28+
29+
test("Should fail for test : Ko click failed with custom timeout", () => {
30+
const testCase = JunitReportHelper.getTestCase(report, "Ko", "Ko click failed with custom timeout");
31+
expect(testCase?.failure._).toContain("Timed out retrying after 9000ms: Unable to find an accessible element with the role \"button\" and name \"Timer ended\"");
32+
});
2833
});

packages/runner-playwright/e2e/ko.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ Feature: Ko
5353
When I click on element with role "checkbox" and name "Allow automatic update"
5454
Then I should see a checkbox named "Allow automatic update" unchecked
5555

56+
@ko
57+
Scenario: click failed with custom timeout
58+
Given I visit path "https://e2e-test-quest.github.io/simple-webapp/"
59+
When I click on button named "Start timer"
60+
And I set timeout with value 9000
61+
Then I click on button named "Timer ended"
62+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature: Timeout
2+
3+
Scenario: click success with custom timeout
4+
Given I visit path "https://e2e-test-quest.github.io/simple-webapp/"
5+
When I click on button named "Start timer"
6+
And I set timeout with value 15000
7+
Then I click on button named "Timer ended"

packages/runner-playwright/src/cucumber/step_definitions/playwright/base-check-engine.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import {
3333
MockCookie,
3434
notFoundWithRoleAndName,
3535
SelectedElementCookie,
36-
withinRoleAndName
36+
TimeoutCookie,
37+
withinRoleAndName,
38+
getTimeout
3739
} from "./core-engine";
3840
import { World } from "../../preprocessor/run/world";
3941
import { ContextObject, RunOptions } from "axe-core";
@@ -115,6 +117,7 @@ When(`${key.when.withinElement.ariaLabel}`, async function(this: World, expected
115117
* */
116118
When(`${key.when.resetContext}`, async function(this: World) {
117119
await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT);
120+
await deleteCookieByName(this, COOKIE_NAME.TIMEOUT);
118121
});
119122

120123
/**
@@ -175,7 +178,7 @@ When(`${key.when.keyboard.nextElement}`, async function(this: World) {
175178
* key.when.timeout.description
176179
* */
177180
When(`${key.when.timeout}`, async function(this: World, newTimeout: number) {
178-
await this.testInfo.setTimeout(newTimeout);
181+
await addCookie(this, COOKIE_NAME.TIMEOUT, new TimeoutCookie("timeout", newTimeout));
179182
});
180183

181184
/**
@@ -602,9 +605,12 @@ async function pressKey(world: World, key: string) {
602605

603606
async function click(world: World, role: any, name: string) {
604607
await getPageOrElement(world).then(async (element) => {
605-
const byRole = element.getByRole(role, { name: name, includeHidden: true, exact: true });
606-
await expect(byRole).toHaveCount(1);
607-
await byRole.click({ timeout: DEFAULT_TIMEOUT });
608+
const byRole = element.getByRole(role, {
609+
name: name,
610+
exact: true
611+
});
612+
await expect(byRole).toHaveCount(1, { timeout: await getTimeout(world) });
613+
await byRole.click();
608614
await world.page.waitForLoadState();
609615
await deleteCookieByName(world, COOKIE_NAME.SELECTED_ELEMENT);
610616
});

packages/runner-playwright/src/cucumber/step_definitions/playwright/based-role-check-engine.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
findWithRoleAndNameAndContentDisable,
2323
findWithRoleAndNameAndContentEnable, findWithRoleAndNameAndUnchecked, findWithRoleAndNameFocused,
2424
getPageOrElement,
25+
getTimeout,
2526
notFoundWithRoleAndName,
2627
withinRoleAndName
2728
} from "./core-engine";
@@ -62,8 +63,8 @@ Then(
6263
* */
6364
When(`${key.when.type}`, async function(this: World, textToType: string, name: string) {
6465
await getPageOrElement(this).then(async (element) => {
65-
const byRole = await element.getByRole("$roleId", { name: name, includeHidden: true, exact: true });
66-
await expect(byRole).toHaveCount(1);
66+
const byRole = await element.getByRole("$roleId", { name: name, exact: true });
67+
await expect(byRole).toHaveCount(1, { timeout: await getTimeout(this) });
6768
await byRole.type(textToType);
6869
await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT);
6970
});

packages/runner-playwright/src/cucumber/step_definitions/playwright/core-engine.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
import { World } from "../../preprocessor/run/world";
1616
import { Cookie, expect, Locator as LocatorTest } from "@playwright/test";
17+
import { DEFAULT_TIMEOUT } from "@uuv/runner-commons";
1718
import { Locator, Page } from "playwright";
1819

1920
export enum COOKIE_NAME {
20-
SELECTED_ELEMENT = "withinFocusedElement",
21-
MOCK_URL = "mockUrl"
21+
TIMEOUT = "uuv.timeout",
22+
SELECTED_ELEMENT = "uuv.withinFocusedElement",
23+
MOCK_URL = "uuv.mockUrl"
2224
}
2325

2426
export enum COOKIE_VALUE {
@@ -64,6 +66,11 @@ export class SelectedElementCookie implements CustomCookieValue {
6466
}
6567
}
6668

69+
export class TimeoutCookie implements CustomCookieValue {
70+
constructor(public name: string, public value: number) {
71+
}
72+
}
73+
6774
export type FilterType = { name: FILTER_TYPE, value: any }
6875

6976
export async function getPageOrElement(world: World): Promise<any> {
@@ -124,6 +131,9 @@ export async function addCookie(world: World, cookieName: COOKIE_NAME, newCookie
124131
case COOKIE_NAME.SELECTED_ELEMENT:
125132
cookieValue.push(newCookie);
126133
break;
134+
case COOKIE_NAME.TIMEOUT:
135+
cookieValue.push(newCookie);
136+
break;
127137
}
128138
await world.context.addCookies([{ name: cookieNameStr, value: JSON.stringify(cookieValue), path: "/", domain: ".github.com" }]);
129139
}
@@ -272,3 +282,14 @@ export async function checkTextContentLocator(locator: Locator, expectedTextCont
272282
}
273283
}
274284
}
285+
286+
export async function getTimeout(world: World): Promise<number> {
287+
const cookieTimeout = await getCookie(world, COOKIE_NAME.TIMEOUT);
288+
if (cookieTimeout?.isValid()) {
289+
const timeoutCookies: TimeoutCookie[] = JSON.parse(cookieTimeout.value);
290+
if (timeoutCookies.length > 0) {
291+
return timeoutCookies[0].value;
292+
}
293+
}
294+
return DEFAULT_TIMEOUT;
295+
}

packages/runner-playwright/src/tests/report/report.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe("Runner Playwright JunitReport", () => {
1010
});
1111

1212
test("Should have good results", () => {
13-
expect(report.testsuites.tests).toEqual("120");
14-
expect(report.testsuites.failures).toEqual("7");
13+
expect(report.testsuites.tests).toEqual("122");
14+
expect(report.testsuites.failures).toEqual("8");
1515
expect(report.testsuites.errors).toEqual("0");
1616
expect(report.testsuites.skipped).toEqual("0");
1717
});
@@ -29,7 +29,13 @@ describe("Runner Playwright JunitReport", () => {
2929

3030
test("Should fail for test : Ko TownResearch - Bad textbox name", () => {
3131
const testCase = JunitReportHelper.getTestCase(report, "ko.feature.spec.js", "Ko › TownResearch - Bad textbox name");
32-
expect(testCase?.failure._).toContain("Error: Timed out 5000ms waiting for expect(locator).toHaveCount(expected)");
33-
expect(testCase?.failure._).toContain("Locator: getByRole('textbox', { name: 'Search for a town3', exact: true, includeHidden: true })");
32+
expect(testCase?.failure._).toContain("Error: Timed out 6000ms waiting for expect(locator).toHaveCount(expected)");
33+
expect(testCase?.failure._).toContain("Locator: getByRole('textbox', { name: 'Search for a town3', exact: true })");
34+
});
35+
36+
test("Should fail for test : Ko click failed with custom timeout", () => {
37+
const testCase = JunitReportHelper.getTestCase(report, "ko.feature.spec.js", "Ko › click failed with custom timeout");
38+
expect(testCase?.failure._).toContain("Error: Timed out 9000ms waiting for expect(locator).toHaveCount(expected)");
39+
expect(testCase?.failure._).toContain("Locator: getByRole('button', { name: 'Timer ended', exact: true })");
3440
});
3541
});

0 commit comments

Comments
 (0)