{"__v":0,"_id":"5697efe61c4dc8230054268e","category":{"__v":16,"_id":"56954a95fe18811700c9bfdf","pages":["56954a97fe18811700c9c01d","56954a97fe18811700c9c01e","56954a97fe18811700c9c01f","56954a97fe18811700c9c020","56954a97fe18811700c9c021","56954a97fe18811700c9c022","56954a97fe18811700c9c023","56954a97fe18811700c9c024","56954a97fe18811700c9c025","56954a97fe18811700c9c026","56954a97fe18811700c9c027","56954a97fe18811700c9c028","56954a97fe18811700c9c029","5696cda524490c3700170a05","5697efe61c4dc8230054268e","5697efe72cf4060d004eaa75","56993ff47465970d00650b8f","56a7a155dfdabc0d000ae910","56a7a155b5d0920d0051cd81","56a7a1a6cf6d771700baeee3","56a7a1a63d33bc2100793d5d","56a7a23097e8b00d0096d209","56a7a230ea3e3417000df4b1","56a7a25acf6d771700baeee6","56a7a25a03f28c0d00a545bf","56a7a2b83d33bc2100793d60","56a7a2b8b5d0920d0051cd82","56b27fe42db51f0d0044e566"],"project":"568fde81b700ce0d002f4b43","version":"56954a94fe18811700c9bfda","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-09T16:40:53.584Z","from_sync":false,"order":4,"slug":"guides","title":"Guides"},"parentDoc":null,"project":"568fde81b700ce0d002f4b43","user":"568fffce769f210d0013258f","version":{"__v":6,"_id":"56954a94fe18811700c9bfda","project":"568fde81b700ce0d002f4b43","createdAt":"2016-01-12T18:48:52.007Z","releaseDate":"2016-01-12T18:48:52.007Z","categories":["56954a95fe18811700c9bfdb","56954a95fe18811700c9bfdc","56954a95fe18811700c9bfdd","56954a95fe18811700c9bfde","56954a95fe18811700c9bfdf","56954a95fe18811700c9bfe0","56954a95fe18811700c9bfe1","56954a95fe18811700c9bfe2","56954a95fe18811700c9bfe3","56954a95fe18811700c9bfe4","5695649fdcaf0d1700cb8721","5696c1168560a60d00e2c1d6","56a7a32e79395317007c1ad6","5898fc3eec49fb0f004c2663","589cc675ea37da23004e05e1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"foo","version_clean":"0.0.0","version":"0.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-14T18:58:46.273Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"# Contents\n\n- :fa-angle-right: [What's Supported?](#section-what-s-supported-)\n- :fa-angle-right: [Running in CI](#section-running-in-ci)\n  - [Your CI config file](#section-your-ci-config-file)\n  - [Recording your runs](#section-recording-your-runs)\n- :fa-angle-right: [Using Environment Variables](#section-using-environment-variables)\n  - [Hide your **Record Key**](#section-hide-your-record-key)\n  - [Install a specific version](#section-install-a-specific-version)\n  - [Modify configuration settings](#section-modify-configuration-settings)\n  - [Change environment variables in your tests](#section-change-environment-variables-in-your-tests)\n- :fa-angle-right: [Optimizing CI](#section-optimizing-ci)\n  - [Caching Cypress in Travis CI](#section-caching-cypress-in-travis-ci)\n  - [Caching Cypress in CircleCI](#section-caching-cypress-in-circleci)\n- :fa-angle-right: [Dependencies](#section-dependencies)\n- :fa-angle-right: [Known Issues](#section-known-issues)\n  - [CircleCI](#section-circleci)\n  - [Jenkins](#section-jenkins)\n  - [Docker](#section-docker)\n- :fa-angle-right: [Troubleshooting](#section-troubleshooting)\n  - [No output](#section-no-output)\n\n***\n\n# What's Supported?\n\nCypress should run on **all** CI providers. We currently have seen Cypress working on the following services / providers:\n\n- Jenkins (Linux)\n- TravisCI\n- CircleCI\n- CodeShip\n- GitLab\n- Docker\n\n***\n\n# Running in CI\n\nRunning Cypress in CI is just as easy as running it locally. You generally only need to do two things:\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"## 1. install the CLI tools\\nnpm install -g cypress-cli\\n\\n## 2. run cypress\\ncypress run\\n\",\n            \"language\": \"shell\"\n        }\n    ]\n}\n[/block]\n\nThat's it!\n\nThis will automatically go out and install Cypress, and then run all your tests.\n\nFor a comprehensive list of all the options you can pass to `cypress run`, [refer to the CLI documentation](https://on.cypress.io/cli).\n\n![travis-logs](https://cloud.githubusercontent.com/assets/1268976/9291527/8ea21024-4393-11e5-86b7-80e3b5d1047e.gif)\n\n***\n\n## Your CI Config File\n\nDepending on which CI provider you'll need to add these two lines (above) to a config file.\n\nFor instance with TravisCI and CircleCI we have:\n\n- `.travis.yml`\n- `circle.yml`\n\nYou'll want to refer to your CI providers documentation for knowing when to run those commands.\n\nHere's a couple example config files:\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"## .travis.yml\\n\\nbefore_install:\\n  - npm install -g cypress-cli\\n\\nscript:\\n  - cypress run\\n\",\n            \"language\": \"yaml\"\n        }\n    ]\n}\n[/block]\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"## circle.yml\\n\\ndependencies:\\n  post:\\n    - npm install -g cypress-cli\\n\\ntest:\\n  override:\\n    - cypress run\\n\",\n            \"language\": \"yaml\"\n        }\n    ]\n}\n[/block]\n\nFor more example config files check out any of our [example apps](https://on.cypress.io/guides/all-example-apps).\n\n***\n\n## Recording your runs\n\nYou can automatically have Cypress record your runs and make them available in our Dashboard.\n\nRecorded runs will contain:\n\n- Standard output\n- Failing Tests\n- Screenshots\n- Videos\n\nTo record your runs:\n\n1. [Setup your project to record](https://on.cypress.io/guides/projects)\n2. [Pass the --record flag to `cypress run`](https://on.cypress.io/how-do-i-record-runs)\n\nYou can [read more about the Dashboard here](https://on.cypress.io/guides/dashboard-features).\n\n***\n\n# Using Environment Variables\n\nYou can set various environment variables to modify how Cypress runs.\n\nTypically you'd want to do this to:\n\n- [Hide your **Record Key**](#section-hide-your-record-key)\n- [Install a specific version](#section-install-a-specific-version)\n- [Modify configuration settings](#section-modify-configuration-settings)\n- [Change environment variables in your tests](#section-change-environment-variables-in-your-tests)\n\n***\n\n## Hide your Record Key\n\nIf you are [recording your runs](#section-recording-your-runs) on a public project, you'll want to protect your Record Key. [Learn why.](https://docs.cypress.io/docs/projects#section-how-do-a-projectid-and-record-key-work-together-)\n\nInstead of hard coding it into your run command like this:\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"cypress run --record --key <record_key>\\n\",\n            \"language\": \"shell\"\n        }\n    ]\n}\n[/block]\n\nYou can set it as an environment variable and we'll automatically use that value.\n\nTypically you'd set this inside of your CI provider like this:\n\n**CircleCI**\n![screen shot 2017-02-12 at 8 56 17 pm](https://cloud.githubusercontent.com/assets/1268976/22868594/cabd8152-f165-11e6-8897-0e3e57d0eafd.png)\n\n**TravisCI**\n![screen shot 2017-02-12 at 8 58 01 pm](https://cloud.githubusercontent.com/assets/1268976/22868637/05c46e00-f166-11e6-9106-682d5729acca.png)\n\nYou can now omit the `--key` flag when recording.\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"## weeee we don't have to pass in the key here!\\ncypress run --record\\n\",\n            \"language\": \"shell\"\n        }\n    ]\n}\n[/block]\n\n***\n\n## Install a specific version\n\nYou can install a specific version of Cypress by setting the environment variable: `CYPRESS_VERSION`.\n\n**Set the version to an older Cypress**\n![screen shot 2016-03-28 at 11 28 26 am](https://cloud.githubusercontent.com/assets/1271364/14081365/601e2da4-f4d8-11e5-8ea8-0491ffcb0999.png)\n\n***\n\n## Modify configuration settings\n\nDon't forget you can also override settings in `cypress.json` to modify Cypress's behavior.\n\nTypical use cases would be modifying things like:\n\n- `CYPRESS_BASE_URL`\n- `CYPRESS_VIDEO_COMPRESSION`\n- `CYPRESS_REPORTER`\n\nRefer to the [configuration docs](https://on.cypress.io/guides/configuration#section-environment-variables) for more examples.\n\n***\n\n## Change environment variables in your tests\n\nOf course you can also set environment varibables for use strictly in your tests.\n\nThese enable your code to reference dynamic values.\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"export \\\"EXTERNAL_API_SERVER=https://corp.acme.co\\\"\\n\",\n            \"language\": \"shell\"\n        }\n    ]\n}\n[/block]\n\nAnd then in your tests:\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"cy\\n  .request({\\n    method: \\\"POST\\\",\\n    url: Cypress.env(\\\"EXTERNAL_API_SERVER\\\") + \\\"/users/1\\\",\\n    body: {\\n      foo: \\\"bar\\\",\\n      baz: \\\"quux\\\"\\n    }\\n  })\\n\",\n            \"language\": \"javascript\"\n        }\n    ]\n}\n[/block]\n\nRefer to the dedicated [Environment Variables Guide](https://on.cypress.io/guides/environment-variables) for more examples.\n\n***\n\n# Optimizing CI\n\nMost CI providers allow caching of directories and dependencies between builds. This allows you to save the state of Cypress, therefore making the builds run faster.\n\n## Caching Cypress in Travis CI\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"## .travis.yml\\n\\ncache:\\n  directories:\\n    - /home/travis/.cypress/Cypress\\n\",\n            \"language\": \"yaml\"\n        }\n    ]\n}\n[/block]\n\n***\n\n## Caching Cypress in CircleCI\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"## circle.yml\\n\\n## make sure you set the correct node version based on what you've installed!\\ndependencies:\\n  cache_directories:\\n    - /home/ubuntu/nvm/versions/node/v6.2.2/bin/cypress\\n    - /home/ubuntu/nvm/versions/node/v6.2.2/lib/node_modules/cypress-cli\\n    - /home/ubuntu/.cypress/Cypress\\n\",\n            \"language\": \"yaml\"\n        }\n    ]\n}\n[/block]\n\n***\n\n# Dependencies\n\nIf you're using a hosted CI service such as `Travis` or `CircleCI` then you don't have to install anything.\n\nFor **everything else** you must install these dependencies:\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"apt-get install xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1\\n\",\n            \"language\": \"shell\"\n        }\n    ]\n}\n[/block]\n\nIf you run `cypress run` and see no output [see this section for troubleshooting this known issue](#section-no-output).\n\n***\n\n# Known Issues\n\n## CircleCI\n\nYou need to select their [`Ubuntu 12.04` image](https://circleci.com/docs/build-image-precise/).\n\n![](https://cloud.githubusercontent.com/assets/1268976/20771195/6e93e9f4-b716-11e6-809b-f4fd8f6fa439.png)\n\nThe `Ubuntu 14.04` image does not have all of the required dependencies installed by default. You can likely install them yourself. [There is an open issue for this here.](https://github.com/cypress-io/cypress/issues/315)\n\n***\n\n## Jenkins\n\nYou need to install all of the [linux dependencies](#section-dependencies).\n\n***\n\n## Docker\n\nWe don't offer an **official** docker container, but our users have created one. [This container has all of the required dependencies installed and ready to go](https://docs.cypress.io/docs/userland-extensions#section-docker).\n\nIf you don't use this image you must install all of the [linux dependencies](#section-dependencies).\n\nSee [this issue](https://github.com/cypress-io/cypress/issues/165) for more information.\n\nIf you are running **long** runs on Docker, you need to set the `ipc` to `host` mode.\n\n[This issue](https://github.com/cypress-io/cypress/issues/350) describes exactly what to do.\n\n***\n\n# Troubleshooting\n\n## No Output\n\n**Sympton**\nAfter executing `cypress run` you don't see any output. In other words: nothing happens.\n\n**Problem**\nYou are in 100% of the cases missing [a dependency](#section-dependencies) above. Please install all of the dependencies.\n\nThe reason you're not seeing any output is a longstanding issue with Cypress which [there is an open issue for](https://github.com/cypress-io/cypress/issues/317).\n\nWe are working on improving this experience!\n\n**Seeing Errors**\nAlthough running `cypress run` will yield no output - you can see the actual dependency failure by invoking the Cypress binary directly.\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"## invoke the Cypress binary directly\\n/home/<user>/.cypress/Cypress/Cypress\\n\",\n            \"language\": \"shell\"\n        }\n    ]\n}\n[/block]","excerpt":"Run Cypress in any CI provider","slug":"continuous-integration","type":"basic","title":"Continuous Integration"}

Continuous Integration

Run Cypress in any CI provider

# Contents - :fa-angle-right: [What's Supported?](#section-what-s-supported-) - :fa-angle-right: [Running in CI](#section-running-in-ci) - [Your CI config file](#section-your-ci-config-file) - [Recording your runs](#section-recording-your-runs) - :fa-angle-right: [Using Environment Variables](#section-using-environment-variables) - [Hide your **Record Key**](#section-hide-your-record-key) - [Install a specific version](#section-install-a-specific-version) - [Modify configuration settings](#section-modify-configuration-settings) - [Change environment variables in your tests](#section-change-environment-variables-in-your-tests) - :fa-angle-right: [Optimizing CI](#section-optimizing-ci) - [Caching Cypress in Travis CI](#section-caching-cypress-in-travis-ci) - [Caching Cypress in CircleCI](#section-caching-cypress-in-circleci) - :fa-angle-right: [Dependencies](#section-dependencies) - :fa-angle-right: [Known Issues](#section-known-issues) - [CircleCI](#section-circleci) - [Jenkins](#section-jenkins) - [Docker](#section-docker) - :fa-angle-right: [Troubleshooting](#section-troubleshooting) - [No output](#section-no-output) *** # What's Supported? Cypress should run on **all** CI providers. We currently have seen Cypress working on the following services / providers: - Jenkins (Linux) - TravisCI - CircleCI - CodeShip - GitLab - Docker *** # Running in CI Running Cypress in CI is just as easy as running it locally. You generally only need to do two things: [block:code] { "codes": [ { "code": "## 1. install the CLI tools\nnpm install -g cypress-cli\n\n## 2. run cypress\ncypress run\n", "language": "shell" } ] } [/block] That's it! This will automatically go out and install Cypress, and then run all your tests. For a comprehensive list of all the options you can pass to `cypress run`, [refer to the CLI documentation](https://on.cypress.io/cli). ![travis-logs](https://cloud.githubusercontent.com/assets/1268976/9291527/8ea21024-4393-11e5-86b7-80e3b5d1047e.gif) *** ## Your CI Config File Depending on which CI provider you'll need to add these two lines (above) to a config file. For instance with TravisCI and CircleCI we have: - `.travis.yml` - `circle.yml` You'll want to refer to your CI providers documentation for knowing when to run those commands. Here's a couple example config files: [block:code] { "codes": [ { "code": "## .travis.yml\n\nbefore_install:\n - npm install -g cypress-cli\n\nscript:\n - cypress run\n", "language": "yaml" } ] } [/block] [block:code] { "codes": [ { "code": "## circle.yml\n\ndependencies:\n post:\n - npm install -g cypress-cli\n\ntest:\n override:\n - cypress run\n", "language": "yaml" } ] } [/block] For more example config files check out any of our [example apps](https://on.cypress.io/guides/all-example-apps). *** ## Recording your runs You can automatically have Cypress record your runs and make them available in our Dashboard. Recorded runs will contain: - Standard output - Failing Tests - Screenshots - Videos To record your runs: 1. [Setup your project to record](https://on.cypress.io/guides/projects) 2. [Pass the --record flag to `cypress run`](https://on.cypress.io/how-do-i-record-runs) You can [read more about the Dashboard here](https://on.cypress.io/guides/dashboard-features). *** # Using Environment Variables You can set various environment variables to modify how Cypress runs. Typically you'd want to do this to: - [Hide your **Record Key**](#section-hide-your-record-key) - [Install a specific version](#section-install-a-specific-version) - [Modify configuration settings](#section-modify-configuration-settings) - [Change environment variables in your tests](#section-change-environment-variables-in-your-tests) *** ## Hide your Record Key If you are [recording your runs](#section-recording-your-runs) on a public project, you'll want to protect your Record Key. [Learn why.](https://docs.cypress.io/docs/projects#section-how-do-a-projectid-and-record-key-work-together-) Instead of hard coding it into your run command like this: [block:code] { "codes": [ { "code": "cypress run --record --key <record_key>\n", "language": "shell" } ] } [/block] You can set it as an environment variable and we'll automatically use that value. Typically you'd set this inside of your CI provider like this: **CircleCI** ![screen shot 2017-02-12 at 8 56 17 pm](https://cloud.githubusercontent.com/assets/1268976/22868594/cabd8152-f165-11e6-8897-0e3e57d0eafd.png) **TravisCI** ![screen shot 2017-02-12 at 8 58 01 pm](https://cloud.githubusercontent.com/assets/1268976/22868637/05c46e00-f166-11e6-9106-682d5729acca.png) You can now omit the `--key` flag when recording. [block:code] { "codes": [ { "code": "## weeee we don't have to pass in the key here!\ncypress run --record\n", "language": "shell" } ] } [/block] *** ## Install a specific version You can install a specific version of Cypress by setting the environment variable: `CYPRESS_VERSION`. **Set the version to an older Cypress** ![screen shot 2016-03-28 at 11 28 26 am](https://cloud.githubusercontent.com/assets/1271364/14081365/601e2da4-f4d8-11e5-8ea8-0491ffcb0999.png) *** ## Modify configuration settings Don't forget you can also override settings in `cypress.json` to modify Cypress's behavior. Typical use cases would be modifying things like: - `CYPRESS_BASE_URL` - `CYPRESS_VIDEO_COMPRESSION` - `CYPRESS_REPORTER` Refer to the [configuration docs](https://on.cypress.io/guides/configuration#section-environment-variables) for more examples. *** ## Change environment variables in your tests Of course you can also set environment varibables for use strictly in your tests. These enable your code to reference dynamic values. [block:code] { "codes": [ { "code": "export \"EXTERNAL_API_SERVER=https://corp.acme.co\"\n", "language": "shell" } ] } [/block] And then in your tests: [block:code] { "codes": [ { "code": "cy\n .request({\n method: \"POST\",\n url: Cypress.env(\"EXTERNAL_API_SERVER\") + \"/users/1\",\n body: {\n foo: \"bar\",\n baz: \"quux\"\n }\n })\n", "language": "javascript" } ] } [/block] Refer to the dedicated [Environment Variables Guide](https://on.cypress.io/guides/environment-variables) for more examples. *** # Optimizing CI Most CI providers allow caching of directories and dependencies between builds. This allows you to save the state of Cypress, therefore making the builds run faster. ## Caching Cypress in Travis CI [block:code] { "codes": [ { "code": "## .travis.yml\n\ncache:\n directories:\n - /home/travis/.cypress/Cypress\n", "language": "yaml" } ] } [/block] *** ## Caching Cypress in CircleCI [block:code] { "codes": [ { "code": "## circle.yml\n\n## make sure you set the correct node version based on what you've installed!\ndependencies:\n cache_directories:\n - /home/ubuntu/nvm/versions/node/v6.2.2/bin/cypress\n - /home/ubuntu/nvm/versions/node/v6.2.2/lib/node_modules/cypress-cli\n - /home/ubuntu/.cypress/Cypress\n", "language": "yaml" } ] } [/block] *** # Dependencies If you're using a hosted CI service such as `Travis` or `CircleCI` then you don't have to install anything. For **everything else** you must install these dependencies: [block:code] { "codes": [ { "code": "apt-get install xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1\n", "language": "shell" } ] } [/block] If you run `cypress run` and see no output [see this section for troubleshooting this known issue](#section-no-output). *** # Known Issues ## CircleCI You need to select their [`Ubuntu 12.04` image](https://circleci.com/docs/build-image-precise/). ![](https://cloud.githubusercontent.com/assets/1268976/20771195/6e93e9f4-b716-11e6-809b-f4fd8f6fa439.png) The `Ubuntu 14.04` image does not have all of the required dependencies installed by default. You can likely install them yourself. [There is an open issue for this here.](https://github.com/cypress-io/cypress/issues/315) *** ## Jenkins You need to install all of the [linux dependencies](#section-dependencies). *** ## Docker We don't offer an **official** docker container, but our users have created one. [This container has all of the required dependencies installed and ready to go](https://docs.cypress.io/docs/userland-extensions#section-docker). If you don't use this image you must install all of the [linux dependencies](#section-dependencies). See [this issue](https://github.com/cypress-io/cypress/issues/165) for more information. If you are running **long** runs on Docker, you need to set the `ipc` to `host` mode. [This issue](https://github.com/cypress-io/cypress/issues/350) describes exactly what to do. *** # Troubleshooting ## No Output **Sympton** After executing `cypress run` you don't see any output. In other words: nothing happens. **Problem** You are in 100% of the cases missing [a dependency](#section-dependencies) above. Please install all of the dependencies. The reason you're not seeing any output is a longstanding issue with Cypress which [there is an open issue for](https://github.com/cypress-io/cypress/issues/317). We are working on improving this experience! **Seeing Errors** Although running `cypress run` will yield no output - you can see the actual dependency failure by invoking the Cypress binary directly. [block:code] { "codes": [ { "code": "## invoke the Cypress binary directly\n/home/<user>/.cypress/Cypress/Cypress\n", "language": "shell" } ] } [/block]