@@ -3,7 +3,7 @@ import { Effect } from "effect";
33import { chromium } from "playwright-core" ;
44import { PlaywrightBrowser } from "./browser" ;
55import { PlaywrightEnvironment } from "./experimental" ;
6- import { PlaywrightFrame } from "./frame" ;
6+ import type { PlaywrightFrameService } from "./frame" ;
77
88layer ( PlaywrightEnvironment . layer ( chromium ) ) ( "PlaywrightFrame" , ( it ) => {
99 it . scoped ( "should wrap frame methods" , ( ) =>
@@ -20,41 +20,76 @@ layer(PlaywrightEnvironment.layer(chromium))("PlaywrightFrame", (it) => {
2020 document . body . appendChild ( iframe ) ;
2121 } ) ;
2222
23+ // wait for iframe to load or something. has to be networkidle for some reason
24+ yield * page . waitForLoadState ( "networkidle" ) ;
25+
2326 // Get the frame
24- const frameService = yield * page . use ( async ( p ) => {
25- let frame = p . frames ( ) . find ( ( f ) => f . name ( ) === "test-frame" ) ;
26- if ( ! frame ) {
27- // Wait a bit if not found immediately (though srcdoc is sync-ish, iframe loading is async)
28- await p . waitForLoadState ( "networkidle" ) ;
29- frame = p . frames ( ) . find ( ( f ) => f . name ( ) === "test-frame" ) ;
30- }
31- if ( ! frame ) throw new Error ( "Frame not found" ) ;
32- return PlaywrightFrame . make ( frame ) ;
33- } ) ;
27+ const frames = yield * page . frames ;
28+
29+ const isTestFrame = ( f : PlaywrightFrameService ) =>
30+ f . name . pipe ( Effect . map ( ( n ) => n === "test-frame" ) ) ;
31+
32+ const frame = yield * Effect . findFirst ( frames , isTestFrame ) . pipe (
33+ Effect . flatten ,
34+ Effect . retry ( {
35+ times : 3 ,
36+ } ) ,
37+ ) ;
38+
39+ assert . isOk ( frame , "Frame not found" ) ;
3440
3541 // Test title
36- const title = yield * frameService . title ;
42+ const title = yield * frame . title ;
3743 assert . strictEqual ( title , "Frame Title" ) ;
3844
3945 // Test content
40- const content = yield * frameService . content ;
46+ const content = yield * frame . content ;
4147 assert . isTrue ( content . includes ( "Hello from Frame" ) ) ;
4248
4349 // Test evaluate
44- const result = yield * frameService . evaluate ( ( ) => 1 + 1 ) ;
50+ const result = yield * frame . evaluate ( ( ) => 1 + 1 ) ;
4551 assert . strictEqual ( result , 2 ) ;
4652
4753 // Test locator
48- const text = yield * frameService . locator ( "#target" ) . textContent ( ) ;
54+ const text = yield * frame . locator ( "#target" ) . textContent ( ) ;
4955 assert . strictEqual ( text , "Hello from Frame" ) ;
5056
5157 // Test getByText
52- const byText = yield * frameService . getByText ( "Hello from Frame" ) . count ;
58+ const byText = yield * frame . getByText ( "Hello from Frame" ) . count ;
5359 assert . strictEqual ( byText , 1 ) ;
5460
5561 // Test name
56- const name = yield * frameService . name ;
62+ const name = yield * frame . name ;
5763 assert . strictEqual ( name , "test-frame" ) ;
5864 } ) . pipe ( PlaywrightEnvironment . withBrowser ) ,
5965 ) ;
66+
67+ it . scoped ( "waitForLoadState should resolve on frame" , ( ) =>
68+ Effect . gen ( function * ( ) {
69+ const browser = yield * PlaywrightBrowser ;
70+ const page = yield * browser . newPage ( ) ;
71+
72+ // Load a page that already has an iframe
73+ yield * page . goto (
74+ "data:text/html,<html><body><iframe name='test-frame' src='about:blank'></iframe></body></html>" ,
75+ ) ;
76+
77+ // Wait for the main page to settle
78+ yield * page . waitForLoadState ( "load" ) ;
79+
80+ // Get the frame - it should be there now
81+ // Get the frame - it should be there now
82+ const frames = yield * page . frames ;
83+ const frameService = frames . find ( ( f ) =>
84+ Effect . runSync ( f . name . pipe ( Effect . map ( ( n ) => n === "test-frame" ) ) ) ,
85+ ) ;
86+
87+ assert . isOk ( frameService , "Frame not found" ) ;
88+
89+ // Wait for 'load' state on the frame
90+ yield * frameService . waitForLoadState ( "load" ) ;
91+
92+ assert . ok ( true ) ;
93+ } ) . pipe ( PlaywrightEnvironment . withBrowser ) ,
94+ ) ;
6095} ) ;
0 commit comments