import 'cypress-real-events/support' ; import { Interception } from 'cypress/types/net-stubbing' ; Cypress . Commands . add ( 'loginAsReadOnlyUser' , ( ) => { cy . loginAs ( { username : 'apm_read_user' , password : 'changeme' } ) ; } ) ; Cypress . Commands . add ( 'loginAsPowerUser' , ( ) => { cy . loginAs ( { username : 'apm_power_user' , password : 'changeme' } ) ; } ) ; Cypress . Commands . add ( 'loginAs' , ( { username , password } ) => { cy . log ( `Logging in as ${ username }` ) ; const kibanaUrl = Cypress . env ( 'KIBANA_URL' ) ; cy . request ( { log : false , method : 'POST' , url : `${ kibanaUrl }/internal/security/login` , body : { providerType : 'basic' , providerName : 'basic' , currentURL : `${ kibanaUrl }/login` , params : { username , password } , } , headers : { 'kbn-xsrf' : 'e2e_test' , } , } ) ; } ) ; Cypress . Commands . add ( 'changeTimeRange' , ( value ) => { cy . get ( '[data-test-subj="superDatePickerToggleQuickMenuButton"]' ) . click ( ) ; cy . contains ( value ) . click ( ) ; } ) ; Cypress . Commands . add ( 'selectAbsoluteTimeRange' , ( start , end ) => { cy . get ( '[data-test-subj="superDatePickerstartDatePopoverButton"]' ) . click ( ) ; cy . get ( '[data-test-subj="superDatePickerAbsoluteDateInput"]' ) . eq ( 0 ) . clear ( ) . type ( start , { force : true } ) ; cy . get ( '[data-test-subj="superDatePickerendDatePopoverButton"]' ) . click ( ) ; cy . get ( '[data-test-subj="superDatePickerAbsoluteDateInput"]' ) . eq ( 1 ) . clear ( ) . type ( end , { force : true } ) ; } ) ; Cypress . Commands . add ( 'expectAPIsToHaveBeenCalledWith' , ( { apisIntercepted , value , } ) => { cy . wait ( apisIntercepted ) . then ( ( interceptions ) => { if ( Array . isArray ( interceptions ) ) { interceptions . map ( ( interception ) => { expect ( interception . request . url ) . include ( value ) ; } ) ; } else { expect ( ( interceptions as Interception ) . request . url ) . include ( value ) ; } } ) ; } ) ;