import { PlaywrightFluent } from '../../playwright-fluent' ; import { LaunchOptions } from '../../../actions' ; import { sizeOf , ViewportSize } from '../../../devices' ; const isCI = require ( 'is-ci' ) as boolean ; describe ( 'Playwright Fluent - withViewPort' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should target chromium in headfull with viewport size 800x600' , async ( ) : Promise < void > => { const browser = 'chromium' ; const options = { headless : false , } ; const url = 'https://reactstrap.github.io' ; const viewport = { ... sizeOf . _800x600 , } ; await p . withBrowser ( browser ) . withOptions ( options ) . withViewport ( viewport ) . navigateTo ( url ) ; const windowState = await p . getCurrentWindowState ( ) ; expect ( Math . abs ( windowState . innerWidth - viewport . width ) ) . toBeLessThanOrEqual ( 10 ) ; expect ( Math . abs ( windowState . innerHeight - viewport . height ) ) . toBeLessThanOrEqual ( 10 ) ; } ) ; test ( 'should target chromium in headfull with viewport size 1280x720' , async ( ) : Promise < void > => { const browser = 'chromium' ; const options = { headless : false , } ; const url = 'https://reactstrap.github.io' ; const viewport = { ... sizeOf . _1280x720 , } ; await p . withBrowser ( browser ) . withOptions ( options ) . withViewport ( viewport ) . navigateTo ( url ) ; const windowState = await p . getCurrentWindowState ( ) ; expect ( Math . abs ( windowState . innerWidth - viewport . width ) ) . toBeLessThanOrEqual ( 10 ) ; expect ( Math . abs ( windowState . innerHeight - viewport . height ) ) . toBeLessThanOrEqual ( 10 ) ; } ) ; test ( 'should target chromium in headfull with viewport size 1600x900' , async ( ) : Promise < void > => { if ( ! isCI ) { console . log ( 'test will be ignored because it should be executed only in a CI env' ) ; return ; } const browser = 'chromium' ; const options = { headless : false , } ; const url = 'https://reactstrap.github.io' ; const viewport = { ... sizeOf . _1600x900 , } ; await p . withBrowser ( browser ) . withOptions ( options ) . withViewport ( viewport , { ciOnly : true } ) . navigateTo ( url ) ; const windowState = await p . getCurrentWindowState ( ) ; expect ( Math . abs ( windowState . innerWidth - viewport . width ) ) . toBeLessThanOrEqual ( 10 ) ; expect ( Math . abs ( windowState . innerHeight - viewport . height ) ) . toBeLessThanOrEqual ( 10 ) ; } ) ; } ) ;