MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / pressKeys

Function pressKeys

core/src/utils/test/press-keys.ts:106–147  ·  view source on GitHub ↗
(this: PageUtils, key: string, { times, ...pressOptions }: Options = {})

Source from the content-addressed store, hash-verified

104 * ```
105 */
106export async function pressKeys(this: PageUtils, key: string, { times, ...pressOptions }: Options = {}) {
107 const hasNaturalTabNavigation = await getHasNaturalTabNavigation(this.page);
108 /**
109 * Split the key combination into individual keys and map each key to its
110 * corresponding modifier.
111 */
112 const keys = key.split('+').flatMap((keyCode) => {
113 /**
114 * If the key is a modifier, we need to map it to the correct modifier for
115 * the current platform.
116 */
117 if (keyCode in modifiers) {
118 return modifiers[keyCode as keyof typeof modifiers](isAppleOS).map((modifier) =>
119 modifier === CTRL ? 'Control' : capitalCase(modifier)
120 );
121 } else if (keyCode === 'Tab' && !hasNaturalTabNavigation) {
122 /**
123 * If the key is the tab key and the browser does not have natural tab
124 * navigation, we need to simulate the tab key press by pressing the Alt key
125 * and the Tab key.
126 */
127 return ['Alt', 'Tab'];
128 }
129 // If the key is not a modifier, we can just return the key.
130 return keyCode;
131 });
132 const normalizedKeys = keys.join('+');
133 const command = () => this.page.keyboard.press(normalizedKeys);
134
135 times = times ?? 1;
136 for (let i = 0; i < times; i += 1) {
137 await command();
138
139 if (times > 1 && pressOptions.delay !== undefined) {
140 /**
141 * If we are pressing the key multiple times, we need to wait for the
142 * delay between each key press.
143 */
144 await this.page.waitForTimeout(pressOptions.delay);
145 }
146 }
147}
148
149/**
150 * Capitalizes the first letter of a string.

Callers

nothing calls this directly

Calls 3

capitalCaseFunction · 0.85
commandFunction · 0.85

Tested by

no test coverage detected