Skip to content

Commit 77e9148

Browse files
committed
add failing tests
1 parent c24e29c commit 77e9148

File tree

1 file changed

+215
-0
lines changed

1 file changed

+215
-0
lines changed
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
import { test, expect } from "@playwright/test";
2+
import { V3 } from "../v3";
3+
import { v3TestConfig } from "./v3.config";
4+
import { V3Context } from "../understudy/context";
5+
6+
// TODO: mark as unskipped once we have a fix
7+
test.describe.skip("context.addInitScript with iframes", () => {
8+
let v3: V3;
9+
let ctx: V3Context;
10+
11+
test.beforeEach(async () => {
12+
v3 = new V3(v3TestConfig);
13+
await v3.init();
14+
ctx = v3.context;
15+
16+
// Add init script that sets background to red
17+
await ctx.addInitScript(`
18+
(() => {
19+
document.addEventListener('DOMContentLoaded', () => {
20+
document.documentElement.style.backgroundColor = 'red';
21+
});
22+
})();
23+
`);
24+
});
25+
26+
test.afterEach(async () => {
27+
await v3?.close?.().catch(() => {});
28+
});
29+
30+
test.describe("direct navigation", () => {
31+
test("with OOPIF - sets background red in main page and iframe", async () => {
32+
const page = await ctx.awaitActivePage();
33+
34+
await page.goto(
35+
"https://browserbase.github.io/stagehand-eval-sites/sites/oopif-in-closed-shadow-dom/",
36+
{ waitUntil: "networkidle" },
37+
);
38+
39+
// Wait for iframe to load
40+
await new Promise((resolve) => setTimeout(resolve, 1000));
41+
42+
// Check main page background
43+
const mainBgColor = await page.mainFrame().evaluate(() => {
44+
return getComputedStyle(document.documentElement).backgroundColor;
45+
});
46+
expect(mainBgColor).toBe("rgb(255, 0, 0)");
47+
48+
// Check iframe background - find the child frame (not main frame)
49+
const frames = page.frames();
50+
const iframe = frames.find((f) => f !== page.mainFrame());
51+
expect(iframe).toBeDefined();
52+
53+
const iframeBgColor = await iframe!.evaluate(() => {
54+
return getComputedStyle(document.documentElement).backgroundColor;
55+
});
56+
expect(iframeBgColor).toBe("rgb(255, 0, 0)");
57+
});
58+
59+
test("with SPIF - sets background red in main page and iframe", async () => {
60+
const page = await ctx.awaitActivePage();
61+
62+
await page.goto(
63+
"https://browserbase.github.io/stagehand-eval-sites/sites/spif-in-closed-shadow-dom/",
64+
{ waitUntil: "networkidle" },
65+
);
66+
67+
// Wait for iframe to load
68+
await new Promise((resolve) => setTimeout(resolve, 1000));
69+
70+
// Check main page background
71+
const mainBgColor = await page.mainFrame().evaluate(() => {
72+
return getComputedStyle(document.documentElement).backgroundColor;
73+
});
74+
expect(mainBgColor).toBe("rgb(255, 0, 0)");
75+
76+
// Check iframe background - find the child frame (not main frame)
77+
const frames = page.frames();
78+
const iframe = frames.find((f) => f !== page.mainFrame());
79+
expect(iframe).toBeDefined();
80+
81+
const iframeBgColor = await iframe!.evaluate(() => {
82+
return getComputedStyle(document.documentElement).backgroundColor;
83+
});
84+
expect(iframeBgColor).toBe("rgb(255, 0, 0)");
85+
});
86+
});
87+
88+
test.describe("via newPage", () => {
89+
test("with OOPIF - sets background red in main page and iframe", async () => {
90+
const page = await ctx.newPage();
91+
92+
await page.goto(
93+
"https://browserbase.github.io/stagehand-eval-sites/sites/oopif-in-closed-shadow-dom/",
94+
{ waitUntil: "networkidle" },
95+
);
96+
97+
// Wait for iframe to load
98+
await new Promise((resolve) => setTimeout(resolve, 1000));
99+
100+
// Check main page background
101+
const mainBgColor = await page.mainFrame().evaluate(() => {
102+
return getComputedStyle(document.documentElement).backgroundColor;
103+
});
104+
expect(mainBgColor).toBe("rgb(255, 0, 0)");
105+
106+
// Check iframe background - find the child frame (not main frame)
107+
const frames = page.frames();
108+
const iframe = frames.find((f) => f !== page.mainFrame());
109+
expect(iframe).toBeDefined();
110+
111+
const iframeBgColor = await iframe!.evaluate(() => {
112+
return getComputedStyle(document.documentElement).backgroundColor;
113+
});
114+
expect(iframeBgColor).toBe("rgb(255, 0, 0)");
115+
});
116+
117+
test("with SPIF - sets background red in main page and iframe", async () => {
118+
const page = await ctx.newPage();
119+
120+
await page.goto(
121+
"https://browserbase.github.io/stagehand-eval-sites/sites/spif-in-closed-shadow-dom/",
122+
{ waitUntil: "networkidle" },
123+
);
124+
125+
// Wait for iframe to load
126+
await new Promise((resolve) => setTimeout(resolve, 1000));
127+
128+
// Check main page background
129+
const mainBgColor = await page.mainFrame().evaluate(() => {
130+
return getComputedStyle(document.documentElement).backgroundColor;
131+
});
132+
expect(mainBgColor).toBe("rgb(255, 0, 0)");
133+
134+
// Check iframe background - find the child frame (not main frame)
135+
const frames = page.frames();
136+
const iframe = frames.find((f) => f !== page.mainFrame());
137+
expect(iframe).toBeDefined();
138+
139+
const iframeBgColor = await iframe!.evaluate(() => {
140+
return getComputedStyle(document.documentElement).backgroundColor;
141+
});
142+
expect(iframeBgColor).toBe("rgb(255, 0, 0)");
143+
});
144+
});
145+
146+
test.describe("via popup", () => {
147+
test("with OOPIF - sets background red in main page and iframe", async () => {
148+
const page = await ctx.awaitActivePage();
149+
150+
await page.goto(
151+
"https://browserbase.github.io/stagehand-eval-sites/sites/ctx-add-init-script-oopif/",
152+
{ waitUntil: "networkidle" },
153+
);
154+
155+
// Click link to open popup
156+
await page.locator("a").click();
157+
158+
// Wait for popup to open and become active
159+
const popup = await ctx.awaitActivePage();
160+
161+
// Wait for iframe to load in popup
162+
await new Promise((resolve) => setTimeout(resolve, 1000));
163+
164+
// Check popup main page background
165+
const mainBgColor = await popup.mainFrame().evaluate(() => {
166+
return getComputedStyle(document.documentElement).backgroundColor;
167+
});
168+
expect(mainBgColor).toBe("rgb(255, 0, 0)");
169+
170+
// Check iframe background in popup - find the child frame (not main frame)
171+
const frames = popup.frames();
172+
const iframe = frames.find((f) => f !== popup.mainFrame());
173+
expect(iframe).toBeDefined();
174+
175+
const iframeBgColor = await iframe!.evaluate(() => {
176+
return getComputedStyle(document.documentElement).backgroundColor;
177+
});
178+
expect(iframeBgColor).toBe("rgb(255, 0, 0)");
179+
});
180+
181+
test("with SPIF - sets background red in main page and iframe", async () => {
182+
const page = await ctx.awaitActivePage();
183+
184+
await page.goto(
185+
"https://browserbase.github.io/stagehand-eval-sites/sites/ctx-add-init-script-spif/",
186+
{ waitUntil: "networkidle" },
187+
);
188+
189+
// Click link to open popup
190+
await page.locator("a").click();
191+
192+
// Wait for popup to open and become active
193+
const popup = await ctx.awaitActivePage();
194+
195+
// Wait for iframe to load in popup
196+
await new Promise((resolve) => setTimeout(resolve, 1000));
197+
198+
// Check popup main page background
199+
const mainBgColor = await popup.mainFrame().evaluate(() => {
200+
return getComputedStyle(document.documentElement).backgroundColor;
201+
});
202+
expect(mainBgColor).toBe("rgb(255, 0, 0)");
203+
204+
// Check iframe background in popup - find the child frame (not main frame)
205+
const frames = popup.frames();
206+
const iframe = frames.find((f) => f !== popup.mainFrame());
207+
expect(iframe).toBeDefined();
208+
209+
const iframeBgColor = await iframe!.evaluate(() => {
210+
return getComputedStyle(document.documentElement).backgroundColor;
211+
});
212+
expect(iframeBgColor).toBe("rgb(255, 0, 0)");
213+
});
214+
});
215+
});

0 commit comments

Comments
 (0)