import { PlaywrightFluent } from '../../playwright-fluent' ; import { BrowserName } from '../../../actions' ; declare const window ; describe ( 'Playwright Fluent - withBrowser' , ( ) : void => { beforeEach ( ( ) : void => { } ) ; test ( 'should target chrome' , async ( ) : Promise < void > => { const browser = 'chrome' ; const p = new PlaywrightFluent ( ) ; await p . withBrowser ( browser ) ; const browserInstance = p . currentBrowser ( ) ; const pageInstance = p . currentPage ( ) ; expect ( browserInstance ) . toBeDefined ( ) ; expect ( pageInstance ) . toBeDefined ( ) ; const userAgent = pageInstance && ( await pageInstance . evaluate ( ( ) => window . navigator . userAgent ) ) ; expect ( userAgent ) . toContain ( 'HeadlessChrome' ) ; browserInstance && ( await browserInstance . close ( ) ) ; } ) ; test ( 'should target chromium' , async ( ) : Promise < void > => { const browser = 'chromium' ; const p = new PlaywrightFluent ( ) ; await p . withBrowser ( browser ) ; const browserInstance = p . currentBrowser ( ) ; const pageInstance = p . currentPage ( ) ; expect ( browserInstance ) . toBeDefined ( ) ; expect ( pageInstance ) . toBeDefined ( ) ; const userAgent = pageInstance && ( await pageInstance . evaluate ( ( ) => window . navigator . userAgent ) ) ; expect ( userAgent ) . toContain ( 'HeadlessChrome' ) ; browserInstance && ( await browserInstance . close ( ) ) ; } ) ; test ( 'should target msedge' , async ( ) : Promise < void > => { const browser = 'msedge' ; const p = new PlaywrightFluent ( ) ; await p . withBrowser ( browser ) ; const browserInstance = p . currentBrowser ( ) ; const pageInstance = p . currentPage ( ) ; expect ( browserInstance ) . toBeDefined ( ) ; expect ( pageInstance ) . toBeDefined ( ) ; const userAgent = pageInstance && ( await pageInstance . evaluate ( ( ) => window . navigator . userAgent ) ) ; expect ( userAgent ) . toContain ( 'Edg/' ) ; browserInstance && ( await browserInstance . close ( ) ) ; } ) ; test ( 'should target firefox' , async ( ) : Promise < void > => { const browser = 'firefox' ; const p = new PlaywrightFluent ( ) ; await p . withBrowser ( browser ) ; const browserInstance = p . currentBrowser ( ) ; const pageInstance = p . currentPage ( ) ; expect ( browserInstance ) . toBeDefined ( ) ; expect ( pageInstance ) . toBeDefined ( ) ; const userAgent = pageInstance && ( await pageInstance . evaluate ( ( ) => window . navigator . userAgent ) ) ; expect ( userAgent ) . toContain ( 'Firefox' ) ; browserInstance && ( await browserInstance . close ( ) ) ; } ) ; test ( 'should target webkit' , async ( ) : Promise < void > => { const browser = 'webkit' ; const p = new PlaywrightFluent ( ) ; await p . withBrowser ( browser ) ; const browserInstance = p . currentBrowser ( ) ; const pageInstance = p . currentPage ( ) ; expect ( browserInstance ) . toBeDefined ( ) ; expect ( pageInstance ) . toBeDefined ( ) ; const userAgent = pageInstance && ( await pageInstance . evaluate ( ( ) => window . navigator . userAgent ) ) ; expect ( userAgent ) . toContain ( 'Safari' ) ; browserInstance && ( await browserInstance . close ( ) ) ; } ) ; test ( 'should throw an error on unknown browser' , async ( ) : Promise < void > => { const browser = 'yo' ; const p = new PlaywrightFluent ( ) ; let result = undefined ; try { await p . withBrowser ( browser as BrowserName ) ; } catch ( error ) { result = error as Error ; } const expectedErrorMessage = "Browser named 'yo' is unknown. It should be one of 'chrome', 'chromium', 'chrome-canary', 'firefox', 'webkit'" ; expect ( result && result . message ) . toContain ( expectedErrorMessage ) ; expect ( ( p . lastError ( ) || { } ) . message ) . toBe ( expectedErrorMessage ) ; } ) ; } ) ;