@@ -4,13 +4,14 @@ import {selectors} from '@playwright/test'
44import type {
55 Config ,
66 LocatorQueries as Queries ,
7+ Screen ,
78 SelectorEngine ,
89 SynchronousQuery ,
910 Within ,
1011} from '../types'
1112
12- import { buildTestingLibraryScript , queryToSelector } from './helpers'
13- import { isAllQuery , queriesFor , synchronousQueryNames } from './queries'
13+ import { buildTestingLibraryScript , includes , queryToSelector } from './helpers'
14+ import { allQueryNames , isAllQuery , queriesFor , synchronousQueryNames } from './queries'
1415
1516type TestArguments = PlaywrightTestArgs & Config
1617
@@ -29,6 +30,24 @@ const queriesFixture: TestFixture<Queries, TestArguments> = async (
2930 use ,
3031) => use ( queriesFor ( page , { asyncUtilExpectedState, asyncUtilTimeout} ) )
3132
33+ const screenFixture : TestFixture < Screen , TestArguments > = async (
34+ { page, asyncUtilExpectedState, asyncUtilTimeout} ,
35+ use ,
36+ ) => {
37+ const queries = queriesFor ( page , { asyncUtilExpectedState, asyncUtilTimeout} )
38+ const revocable = Proxy . revocable ( page , {
39+ get ( target , property , receiver ) {
40+ return includes ( allQueryNames , property )
41+ ? queries [ property ]
42+ : Reflect . get ( target , property , receiver )
43+ } ,
44+ } )
45+
46+ await use ( revocable . proxy as Screen )
47+
48+ revocable . revoke ( )
49+ }
50+
3251const withinFixture : TestFixture < Within , TestArguments > = async (
3352 { asyncUtilExpectedState, asyncUtilTimeout} ,
3453 use ,
@@ -117,6 +136,7 @@ export {
117136 options ,
118137 queriesFixture ,
119138 registerSelectorsFixture ,
139+ screenFixture ,
120140 withinFixture ,
121141}
122142export type { Queries }
0 commit comments