File tree Expand file tree Collapse file tree 5 files changed +32
-14
lines changed
Fixtures/PlaywrightOnPageLoadTest Expand file tree Collapse file tree 5 files changed +32
-14
lines changed Original file line number Diff line number Diff line change 11import Testing
2+ import JavaScriptKit
23
34@Test func expectToBeTrue( ) async throws {
4- #expect( Bool ( true ) )
5+ let expectToBeTrue = #require( JSObject . global. expectToBeTrue. function)
6+ let result = expectToBeTrue. callAsFunction ( ) . boolean
7+ #expect( result == true )
8+ }
9+
10+ enum TestError : Error {
11+ case nilResult( String )
512}
Original file line number Diff line number Diff line change 11import XCTest
2- // import JavaScriptKit
2+ import JavaScriptKit
33
44final class CheckTests : XCTestCase {
55 func testExpectToBeTrue( ) async throws {
6- // let expectToBeTrue = JSObject.global.expectToBeTrue.function!
7- // let result = await expectToBeTrue().boolean
8- // guard let result else { return XCTFail("expectToBeTrue() returned nil") }
9- // XCTAssertTrue(result)
10- XCTAssertTrue ( true )
6+ guard let expectToBeTrue = JSObject . global. expectToBeTrue. function
7+ else { return XCTFail ( " Function expectToBeTrue not found " ) }
8+ let result = expectToBeTrue ( ) . boolean
9+ guard let result
10+ else { return XCTFail ( " expectToBeTrue() returned nil " ) }
11+ XCTAssertTrue ( result)
1112 }
1213}
Original file line number Diff line number Diff line change @@ -95,7 +95,20 @@ Hint: This typically means that a continuation leak occurred.
9595 }
9696 } ,
9797 browser : async ( { preludeScript } ) => {
98- process . exit ( await testBrowser ( { preludeScript, inspect : args . values . inspect , args : testFrameworkArgs } ) ) ;
98+ const onPageLoad = ( page ) => {
99+ page . exposeFunction ( "expectToBeTrue" , ( ) => {
100+ return true ;
101+ } ) ;
102+ }
103+ const exitCode = await testBrowser ( {
104+ preludeScript,
105+ inspect : args . values . inspect ,
106+ args : testFrameworkArgs ,
107+ playwright : {
108+ onPageLoad
109+ }
110+ } ) ;
111+ process . exit ( exitCode ) ;
99112 }
100113}
101114
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export function testBrowser(
1717 playwright ?: {
1818 browser ?: string ,
1919 launchOptions ?: import ( "playwright" ) . LaunchOptions
20+ onPageLoad ?: ( page : import ( "playwright" ) . Page ) => Promise < void >
2021 }
2122 }
2223) : Promise < number >
Original file line number Diff line number Diff line change @@ -99,12 +99,8 @@ Please run the following command to install it:
9999 const browser = await playwright [ options . playwright ?. browser ?? "chromium" ] . launch ( options . playwright ?. launchOptions ?? { } ) ;
100100 const context = await browser . newContext ( ) ;
101101 const page = await context . newPage ( ) ;
102-
103-
104- // Forward console messages in the page to the Node.js console
105- page . on ( "console" , ( message ) => {
106- console . log ( message . text ( ) ) ;
107- } ) ;
102+ // Allow the user to customize the page before it's loaded, for defining custom export functions
103+ if ( options . playwright ?. onPageLoad ) { await options . playwright . onPageLoad ( page ) ; }
108104
109105 const onExit = new Promise ( ( resolve ) => {
110106 page . exposeFunction ( "exitTest" , resolve ) ;
You can’t perform that action at this time.
0 commit comments