import { Page } from '@playwright/test' ; import { AM_URL , BASE_URL , CLIENT_ID , RESOURCE_URL , SCOPE , REALM_PATH , USERS } from '../env.config' ; import 'core-js/stable' ; export async function setupAndGo ( page , browserType , path , config ? ) { const messageArray = [ ] ; const networkArray = [ ] ; const url = new URL ( `${ BASE_URL }/${ path }` ) ; url . searchParams . set ( 'amUrl' , ( config && config . amUrl ) || AM_URL ) ; url . searchParams . set ( 'clientId' , ( config && config . clientId ) || CLIENT_ID ) ; config && config . code && url . searchParams . set ( 'code' , ( config && config . code ) || '' ) ; url . searchParams . set ( 'email' , ( config && config . email ) || '' ) ; url . searchParams . set ( 'middleware' , ( config && config . middleware ) || '' ) ; url . searchParams . set ( 'preAuthenticated' , ( config && config . preAuthenticated ) || '' ) ; url . searchParams . set ( 'pw' , ( config && config . pw ) || USERS [ 0 ] . pw ) ; url . searchParams . set ( 'realmPath' , ( config && config . realmPath ) || REALM_PATH ) ; url . searchParams . set ( 'resourceUrl' , ( config && config . resourceUrl ) || RESOURCE_URL ) ; url . searchParams . set ( 'scope' , ( config && config . scope ) || SCOPE ) ; config && config . state && url . searchParams . set ( 'state' , ( config && config . state ) || '' ) ; url . searchParams . set ( 'support' , ( config && config . support ) || '' ) ; url . searchParams . set ( 'tokenStore' , ( config && config . tokenStore ) || '' ) ; url . searchParams . set ( 'tree' , ( config && config . tree ) || '' ) ; url . searchParams . set ( 'un' , ( config && config . un ) || USERS [ 0 ] . un ) ; if ( browserType === 'chromium' ) { console . log ( url . toString ( ) ) ; } await page . goto ( url . toString ( ) ) ; page . on ( 'console' , ( msg ) => { messageArray . push ( msg . text ( ) ) ; } ) ; page . on ( 'console' , ( msg ) => { messageArray . push ( msg . text ( ) ) ; } ) ; page . on ( 'request' , ( req ) => { networkArray . push ( `${ new URL ( req . url ( ) ) . pathname }, ${ req . resourceType ( ) }` ) ; } ) ; page . on ( 'dialog' , async ( dialog ) => { await dialog . accept ( config ?. dialogInput || 'abc123' ) ; } ) ; await page . waitForSelector ( config ?. selector || '.Test_Complete' ) ; return { messageArray , networkArray } ; }