Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Use mobile emulation in Chrome to get better screen size emulation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bsessions85 committed Sep 24, 2018
1 parent 5e5c5d8 commit d065aa6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
45 changes: 44 additions & 1 deletion lib/driver-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export function startBrowser( { useCustomUA = true, resizeBrowserWindow = true }
} );
options.setProxy( this.getProxyType() );
options.addArguments( '--no-first-run' );
options.addArguments( '--window-size=1600,1200' );
options.setMobileEmulation( {
deviceMetrics: this.getBrowserSize( screenSize )
} );
if ( useCustomUA ) {
options.addArguments(
'user-agent=Mozilla/5.0 (wp-e2e-tests) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36'
Expand Down Expand Up @@ -194,7 +198,7 @@ export function startBrowser( { useCustomUA = true, resizeBrowserWindow = true }
.manage()
.setTimeouts( { implicit: webDriverImplicitTimeOutMS, pageLoad: webDriverPageLoadTimeOutMS } );

if ( resizeBrowserWindow ) {
if ( resizeBrowserWindow && browser.toLowerCase() !== 'chrome' ) {
this.resizeBrowser( driver, screenSize );
}

Expand Down Expand Up @@ -244,6 +248,45 @@ export function resizeBrowser( driver, screenSize ) {
}
}

export function getBrowserSize( screenSize ) {
let deviceMetrics = {
width: 1440,
height: 1000,
pixelRatio: 1
};
if ( typeof screenSize === 'string' ) {
switch ( screenSize.toLowerCase() ) {
case 'mobile':
deviceMetrics.height = 1000;
deviceMetrics.width = 400;
break;
case 'tablet':
deviceMetrics.height = 1000;
deviceMetrics.width = 1024;
break;
case 'desktop':
break;
case 'laptop':
deviceMetrics.height = 790;
deviceMetrics.width = 1400;
break;
default:
throw new Error(
'Unsupported screen size specified (' +
screenSize +
'). Supported values are desktop, tablet and mobile.'
);
}
} else {
throw new Error(
'Unsupported screen size specified (' +
screenSize +
'). Supported values are desktop, tablet and mobile.'
);
}
return deviceMetrics;
}

export async function clearCookiesAndDeleteLocalStorage( driver, siteURL = null ) {
if ( siteURL ) {
await driver.get( siteURL );
Expand Down
2 changes: 1 addition & 1 deletion lib/video-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function startDisplay() {
':' + global.displayNum,
'-screen',
'0',
'1600x12000x16',
'1600x1200x24',
'+extension',
'RANDR'
]
Expand Down

0 comments on commit d065aa6

Please sign in to comment.