# e2eTests

Run end-to-end tests from the [cucumber-cypress-tests](https://github.com/theorchard/cucumber-cypress-tests) repository.

## Parameters
| Name                                                                                                                   | Description                                                                                                                              | Type                                                                                            | Default                | Required |
|------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|------------------------|----------|
| **Cucumber cypress parameters**                                                                                        |
| tags                                                                                                                   | The name of the tag to filter our sceanrios                                                                                              | `string`                                                                                        | n/a                    | yes      |
| makeTarget                                                                                                             | The name of the make target to invoke to run the tests.                                                                                  | `string`                                                                                        | `cypress_run_parallel` | no       |
| configFile                                                                                                             | The name of the configuration file to load                                                                                               | `string`                                                                                        | 'qa'                   | no       |
| envVars                                                                                                                |                                                                                                                                          | The custom environment variables passed to runner                                               | `Map`                  | null                   | no       |
| **Environment Variables can be passed under envVars without need to change this repository, see below for an example** |
|                                                                                                                        | - tries                                                                                                                                  | The number of times that E2E tests reruns using the rerun plugin                                | `integer`              | `1`                    | no       |
|                                                                                                                        | - dd_env                                                                                                                                 | The name of the datadog env                                                                     | `string`               | `qa`                   | no       |
|                                                                                                                        | - cypress_test_wise                                                                                                                      | Set wise to true to test wise integration                                                       | `string`               | `false`                | no       |
|                                                                                                                        | - no_video                                                                                                                               | set this to true to disable video recording                                                     | `string`               | `false`                | no       |
|                                                                                                                        | - cypress_override_frontend_host                                                                                                         | Set this to a pr url to run suite agains a pr environment                                       | `string`               | `qaorch or theorchard` | no       |
|                                                                                                                        | - cypress_default_command_timeout                                                                                                        | Set this to a number in millis to inccreas or decrease command waiting time                     | `integer`              | `time in millis`       | no       |
|                                                                                                                        | - delay                                                                                                                                  | The delay needed between the first run and the rerun in case of failures using the rerun plugin | `integer`              | `0`                    | no       |
|                                                                                                                        | - debug                                                                                                                                  | The number of times that E2E tests reties                                                       | `string`               | `false`                | no       |
|                                                                                                                        | - setupMakeCommand                                                                                                                       | `make` target name that has to be executed prior main e2e suite                                 | `string`               | `false`                | no       |
| checkoutSubDir                                                                                                         | The name of the sub directory where we checkout the cucumber-cypress-tests repo.                                                         | `string`                                                                                        | `default`              | no       |
| frameworkEnvironment                                                                                                   | The framework environment you wish to run the tests on, either 'qa' or 'prod'.                                                           | `string`                                                                                        | `prod`                 | no       |
| branchName                                                                                                             | The branch which has changes in the <a href="https://github.com/theorchard/cucumber-cypress-tests">cucumber-cypress-tests</a> repository | `string`                                                                                        | `master`               | no       |
| githubUser                                                                                                             | Your github user name                                                                                                                    | `string`                                                                                        | `theorchard`           | no       |
| rerunFargate                                                                                                           | Enable to rerun all fails in a fresh fargate environment. This is for especially flaky jobs                                              | `boolean`                                                                                       | false                  | no       |
| reportTitle                                                                                                            | The title of the cucumber test report                                                                                                    | `string`                                                                                        | `QA-Env-E2E-Tests`     | no       |

## Usage

```groovy
stage('Cypress Frontend - SUITE APP e2e') {
    when {
        branch 'master'
    }
    parallel {
        stage('Cypress Cucumber E2E tests') {
            steps {
                e2eTests tags: ['@frontend_collaborators'], envVars: [CYPRESS_TEST_WISE:'true', DD_ENV:'qa']
            }
        }
    }
}
```

### Parallel stages
If your Jenkinsfile runs e2e tests in parallel stages then you need to specify a unique checkout dir for each stage.
If not, the cucumber-cypress-tests will try to do multiple checkouts into the same folder at the same time. 
This will usually cause issues and the stages fail.
Use the `checkoutSubDir` parameter to specify a unique directory for each stage to prevent concurrency issues.

```groovy
stage('Performance Tests') {
    when {
        branch 'master'
    }
    parallel {
        stage('QA Performance Tests') {
            steps {
                e2eTests makeTarget: "cypress_run_performance", checkoutSubDir: 'insights-perf-qa'
            }
        }
        stage('Prod Performance Tests') {
            when {
                expression { params.DEPLOY_TO_PROD == 'Yes' }
            }
            steps {
                e2eTests makeTarget: "cypress_run_performance_prod", checkoutSubDir: 'insights-perf-prod'
            }
        }
    }
}
```

### Retries
We have 2 levels of retry in the framework. The tries variable indicates the number of tries within a docker container run in fargate, the rerunFargate flag enables a full rerun of the fails in a fresh container
in fargate. By default, we use 2 tries. Meaning we will trigger a container and try the tests up to 2 times. If you have a particularly flaky job you can enable rerunFargate, but this of course comes with
spee costs.
