Cypress: Support `chrome --headless`

Created on 27 Oct 2017  路  44Comments  路  Source: cypress-io/cypress

Change 1.

With Chrome 63 coming out we can make some big changes at Cypress.

  1. We will be able to support the debugger protocol which will enable native events
  2. We will be able to support chrome --headless

The reason we currently do not support chrome --headless is because Chrome does not support extensions in that mode. We use an extension to automate the browser and that's why its a no-go. By switching from the extension to the debugger protocol, we'll be able to get around this.

Change 2.

Once we support chrome headless I propose the following changes to the CLI:

cypress run

Currently cypress run will launch Electron headlessly. This is confusing for users because they can't see what's going on and because they don't read our docs they don't understand that we're launching Electron instead of Chrome. Due to the browser version differences, they see failures in Electron that aren't happening in Chrome.

What I propose is to change this behavior so that cypress run by default will search for Chrome and launch it in headed mode. When no Chrome is installed, it'll fall back to Electron.

Currently we support a --headed option that only applies to Electron. This was done to prevent breaking changes.

This should now switch to being the default but then enabling the user to explicitly opt into the --headless mode for both Electron + Chrome.

This will be a breaking change and could come out in Cypress 2.x.x.

heroku chrome cli

Most helpful comment

Is Chrome headless support happening? If so, is there an approx. date of availability?

All 44 comments

This is important. Today I found a couple of our tests failing in CI environments but not locally using cypress app. It turns out Chrome and Electron act differently.

Is there anyway you can prioritize this feature? 2.x.x seems like too far away.

Chrome and Electron act the same - the difference is the underlying version of Chromium each is using.

Electron uses Chromium 53. Your local version of Chrome likely differs. These different versions will not act exactly the same.

I can't say when this will be prioritized because all of our team members are currently working on other features. We are open source now and are accepting PR's of course. It's going to be a lot of work - likely weeks for someone to work on full time.

As for the 2.x.x - its not that far off because we use semver. Whenever we have the next breaking change we will reach 2.x.x - it could be the next release for that matter!

What I would suggest is install chrome in CI and make it match the version you're running locally. We have several docker containers with this prebuilt.

Alternatively you could also run Electron locally to suss out the differences in failing tests. Plenty of users do either.

@brian-mann, has there been any consideration to either:

  1. Expose arguments to pass to chrome to run it in headless mode?
  2. Semi-regularly update the version of Chromium used in the Electron browser? It looks like it's currently 10 versions behind.

Those might be lower-hanging (?) fruit that might help close the gap.

@nrutman there is already an API for doing your first bullet item: https://docs.cypress.io/api/plugins/browser-launch-api.html

The problem is that running in headless mode disables chrome extensions which prevents Cypress from working. However you can modify other arguments.

Yes, per your second bullet item we have been waiting for Electron to drop 1.8 which bumps node to 8.x.x. They are currently in beta with semi regular releases.

https://electronjs.org/releases#1.8.2-beta.4

Looks like should be able to load extensions for headless chrome with flags

--disable-extensions-except=/path/to/extension/
--load-extension=/path/to/extension/

Source: https://github.com/GoogleChrome/puppeteer/issues/659#issuecomment-341965254

I had read somewhere about chrome headless not ever going to support extensions. I don't believe there are any configuration options that will change this. Puppeteer here is irrelevant since this is a restriction from Chrome itself.

@brian-mann When this change will be rolledout

Why cypress need chrome extension? Why using headless mode is valuable?

Should still be able to switch from using xvfb and chrome -> chome --headless

@kelegorm Headless chrome would be awesome, since it's the option default available at Heroku. To quote from their webpage:

Google Chrome recently added support for a --headless command line option, which means you no longer need a window server to run browser tests. This configuration is optimal for UAT as it uses your browser, but doesn鈥檛 waste cycles rendering content to the screen. As such, this is our prescribed browser solution.

They have depreciated support for Xvfb Chrome buildpack on their new buildpacks, such as heroku-16.

So you might say, why care about Heroku? The best argument I can find is that while Cypress makes it easy to do end2end testing, Heroku aims to make hosting simple. A perfect match 鉂わ笍

Yes, this would be fantastic to have Cypress working with Heroku. This currently stops me from using Cypress

Is Chrome headless support happening? If so, is there an approx. date of availability?

Any update on this? We heavily use cypress and heroku but cypress needs cedar-14 which will go away in april 2019.

Cypress team update

We have investigated headless Chrome support. To support executing commands and capture the video of the test run, we must go through the Debugger protocol. Thus we will support headless Chrome after landing native events #311 which is in progress.

Hi,

Thank you for your work !! I just started to use Cypress and it's really great !

Unfortunatly I'm using heroku and cedar-14 is no more supported so I'm waiting for headless Chrome support...

Capture d鈥檈虂cran 2019-03-18 a虁 14 56 16

I saw above that you are working on it, but do you know when it will be available ? Is it in days, weeks, month ? I'm stuck waiting for this feature it's too bad :cry:

