import type { Response } from 'playwright' ; import { SupportedCharacters } from 'test-keyboard' ; import type { PlaywrightBrowserName } from './playwright-types' ; /**
 * Clear the editor via triple click and backspace.
 */ export async function clearEditor ( selector ) { await page . click ( selector , { clickCount : 3 } ) ; await page . keyboard . press ( 'Backspace' ) ; } /**
 * Create a selector.
 */ export function sel ( ... selectors ) { return selectors . join ( ' ' ) ; } /**
 * Obtain the inner HTML.
 */ export function innerHtml ( selector ) { return page . $eval ( selector , ( element ) => element . innerHTML ) ; } /**
 * Retrieve the text content from the editor
 */ export function textContent ( selector ) { return page . $eval ( selector , ( element ) => element . textContent ) ; } /**
 * Retrieve the outerHTML from the editor
 */ export function outerHtml ( selector ) { return page . $eval ( selector , ( element ) => element . outerHTML ) ; } param length param fn function times < Type = number > ( length , fn ? ) { return Array . from < unknown , Type > ( { length } , ( _ , index ) => fn ? fn ( index ) : ( index as unknown as Type ) ) ; } param sequence return async function promiseSequence ( sequence ) { const promise = Promise . resolve ( ) ; for ( const next of sequence ) { promise . then ( next ) ; } return promise ; } export interface TypeProps { /**
     * The text to type.
     */ text : string ; /**
     * The delay between each key press. Setting this higher can sometimes solve fix flakey tests.
     */ delay ? : number ; } export interface PressProps extends Pick < TypeProps , 'delay' > { /**
     * The key to press.
     */ key : SupportedCharacters ; default count ? : number ; } param key param count return export async function press ( { key , count = 1 , delay = 10 } ) { return promiseSequence ( times ( count , ( ) => ( ) => page . keyboard . press ( key , { delay } ) ) ) ; } /**
 * Wrapper around `page.keyboard.type` with default typing delay.
 */ export async function type ( { text , delay = 10 } ) { return page . keyboard . type ( text , { delay } ) ; } interface HTMLObject { _ : 'HTML' ; html : string ; } async function makeHtmlObject ( htmlOrPromise ) { return await Promise . resolve ( { _ : 'HTML' , html : await Promise . resolve ( htmlOrPromise ) } ) ; } export function $innerHtml ( selector ) { return makeHtmlObject ( page . $eval ( selector , ( element ) => element . innerHTML ) ) ; } /**
 * Navigate to a page relative to the active server's main URL.
 *
 * The timeout is increased so that the first navigation can succeed.
 */ export async function goto ( url = '' ) { return page . goto ( __SERVER__ . url + url , { timeout : 60000 } ) ; } /**
 * Retrieve the browser name from the environment
 */ export function getBrowserName ( ) { return process . env . E2E_BROWSER ?? 'chromium' ; } /**
 * Prefix the browser name to the passed in string
 */ export function prefixBrowserName ( ... value ) { return `${ getBrowserName ( ) }-${ process . platform }-${ __SERVER__ . name }-${ value . join ( '-' ) }` ; }