Let's imagine you have a
Dev environment and a
QA environment, both of which you want to test with the same Cypress code - and you want to send results to the Cypress Dashboard. You may have found that after creating your project in the Dashboard, you are instructed to include the
projectId key in your
cypress.json file. From your
package.json, you might have some test scripts, let's say
test:qa which will report to the Cypress Dashboard via the flags
--record --key and then the long "Record Key" provided in the Cypress Dashboard.
Great, all well and good, but how can you report these two environments out separately to the dashboard, given that you must insert the short 6-character "Project ID" in your
cypress.json file? If you try to set these as environmental variables, you'll get a warning that the key is missing from
cypress.json and the tests will not report.
There are a few hacky ways to get around this, but the easiest way I've found is to simply insert
CYPRESS_PROJECT_ID=abcdef into your test scripts before the
cypress run keywords. This works as a consequence of variable expansion magic.
Note that if you take this approach and set up two separate projects in your Cypress Dashboard, you'll also have two Record Keys to work with, so you must make those unique in your test scripts.
Hopefully this saves you an afternoon of searching.