@@ -4,13 +4,14 @@ import {selectors} from '@playwright/test'
4
4
import type {
5
5
Config ,
6
6
LocatorQueries as Queries ,
7
+ Screen ,
7
8
SelectorEngine ,
8
9
SynchronousQuery ,
9
10
Within ,
10
11
} from '../types'
11
12
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'
14
15
15
16
type TestArguments = PlaywrightTestArgs & Config
16
17
@@ -29,6 +30,24 @@ const queriesFixture: TestFixture<Queries, TestArguments> = async (
29
30
use ,
30
31
) => use ( queriesFor ( page , { asyncUtilExpectedState, asyncUtilTimeout} ) )
31
32
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
+
32
51
const withinFixture : TestFixture < Within , TestArguments > = async (
33
52
{ asyncUtilExpectedState, asyncUtilTimeout} ,
34
53
use ,
@@ -117,6 +136,7 @@ export {
117
136
options ,
118
137
queriesFixture ,
119
138
registerSelectorsFixture ,
139
+ screenFixture ,
120
140
withinFixture ,
121
141
}
122
142
export type { Queries }
0 commit comments