Just a suggestion here... why not split this to separate "Support chrome headless" and "change defaults for cypress run" into separate issues?
Changing defaults introduces a breaking change, whereas "Support chrome headless" (presumably) should be able to be delivered without breaking changes.

I'm all for anything that gets headless chrome support delivered quicker, as I'm having a bit of trouble dealing with some electron limitations.

I had read somewhere about chrome headless not ever going to support extensions. I don't believe there are any configuration options that will change this. Puppeteer here is irrelevant since this is a restriction from Chrome itself.

Relevant link:
https://bugs.chromium.org/p/chromium/issues/detail?id=706008#c5
Please star this issue as a 'vote' for them to reopen and implement it :)

"cypress run --browser chrome" works fine but fire up a browser,
"cypress run --browser chrome --headless" doe not work as --headless is not a supported option

Cypress team update

We have investigated headless Chrome support. To support executing commands and capture the video of the test run, we must go through the Debugger protocol. Thus we will support headless Chrome after landing native events #311 which is in progress.

Hi , I am still not able to run cypress in headless mode . Am using Cypress "3.4.1" and the command i used are "cypress run" and "cypress run -b chrome --headless". Can u pls tell the workaround?

What is going on with this one, seems like we were going to do it but that was 2yrs ago?

Cypress team update

We have investigated headless Chrome support. To support executing commands and capture the video of the test run, we must go through the Debugger protocol. Thus we will support headless Chrome after landing native events #311 which is in progress.

Hi , I am still not able to run cypress in headless mode . Am using Cypress "3.4.1" and the command i used are "cypress run" and "cypress run -b chrome --headless". Can u pls tell the workaround?

@brian-mann .. Can u pls get any update on it . cos i am stuck with it

Could you please help me with any updates on this ?@brian-mann

Would be nice to have the option to run chromium headlessly because otherwise I currently would have to deactivate ALL cypress tests for my CI setup, as they do fail for some reason with Electron.
Please give us an update.

@electrocnic, I run my e2e tests in CircleCI using the Chrome browser with no problems. You don't necessarily _have_ to run them headlessly in CI.

@jrnail23 Can you detail which commands you use exactly?

@quentinus95, I run cypress run --browser chrome, and I use a cypress Docker image as the executor (cypress/browsers:node10.16.0-chrome76).
Hope that helps.

@jrnail23 this sounds awesome, but I'm confused. How do you run a non-headless browser in a Docker container, doesn't it need video or something?

Am I being dumb? 馃槅

If this is true, I could really use this in my CI pipeline

@electrocnic @quentinus95 @Stephen2 - you can launch Chrome browser if it is installed on your CI machine (use one of our Docker images https://github.com/cypress-io/cypress-docker-images/tree/master/browsers if you need Chrome installed) using cypress run --browser chrome CLI argument. Cypress automatically starts XVFB server in Linux and runs Chrome in headed mode. For now, there is no video of the Chrome headed run, but there will be one soon. See https://on.cypress.io/launching-browsers

@Stephen2, it just works. And no, you're not being dumb!
Headless is actually a pretty new development for browser testing, but perhaps unless your app uses GPU (i.e., WebGL) there's nothing really stopping you from running your tests in CI on regular 'ol Chrome.
I'd been using effectively the same approach for years when testing on Chrome via selenium webdriver in TeamCity.

@quentinus95, I run cypress run --browser chrome, and I use a cypress Docker image as the executor (cypress/browsers:node10.16.0-chrome76).
Hope that helps.

Well, wow. Nice thank you so much!
Why did I believe this would not work?! xD

Apparently electron is always lagging behind compared to chrome. This is the second time we run into the situation that a test runs fine in chrome but fails in electron because certain elements don't show in electron.The first time we were saved by an upgrade, now we are stuck.
Could you consider implementing the chrome --headless option? You can then quit supporting electron, saving you a lot of time!
Haven't tried installing chrome in our container pipeline yet (we are using OpenShift)

bump on this thread really need this option

Any updates on this matter?

@Psycholisk, as of v3.5 you can run headlessly with a pretty recent version of Chromium (v73, as embedded in its Electron bundle). The latest version of Chrome is 78, so that's pretty close.

There is a work-in-progress PR for this issue: #5676

ok guys we're waiting for this one :grin:

The code for this is done in cypress-io/cypress#5676, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Released in 3.8.0.

Thank you!

Does not work for me. Cypress opens a visible maximized (it does not adhere viewportWidth and viewportHeight settings) my chrome instance when running cypress run --headless --browser chrome.

Interestingly, it does report to be running chrome 78 headless:
image

Cypress: 3.8.0
OS: Microsoft Windows 10 Enterprise Version 10.0.16299 Build 16299

@Waterstraal I feel you better open a new issue for that.

New issue for --headless not opening Chrome in headless mode here: https://github.com/cypress-io/cypress/issues/5949

5949 fixed

Was this page helpful?
0 / 5 - 0 ratings