Skip to content

Commit

Permalink
Set window size to a better default size when running Chrome he… (#6440)
Browse files Browse the repository at this point in the history
* Set window size to a better default size when running headless in chrome

* add test for spawning in 720p

Co-authored-by: Ben Kucera <[email protected]>
  • Loading branch information
jennifer-shehane and kuceb authored Feb 28, 2020
1 parent 8d7f1a0 commit b4f6f0c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/server/lib/browsers/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ export = {

if (isHeadless) {
args.push('--headless')

// set the window size for headless to a better default
// https://github.com/cypress-io/cypress/issues/6210
args.push('--window-size=1280,720')
}

// force ipv4
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/e2e/1_firefox_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ describe('e2e firefox', function () {
e2e.it('launches maximized by default', {
browser: 'firefox',
project: Fixtures.projectPath('screen-size'),
spec: '*',
spec: 'maximized.spec.js',
})
})
8 changes: 8 additions & 0 deletions packages/server/test/e2e/2_headless_spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const e2e = require('../support/helpers/e2e')
const Fixtures = require('../support/helpers/fixtures')

describe('e2e headless', function () {
e2e.setup()
Expand Down Expand Up @@ -38,4 +39,11 @@ describe('e2e headless', function () {
browser: b,
})
})

e2e.it('launches maximized by default in headless mode (1280x720)', {
browser: 'chrome',
headed: false,
project: Fixtures.projectPath('screen-size'),
spec: '720p.spec.js',
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
describe('windowSize', () => {
it('spawns 720p', () => {
// assert the browser was spawned at 1280x720 and is full size
// normally e2e tests spawn at fixed size, but this spec should be spawned without passing any width/height arguments in plugins file.
expect({
innerWidth: top.window.innerWidth,
innerHeight: top.window.innerHeight,
availWidth: top.screen.availWidth,
availHeight: top.screen.availHeight,
screenWidth: top.screen.width,
screenHeight: top.screen.height,
}).deep.eq({
innerWidth: 1280,
innerHeight: 720,
availWidth: 1280,
availHeight: 720,
screenWidth: 1280,
screenHeight: 720,
})
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('firefox windowSize', () => {
describe('windowSize', () => {
it('spawns maximized', () => {
// normally e2e tests spawn at fixed size, but this spec should be spawned without passing any width/height arguments in plugins file.
expect(top.window.innerWidth).eq(top.screen.availWidth)
Expand Down
14 changes: 14 additions & 0 deletions packages/server/test/unit/browsers/chrome_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ describe "lib/browsers/chrome", ->
# we load the browser with blank page first
expect(utils.launch).to.be.calledWith("chrome", "about:blank", args)

it "sets default window size in headless mode", ->
chrome._writeExtension.restore()

pathToTheme = extension.getPathToTheme()

chrome.open({ isHeadless: true, isHeaded: false }, "http://", {}, @automation)
.then =>
args = utils.launch.firstCall.args[2]

expect(args).to.include.members([
"--headless"
"--window-size=1280,720"
])

it "does not load extension in headless mode", ->
chrome._writeExtension.restore()

Expand Down

4 comments on commit b4f6f0c

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b4f6f0c Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.0.3/linux-x64/circle-develop-b4f6f0c566b3550d39e87416705556b5fd339309-267559/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.0.3/circle-develop-b4f6f0c566b3550d39e87416705556b5fd339309-267542/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b4f6f0c Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.0.3/darwin-x64/circle-develop-b4f6f0c566b3550d39e87416705556b5fd339309-267566/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.0.3/circle-develop-b4f6f0c566b3550d39e87416705556b5fd339309-267563/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b4f6f0c Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.0.3/win32-ia32/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.0.3/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.0.3/win32-ia32/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.0.3/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.0.3/win32-ia32/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.0.3/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.0.3/win32-ia32/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.0.3/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b4f6f0c Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.0.3/win32-x64/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.0.3/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.0.3/win32-x64/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.0.3/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.0.3/win32-x64/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.0.3/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.0.3/win32-x64/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.0.3/appveyor-develop-b4f6f0c566b3550d39e87416705556b5fd339309-31115482/cypress.tgz

Please sign in to comment.