diff --git a/packages/server/lib/browsers/chrome.ts b/packages/server/lib/browsers/chrome.ts index 6da3b80ba819..c389864e02d2 100644 --- a/packages/server/lib/browsers/chrome.ts +++ b/packages/server/lib/browsers/chrome.ts @@ -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 diff --git a/packages/server/test/e2e/1_firefox_spec.ts b/packages/server/test/e2e/1_firefox_spec.ts index f8b45230f7a6..e77f7acba444 100644 --- a/packages/server/test/e2e/1_firefox_spec.ts +++ b/packages/server/test/e2e/1_firefox_spec.ts @@ -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', }) }) diff --git a/packages/server/test/e2e/2_headless_spec.ts b/packages/server/test/e2e/2_headless_spec.ts index 4579c78183fe..a5c506806cfc 100644 --- a/packages/server/test/e2e/2_headless_spec.ts +++ b/packages/server/test/e2e/2_headless_spec.ts @@ -1,4 +1,5 @@ const e2e = require('../support/helpers/e2e') +const Fixtures = require('../support/helpers/fixtures') describe('e2e headless', function () { e2e.setup() @@ -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', + }) }) diff --git a/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/720p.spec.js b/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/720p.spec.js new file mode 100644 index 000000000000..36cf95938700 --- /dev/null +++ b/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/720p.spec.js @@ -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, + }) + }) +}) diff --git a/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/firefox_windowSize.js b/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/maximized.spec.js similarity index 89% rename from packages/server/test/support/fixtures/projects/screen-size/cypress/integration/firefox_windowSize.js rename to packages/server/test/support/fixtures/projects/screen-size/cypress/integration/maximized.spec.js index ff2897c7089c..a0dedb9d134e 100644 --- a/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/firefox_windowSize.js +++ b/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/maximized.spec.js @@ -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) diff --git a/packages/server/test/unit/browsers/chrome_spec.coffee b/packages/server/test/unit/browsers/chrome_spec.coffee index bff049c93675..8b2146640742 100644 --- a/packages/server/test/unit/browsers/chrome_spec.coffee +++ b/packages/server/test/unit/browsers/chrome_spec.coffee @@ -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()