Skip to content

Commit 50d8bc5

Browse files
Ensure Angular Universal SSR E2Es install and wait correctly
1 parent 0002df4 commit 50d8bc5

File tree

3 files changed

+4484
-61754
lines changed

3 files changed

+4484
-61754
lines changed

playwright-e2e/common/base.ts

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,25 @@ export class BaseMethods {
9494

9595
async checkElementVisibility({ selector, isVisible = true, text, parentSelector }: VisibilityOptions): Promise<void> {
9696
const locator = this.resolveLocator(selector, { parentSelector, text });
97-
const count = await locator.count();
9897

9998
if (isVisible) {
100-
expect(count).toBeGreaterThan(0);
99+
await expect(locator.first()).toBeVisible();
100+
const count = await locator.count();
101101
for (let index = 0; index < count; index++) {
102102
await expect(locator.nth(index)).toBeVisible();
103103
}
104104

105105
return;
106106
}
107107

108-
if (count === 0) {
108+
try {
109+
await expect(locator).toHaveCount(0);
109110
return;
110-
}
111-
112-
for (let index = 0; index < count; index++) {
113-
await expect(locator.nth(index)).not.toBeVisible();
111+
} catch (error) {
112+
const count = await locator.count();
113+
for (let index = 0; index < count; index++) {
114+
await expect(locator.nth(index)).not.toBeVisible();
115+
}
114116
}
115117
}
116118

@@ -127,29 +129,54 @@ export class BaseMethods {
127129
if (isMultiple) {
128130
const baseLocator = this.resolveLocator(selector, { parentSelector });
129131
const filtered = baseLocator.filter({ hasText: text });
130-
const count = await filtered.count();
131-
expect(count).toBeGreaterThan(0);
132-
for (let i = 0; i < count; i++) {
133-
if (visibilityState === 'be.visible') {
132+
133+
if (!isVisible) {
134+
if (notVisibleState === 'not.exist') {
135+
await expect(filtered).toHaveCount(0);
136+
return;
137+
}
138+
139+
const count = await filtered.count();
140+
141+
if (count === 0) {
142+
await expect(filtered).toHaveCount(0);
143+
return;
144+
}
145+
146+
for (let i = 0; i < count; i++) {
147+
await expect(filtered.nth(i)).not.toBeVisible();
148+
}
149+
150+
return;
151+
}
152+
153+
if (visibilityState === 'be.visible') {
154+
await expect(filtered.first()).toBeVisible();
155+
const count = await filtered.count();
156+
for (let i = 0; i < count; i++) {
134157
await expect(filtered.nth(i)).toBeVisible();
135-
} else {
136-
await expect(filtered.nth(i)).toContainText(text);
137158
}
159+
160+
return;
138161
}
139162

163+
await expect(filtered).not.toHaveCount(0);
164+
140165
return;
141166
}
142167

143168
const locator = this.resolveLocator(selector, { parentSelector, text, index });
144-
const count = await locator.count();
145169

146170
if (!isVisible) {
147-
if (count === 0) {
171+
if (notVisibleState === 'not.exist') {
172+
await expect(locator).toHaveCount(0);
148173
return;
149174
}
150175

151-
if (notVisibleState === 'not.exist') {
152-
expect(count).toBe(0);
176+
const count = await locator.count();
177+
178+
if (count === 0) {
179+
await expect(locator).toHaveCount(0);
153180
return;
154181
}
155182

@@ -161,15 +188,16 @@ export class BaseMethods {
161188
}
162189

163190
if (visibilityState === 'be.visible') {
164-
expect(count).toBeGreaterThan(0);
191+
await expect(locator.first()).toBeVisible();
192+
const count = await locator.count();
165193
for (let i = 0; i < count; i++) {
166194
await expect(locator.nth(i)).toBeVisible();
167195
}
168196

169197
return;
170198
}
171199

172-
expect(count).toBeGreaterThan(0);
200+
await expect(locator).not.toHaveCount(0);
173201
}
174202

175203
async clickElementWithText({ selector, text, parentSelector, isTargetChanged = false, index }: ClickWithTextOptions): Promise<void> {
@@ -300,15 +328,15 @@ export class BaseMethods {
300328
}
301329

302330
async checkUrlText(urlPart: string, isInclude: boolean = false): Promise<void> {
303-
const currentUrl = this.page.url();
331+
const poller = expect.poll(() => this.page.url());
304332

305333
if (isInclude) {
306-
expect(currentUrl).toContain(urlPart);
334+
await poller.toContain(urlPart);
307335

308336
return;
309337
}
310338

311-
expect(currentUrl).not.toContain(urlPart);
339+
await poller.not.toContain(urlPart);
312340
}
313341

314342
async compareInfoBetweenHosts(

0 commit comments

Comments
 (0)