Skip to content

Commit

Permalink
feat(actions): add "When I set environment variable"
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 25, 2023
1 parent 0dd12ee commit 6f28951
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/actions/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { When } from '@badeball/cypress-cucumber-preprocessor';

/**
* When I set environment variable:
*
* ```gherkin
* When I set environment variable {string} to {string}
* ```
*
* @example
*
* Set environment variable `host` to `http://server.dev.local`:
*
* ```gherkin
* When I set evironment variable "host" to "http://server.dev.local"
* ```
*
* @remarks
*
* **Scope**
*
* Environment variables set using `Cypress.env` _are only in scope for the current spec file_.
*
* Cypress runs each spec file in isolation: the browser is exited between specs. Environment variables added or changed in one spec won't be visible in other specs.
*
* **Difference between OS-level and Cypress environment variables**
*
* In Cypress, "environment variables" are variables that are accessible via `Cypress.env`. These are not the same as OS-level environment variables. However, **it is possible to set Cypress environment variables from OS-level environment variables**.
*/
export function When_I_set_environment_variable(key: string, value: string) {
Cypress.env(key, value);
}

When(
'I set environment variable {string} to {string}',
When_I_set_environment_variable
);
1 change: 1 addition & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './config';
export * from './cookie';
export * from './debug';
export * from './double-click';
export * from './env';
export * from './focus';
export * from './go';
export * from './intercept';
Expand Down

0 comments on commit 6f28951

Please sign in to comment.