@@ -2,11 +2,14 @@ import { TestRunnerPlugin } from '@web/test-runner-core';
2
2
import type { ChromeLauncher } from '@web/test-runner-chrome' ;
3
3
import type { PlaywrightLauncher } from '@web/test-runner-playwright' ;
4
4
5
- type SelectByValuePayload = { selector : string , value : string } ;
6
- type SelectByLabelPayload = { selector : string , label : string } ;
7
- type SelectMultipleValuesPayload = { selector : string , values : string [ ] } ;
5
+ type SelectByValuePayload = { selector : string ; value : string } ;
6
+ type SelectByLabelPayload = { selector : string ; label : string } ;
7
+ type SelectMultipleValuesPayload = { selector : string ; values : string [ ] } ;
8
8
9
- export type SelectOptionPayload = SelectByLabelPayload | SelectByValuePayload | SelectMultipleValuesPayload ;
9
+ export type SelectOptionPayload =
10
+ | SelectByLabelPayload
11
+ | SelectByValuePayload
12
+ | SelectMultipleValuesPayload ;
10
13
11
14
function isObject ( payload : unknown ) : payload is Record < string , unknown > {
12
15
return payload != null && typeof payload === 'object' ;
@@ -17,14 +20,16 @@ function isSelectOptionPayload(payload: unknown): boolean {
17
20
18
21
if ( ! isObject ( payload ) ) throw new Error ( 'You must provide a `SelectOptionPayload` object' ) ;
19
22
20
- if ( ! payload . selector || typeof payload . selector !== 'string' ) {
23
+ if ( ! payload . selector || typeof payload . selector !== 'string' ) {
21
24
throw new Error ( `You must provide a selector representing the select you wish to locate` ) ;
22
25
}
23
26
24
27
const numberOfValidOptions = Object . keys ( payload ) . filter ( key =>
25
28
validOptions . includes ( key ) ,
26
29
) . length ;
27
- const unknownOptions = Object . keys ( payload ) . filter ( key => ! [ ...validOptions , 'selector' ] . includes ( key ) ) ;
30
+ const unknownOptions = Object . keys ( payload ) . filter (
31
+ key => ! [ ...validOptions , 'selector' ] . includes ( key ) ,
32
+ ) ;
28
33
29
34
if ( numberOfValidOptions === 0 )
30
35
throw new Error (
@@ -43,14 +48,13 @@ function isValuePayload(payload: SelectOptionPayload): payload is SelectByValueP
43
48
}
44
49
45
50
function isLabelPayload ( payload : SelectOptionPayload ) : payload is SelectByLabelPayload {
46
- return 'selector' in payload && 'label' in payload ;
51
+ return 'selector' in payload && 'label' in payload ;
47
52
}
48
53
49
54
function isMultiplePayload ( payload : SelectOptionPayload ) : payload is SelectMultipleValuesPayload {
50
- return 'selector' in payload && 'values' in payload ;
55
+ return 'selector' in payload && 'values' in payload ;
51
56
}
52
57
53
-
54
58
export function selectOptionPlugin ( ) : TestRunnerPlugin < SelectOptionPayload > {
55
59
return {
56
60
name : 'select-option-command' ,
@@ -72,7 +76,7 @@ export function selectOptionPlugin(): TestRunnerPlugin<SelectOptionPayload> {
72
76
return true ;
73
77
} else if ( isMultiplePayload ( payload ) ) {
74
78
const { selector, values } = payload ;
75
- await page . locator ( selector ) . selectOption ( [ ...values ] ) ;
79
+ await page . locator ( selector ) . selectOption ( [ ...values ] ) ;
76
80
return true ;
77
81
}
78
82
}
@@ -91,13 +95,13 @@ export function selectOptionPlugin(): TestRunnerPlugin<SelectOptionPayload> {
91
95
} else {
92
96
throw new Error ( `Puppeteer only supports selection of an option by its value(s):
93
97
https://pptr.dev/next/api/puppeteer.page.select#parameters
94
- ` )
98
+ ` ) ;
95
99
}
96
100
}
97
101
98
102
// handle specific behavior for webdriver
99
- if ( session . browser . type === 'webdriver' ) {
100
- throw new Error ( `Selecting an option via a browser driver command is not currently implemented in WebDriver yet.
103
+ if ( session . browser . type === 'webdriver' ) {
104
+ throw new Error ( `Selecting an option via a browser driver command is not currently implemented in WebDriver yet.
101
105
https://www.selenium.dev/documentation/webdriver/elements/select_lists/
102
106
103
107
When using WebDriver, the current recommended (September 2022) approach is to:
@@ -109,7 +113,9 @@ export function selectOptionPlugin(): TestRunnerPlugin<SelectOptionPayload> {
109
113
}
110
114
111
115
// you might not be able to support all browser launchers
112
- throw new Error ( `Selection of select element options is not supported for browser type ${ session . browser . type } .` ) ;
116
+ throw new Error (
117
+ `Selection of select element options is not supported for browser type ${ session . browser . type } .` ,
118
+ ) ;
113
119
}
114
120
} ,
115
121
} ;
0 commit comments