import { AnswersQuestions , Interaction , Question , UsesAbilities } from '@serenity-js/core' ; import { ElementFinder , Key } from 'protractor' ; import { AlertPromise } from 'selenium-webdriver' ; import { withAnswerOf } from '../withAnswerOf' ; import { PressBuilder } from './PressBuilder' ; desc Instructs the  {@link @serenity-js/core/lib/screenplay/actor~Actor} to
 *  send a key press or a sequence of keys to a Web element.
 *
 *  **Please note** that modifier keys, such as Command ⌘, [won't work on Mac](https://github.com/angular/protractor/issues/690)
 *
 *  example example example see BrowseTheWeb see Target see {@link @serenity-js/assertions~Ensure} see {@link @serenity-js/assertions/lib/expectations~equals} see selenium-webdriver extends serenity-js export class Press extends Interaction { desc Instantiates this  {@link @serenity-js/core/lib/screenplay~Interaction} .
     *
     *  param { ... keys returns { PressBuilder } static the ( ... keys ) { return { in : ( field ) => new Press ( keys , field ) , } ; } param { string [ ] } keys param { Question < ElementFinder > | ElementFinder } field constructor ( private readonly keys , private readonly field ) { super ( ) ; } desc Makes the provided  {@link @serenity-js/core/lib/screenplay/actor~Actor} *  perform this  {@link @serenity-js/core/lib/screenplay~Interaction} .
     *
     *  param { UsesAbilities & AnswersQuestions } actor An  {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this  {@link @serenity-js/core/lib/screenplay~Interaction} returns { PromiseLike < void > } see {@link @serenity-js/core/lib/screenplay/actor~Actor} see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities} see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions} performAs ( actor ) { return withAnswerOf ( actor , this . field , ( elf ) => elf . sendKeys ( ... this . keys ) ) ; } desc Generates a description to be used when reporting this  {@link @serenity-js/core/lib/screenplay~Activity} .
     *
     *  returns { string } toString ( ) { return `#actor presses ${ describeSequenceOf ( this . keys ) } in ${ this . field . toString ( ) }` ; } } function describeSequenceOf ( keys ) { return keys . map ( key => [ capitalised ( nameOf ( key ) ) , isModifier ( key ) ? '-' : ', ' , ] ) . reduce ( ( acc , current ) => acc . concat ( current ) , [ ] ) . slice ( 0 , keys . length * 2 - 1 ) . join ( '' ) ; } function isModifier ( key ) { return ! ! ~ [ Key . ALT , Key . COMMAND , Key . CONTROL , Key . SHIFT ] . indexOf ( key ) ; } function nameOf ( key ) { for ( const candidate in Key ) { if ( Object . prototype . hasOwnProperty . call ( Key , candidate ) && Key [ candidate ] === key ) { return candidate ; } } return key ; } function capitalised ( name ) { return name . charAt ( 0 ) . toLocaleUpperCase ( ) + name . slice ( 1 ) . toLocaleLowerCase ( ) ; }