@@ -5,17 +5,10 @@ import {assert} from 'chai';
55import type { ElementHandle } from 'puppeteer-core' ;
66
77import {
8- $$ ,
9- $$textContent ,
10- click ,
11- clickElement ,
128 platform ,
139 selectOption ,
14- waitFor ,
15- waitForElementsWithTextContent ,
16- waitForElementWithTextContent ,
17- waitForFunction ,
1810} from '../../shared/helper.js' ;
11+ import { getBrowserAndPagesWrappers } from '../../shared/non_hosted_wrappers.js' ;
1912
2013const CANCEL_BUTTON_SELECTOR = '[aria-label="Discard changes"]' ;
2114const CONFIRM_BUTTON_SELECTOR = '[aria-label="Confirm changes"]' ;
@@ -59,13 +52,15 @@ if (platform === 'mac') {
5952 CONTROL_ALT_C_SHORTCUT_INPUT_TEXT = [ 'Ctrl ⌥ C' ] ;
6053}
6154
62- export const selectKeyboardShortcutPreset = async ( option : string ) => {
63- const presetSelectElement = await waitForElementWithTextContent ( SHORTCUT_SELECT_TEXT ) ;
55+ export const selectKeyboardShortcutPreset =
56+ async ( option : string , devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
57+ const presetSelectElement = await devToolsPage . waitForElementWithTextContent ( SHORTCUT_SELECT_TEXT ) ;
6458 await selectOption ( await presetSelectElement . toElement ( 'select' ) , option ) ;
6559} ;
6660
67- export const getShortcutListItemElement = async ( shortcutText : string ) => {
68- const textMatches = await $$textContent ( shortcutText ) ;
61+ export const getShortcutListItemElement =
62+ async ( shortcutText : string , devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
63+ const textMatches = await devToolsPage . $$textContent ( shortcutText ) ;
6964 let titleElement ;
7065 for ( const matchingElement of textMatches ) {
7166 // some actions have the same name as categories, so we have to make sure we've got the right one
@@ -78,20 +73,22 @@ export const getShortcutListItemElement = async (shortcutText: string) => {
7873 assert . fail ( 'shortcut element not found' ) ;
7974 }
8075 const listItemElement = await titleElement . getProperty ( 'parentElement' ) ;
81- return ( listItemElement as ElementHandle ) . asElement ( ) ;
76+ return listItemElement . asElement ( ) ;
8277} ;
8378
84- export const editShortcutListItem = async ( shortcutText : string ) => {
85- const listItemElement = await getShortcutListItemElement ( shortcutText ) as ElementHandle ;
79+ export const editShortcutListItem =
80+ async ( shortcutText : string , devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
81+ const listItemElement = await getShortcutListItemElement ( shortcutText , devToolsPage ) as ElementHandle ;
8682
87- await clickElement ( listItemElement ) ;
88- await click ( EDIT_BUTTON_SELECTOR , { root : listItemElement } ) ;
83+ await devToolsPage . clickElement ( listItemElement ) ;
84+ await devToolsPage . click ( EDIT_BUTTON_SELECTOR , { root : listItemElement } ) ;
8985
90- await waitFor ( RESET_BUTTON_SELECTOR ) ;
86+ await devToolsPage . waitFor ( RESET_BUTTON_SELECTOR ) ;
9187} ;
9288
93- export const shortcutsForAction = async ( shortcutText : string ) => {
94- const listItemElement = await getShortcutListItemElement ( shortcutText ) ;
89+ export const shortcutsForAction =
90+ async ( shortcutText : string , devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
91+ const listItemElement = await getShortcutListItemElement ( shortcutText , devToolsPage ) ;
9592 if ( ! listItemElement ) {
9693 assert . fail ( `Could not find shortcut item with text ${ shortcutText } ` ) ;
9794 }
@@ -102,17 +99,17 @@ export const shortcutsForAction = async (shortcutText: string) => {
10299 shortcutElementsTextContent . map ( async textContent => textContent ? await textContent . jsonValue ( ) : [ ] ) ) ;
103100} ;
104101
105- export const shortcutInputValues = async ( ) => {
106- const shortcutInputs = await $$ ( SHORTCUT_INPUT_SELECTOR ) ;
102+ export const shortcutInputValues = async ( devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
103+ const shortcutInputs = await devToolsPage . $$ ( SHORTCUT_INPUT_SELECTOR ) ;
107104 if ( ! shortcutInputs . length ) {
108105 assert . fail ( 'shortcut input not found' ) ;
109106 }
110107 const shortcutValues = await Promise . all ( shortcutInputs . map ( async input => await input . getProperty ( 'value' ) ) ) ;
111108 return await Promise . all ( shortcutValues . map ( async value => value ? await value . jsonValue ( ) : [ ] ) ) ;
112109} ;
113110
114- export const clickAddShortcutLink = async ( ) => {
115- const addShortcutLinkTextMatches = await waitForElementsWithTextContent ( ADD_SHORTCUT_LINK_TEXT ) ;
111+ export const clickAddShortcutLink = async ( devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
112+ const addShortcutLinkTextMatches = await devToolsPage . waitForElementsWithTextContent ( ADD_SHORTCUT_LINK_TEXT ) ;
116113 let addShortcutLinkElement ;
117114 // the link container and the link have the same textContent, but only the latter has a click handler
118115 for ( const matchingElement of addShortcutLinkTextMatches ) {
@@ -125,40 +122,41 @@ export const clickAddShortcutLink = async () => {
125122 assert . fail ( 'could not find add shortcut link' ) ;
126123 }
127124
128- await clickElement ( addShortcutLinkElement ) ;
125+ await devToolsPage . clickElement ( addShortcutLinkElement ) ;
129126} ;
130127
131- export const clickShortcutConfirmButton = async ( ) => {
132- await click ( CONFIRM_BUTTON_SELECTOR ) ;
128+ export const clickShortcutConfirmButton = async ( devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
129+ await devToolsPage . click ( CONFIRM_BUTTON_SELECTOR ) ;
133130} ;
134131
135- export const clickShortcutCancelButton = async ( ) => {
136- await click ( CANCEL_BUTTON_SELECTOR ) ;
132+ export const clickShortcutCancelButton = async ( devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
133+ await devToolsPage . click ( CANCEL_BUTTON_SELECTOR ) ;
137134} ;
138135
139- export const clickShortcutResetButton = async ( ) => {
140- await click ( RESET_BUTTON_SELECTOR ) ;
136+ export const clickShortcutResetButton = async ( devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
137+ await devToolsPage . click ( RESET_BUTTON_SELECTOR ) ;
141138} ;
142139
143- export const clickShortcutDeleteButton = async ( index : number ) => {
144- const deleteButtons = await $$ ( DELETE_BUTTON_SELECTOR ) ;
140+ export const clickShortcutDeleteButton =
141+ async ( index : number , devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
142+ const deleteButtons = await devToolsPage . $$ ( DELETE_BUTTON_SELECTOR ) ;
145143 if ( deleteButtons . length <= index ) {
146144 assert . fail ( `shortcut delete button #${ index } not found` ) ;
147145 }
148- await clickElement ( deleteButtons [ index ] ) ;
146+ await devToolsPage . clickElement ( deleteButtons [ index ] ) ;
149147} ;
150148
151- export const waitForEmptyShortcutInput = async ( ) => {
152- await waitForFunction ( async ( ) => {
153- const shortcutInputs = await $$ ( SHORTCUT_INPUT_SELECTOR ) ;
149+ export const waitForEmptyShortcutInput = async ( devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
150+ await devToolsPage . waitForFunction ( async ( ) => {
151+ const shortcutInputs = await devToolsPage . $$ ( SHORTCUT_INPUT_SELECTOR ) ;
154152 const shortcutInputValues = await Promise . all ( shortcutInputs . map ( input => input . getProperty ( 'value' ) ) ) ;
155153 const shortcutInputValueStrings =
156154 await Promise . all ( shortcutInputValues . map ( value => value ? value . jsonValue ( ) : { } ) ) ;
157155 return shortcutInputValueStrings . includes ( '' ) ;
158156 } ) ;
159157} ;
160158
161- export const waitForVSCodeShortcutPreset = async ( ) => {
159+ export const waitForVSCodeShortcutPreset = async ( devToolsPage = getBrowserAndPagesWrappers ( ) . devToolsPage ) => {
162160 // wait for a shortcut that vsCode has but the default preset does not
163- await waitForElementWithTextContent ( VS_CODE_SHORTCUTS_SHORTCUTS . join ( '' ) ) ;
161+ await devToolsPage . waitForElementWithTextContent ( VS_CODE_SHORTCUTS_SHORTCUTS . join ( '' ) ) ;
164162} ;
0 commit comments