Skip to content

Commit 5a88610

Browse files
committed
build: test webdriver
Tries to deflake the Webdriver test by not waiting for Angular to stabilize.
1 parent b5c68e9 commit 5a88610

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/cdk/testing/tests/webdriver.e2e.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ declare const kagekiri: {
4040
describe('WebDriverHarnessEnvironment', () => {
4141
let wd: webdriver.WebDriver;
4242

43-
async function getUrl(path: string) {
44-
await wd.get(`http://localhost:${port}${path}`);
45-
await waitForAngularReady(wd);
46-
}
47-
4843
async function piercingQueryFn(selector: string, root: () => webdriver.WebElement) {
4944
return wd.findElements(
5045
webdriver.By.js((s: string, r: Element) => kagekiri.querySelectorAll(s, r), selector, root()),
@@ -60,15 +55,20 @@ describe('WebDriverHarnessEnvironment', () => {
6055
.usingServer(process.env['WEB_TEST_WEBDRIVER_SERVER']!)
6156
.withCapabilities(webTestMetadata.capabilities)
6257
.build();
63-
await wd.manage().timeouts().implicitlyWait(0);
64-
});
6558

66-
afterAll(async () => {
67-
await wd.quit();
59+
// Ideally we would refresh the page and wait for Angular to stabilize on each test.
60+
// We don't do it, because it causes Webdriver to eventually time out. Instead we go to
61+
// the page once and reset the component state before the test (see `beforeEach` below).
62+
await wd.get(`http://localhost:${port}/component-harness`);
63+
await waitForAngularReady(wd);
6864
});
6965

7066
beforeEach(async () => {
71-
await getUrl('/component-harness');
67+
await wd.findElement({id: 'reset-state'}).click();
68+
});
69+
70+
afterAll(async () => {
71+
await wd.quit();
7272
});
7373

7474
describe('environment specific', () => {

src/e2e-app/components/component-harness-e2e.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@ import {TestMainComponent} from '@angular/cdk/testing/tests';
33

44
@Component({
55
selector: 'component-harness-e2e',
6-
template: `<test-main></test-main>`,
6+
template: `
7+
<button id="reset-state" (click)="reset()">Reset state</button>
8+
9+
@if (isShown) {
10+
<test-main></test-main>
11+
}
12+
`,
713
encapsulation: ViewEncapsulation.None,
814
changeDetection: ChangeDetectionStrategy.OnPush,
915
standalone: true,
1016
imports: [TestMainComponent],
1117
})
12-
export class ComponentHarnessE2e {}
18+
export class ComponentHarnessE2e {
19+
protected isShown = true;
20+
21+
/**
22+
* Resets the test component state without the need to refresh the page.
23+
* Used by Webdriver integration tests.
24+
*/
25+
protected reset(): void {
26+
this.isShown = false;
27+
setTimeout(() => (this.isShown = true), 100);
28+
}
29+
}

src/e2e-app/components/e2e-app/e2e-app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {Component, ViewEncapsulation} from '@angular/core';
2-
import {NgFor, NgIf} from '@angular/common';
32
import {MatListModule} from '@angular/material/list';
43
import {RouterLink, RouterOutlet} from '@angular/router';
54

@@ -8,7 +7,7 @@ import {RouterLink, RouterOutlet} from '@angular/router';
87
templateUrl: 'e2e-app.html',
98
encapsulation: ViewEncapsulation.None,
109
standalone: true,
11-
imports: [MatListModule, NgIf, NgFor, RouterLink, RouterOutlet],
10+
imports: [MatListModule, RouterLink, RouterOutlet],
1211
})
1312
export class E2eApp {
1413
showLinks = false;

0 commit comments

Comments
 (0)