-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show how to increase the browser window size (#657)
- Loading branch information
Showing
10 changed files
with
158 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Browser window size vs Application viewport | ||
|
||
 | ||
|
||
The browser window, the command log, and the application's iframe sizes are printed. | ||
|
||
The [plugin file](./cypress/plugins/index.js) increases the browser window size when running in the headless mode to produce high quality video. See [launch api](https://on.cypress.io/browser-launch-api) for more documentation. | ||
|
||
**Note:** increasing the browser window size seems to not work very well in Electron browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"fixturesFolder": false, | ||
"supportFile": false, | ||
"viewportWidth": 2000 | ||
} |
43 changes: 43 additions & 0 deletions
43
examples/fundamentals__window-size/cypress/integration/spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/// <reference types="cypress" /> | ||
/* eslint-env browser */ | ||
describe('window size', () => { | ||
it('shows the page clearly', () => { | ||
// let's get the total opened browser dimensions | ||
const windowWidth = window.top.innerWidth | ||
const windowHeight = window.top.innerHeight | ||
|
||
cy.log(`browser window is: **${windowWidth} x ${windowHeight}**`) | ||
cy.task('log', { message: 'browser window', o: { windowWidth, windowHeight } }, { log: false }) | ||
|
||
// part of the browser window is taken up the command log | ||
const commandLog = window.top.document.querySelector('.reporter-wrap') | ||
const commandLogWidth = commandLog.offsetWidth | ||
const commandLogHeight = commandLog.offsetHeight | ||
|
||
cy.log(`command log is: **${commandLogWidth} x ${commandLogHeight}**`) | ||
cy.task('log', { message: 'command log', o: { commandLogWidth, commandLogHeight } }, { log: false }) | ||
|
||
// the app thinks it has the following dimensions | ||
cy.window({ log: false }).then((win) => { | ||
// the application is scaled to fit into its iframe | ||
// and the iframe's dimensions are | ||
const iframe = cy.state('$autIframe') | ||
const iframeWidth = Math.round(iframe.width()) | ||
const iframeHeight = Math.round(iframe.height()) | ||
|
||
cy.log(`app iframe real size is: **${iframeWidth} x ${iframeHeight}**`) | ||
cy.task('log', { message: 'app iframe real size', o: { iframeWidth, iframeHeight } }, { log: false }) | ||
|
||
// the application thinks it has the window of the follow size | ||
// which is the "viewport" numbers | ||
const viewportWidth = win.innerWidth | ||
const viewportHeight = win.innerHeight | ||
|
||
cy.log(`app viewport is: **${viewportWidth} x ${viewportHeight}**`) | ||
cy.task('log', { message: 'app viewport', o: { viewportWidth, viewportHeight } }, { log: false }) | ||
}) | ||
|
||
cy.visit('index.html') | ||
cy.screenshot('page', { capture: 'runner' }) | ||
}) | ||
}) |
48 changes: 48 additions & 0 deletions
48
examples/fundamentals__window-size/cypress/plugins/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable no-console */ | ||
module.exports = function (on, config) { | ||
// configure plugins here | ||
on('task', { | ||
log ({ message, o }) { | ||
console.log(message) | ||
if (o) { | ||
console.log(JSON.stringify(o, null, 2)) | ||
} | ||
|
||
return null | ||
}, | ||
}) | ||
|
||
// let's increase the browser window size when running headlessly | ||
// this will produce higher resolution images and videos | ||
// https://on.cypress.io/browser-launch-api | ||
on('before:browser:launch', (browser = {}, launchOptions) => { | ||
console.log('launching browser %s is headless? %s', browser.name, browser.isHeadless) | ||
|
||
// the browser width and height we want to get | ||
// our screenshots and videos will be of that resolution | ||
const width = 1920 | ||
const height = 1080 | ||
|
||
console.log('setting the browser window size to %d x %d', width, height) | ||
|
||
if (browser.name === 'chrome' && browser.isHeadless) { | ||
launchOptions.args.push(`--window-size=${width},${height}`) | ||
|
||
// force screen to be non-retina and just use our given resolution | ||
launchOptions.args.push('--force-device-scale-factor=1') | ||
} | ||
|
||
if (browser.name === 'electron' && browser.isHeadless) { | ||
// might not work on CI for some reason | ||
launchOptions.preferences.width = width | ||
launchOptions.preferences.height = height | ||
} | ||
|
||
if (browser.name === 'firefox' && browser.isHeadless) { | ||
launchOptions.args.push(`--width=${width}`) | ||
launchOptions.args.push(`--height=${height}`) | ||
} | ||
|
||
return launchOptions | ||
}) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<html lang="en"> | ||
<head> | ||
<style> | ||
* { | ||
margin: 0 | ||
} | ||
body { | ||
background: url('200px.png'); | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "window-size", | ||
"version": "1.0.0", | ||
"description": "How to control the browser window size", | ||
"private": true, | ||
"scripts": { | ||
"cypress:open": "../../node_modules/.bin/cypress open", | ||
"cypress:run": "../../node_modules/.bin/cypress run", | ||
"test:ci": "../../node_modules/.bin/cypress run --headless --browser chrome", | ||
"test:ci:record": "../../node_modules/.bin/cypress run --record --headless --browser chrome" | ||
} | ||
} |