Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate existing Cypress tests to Cypress + Cucumber #57299

Merged
merged 38 commits into from
Feb 26, 2020

Conversation

mdelapenya
Copy link
Contributor

@mdelapenya mdelapenya commented Feb 11, 2020

Summary

It converts the existing Cypress tests for APM from Cypress to Cypress+Cucumber. To achieve that, it adds a cucumber-preprocessor, as shown in the following examples:

The cypress tests are run using the same npm run cypress:run script, so no CI command should be affected.

To follow a proper Cypress layout, we enclosed the end-to-end (e2e) tests under the x-pack/legacy/plugins/apm/e2e directory, where its own package.json will be located, controlling the life cycle if these tests. Then, a cypress directory will contain the implementation of the e2e tests.

We've kept the buid dependencies under apm/e2e because we consider having the testime dependencies isolated from other plugins is important for the sake of running the test during local developement with a nice experience.

Checklist

- [ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support

For maintainers

- [ ] This was checked for breaking API changes and was labeled appropriately

Steps to run the tests

Please follow instructions in the README of the APM UI tests:

  1. Start Elasticsearch and APM Server, using apm-integration-testing:
$ git clone https://github.com/elastic/apm-integration-testing.git
$ cd apm-integration-testing
$ ./scripts/compose.py start master --no-kibana --no-xpack-secure
  1. Download static data file
$ cd x-pack/legacy/plugins/apm/e2e/cypress/ingest-data
$ curl https://storage.googleapis.com/apm-ui-e2e-static-data/events.json --output events.json
  1. Post to APM Server
$ cd x-pack/legacy/plugins/apm/e2e/cypress/ingest-data
$ node replay.js --server-url http://localhost:8200 --secret-token abcd --events ./events.json

This process will take a few minutes to ingest all data

  1. Start Kibana
$ yarn kbn bootstrap
$ yarn start --no-base-path --csp.strict=false

Screenshots

Feature file

Screenshot 2020-02-20 at 13 39 26

Tests passing locally in headless mode (npm run cypress:run):

Screenshot 2020-02-20 at 09 35 58

Tests passing locally using Cypress app (npm run cypress:open):

e2e

Related Issues

@mdelapenya mdelapenya requested review from a team as code owners February 11, 2020 10:24
@mdelapenya mdelapenya added the Team:APM All issues that need APM UI Team support label Feb 11, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:apm)

@mdelapenya mdelapenya added release_note:skip Skip the PR/issue when compiling release notes v7.6.0 labels Feb 11, 2020
@mdelapenya mdelapenya requested a review from v1v February 11, 2020 10:26
@@ -94,7 +94,7 @@ pipeline {
dir("${BASE_DIR}"){
sh '''
jobs -l
docker build --tag cypress ${CYPRESS_DIR}/ci
docker build --tag cypress --build-arg NODE_VERSION=$(cat .node-version) ${CYPRESS_DIR}/ci
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we capture project's Node version from root directory

Comment on lines +59 to +66
# Prepare and run Kibana locally
$ x-pack/legacy/plugins/apm/e2e/ci/prepare-kibana.sh
# Build Docker image for Kibana
$ docker build --tag cypress --build-arg NODE_VERSION=$(cat .node-version) x-pack/legacy/plugins/apm/e2e/ci
# Run Docker image
$ docker run --rm -t --user "$(id -u):$(id -g)" \
-v `pwd`:/app --network="host" \
--name cypress cypress
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified that these steps works locally: the tests pass, although very slow
Screenshot 2020-02-11 at 11 31 53


Background:
Given a user browses the APM UI application
When the user inspects the opbeans-go service
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MadameSheema how do you see having a When clause in a Background? I'm not completely sure if moving this line to the Scenario itself would be a more accurate approach. wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!! Sorry for my late reply, I was a little bit busy. I don't like to use Backgrounds at all. This is because if you have a big file in a feature you can skip it when reading it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A part from what I said in the previous comment. If you only have one scenario, it does not make sense to have a background at all :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was preparing for future updates... but I agree with you :) I'll send a commit moving the background step to the scenario. Thanks!!!

@@ -5,17 +5,20 @@
"license": "MIT",
"scripts": {
"cypress:open": "cypress open",
"cypress:run": "cypress run"
"cypress:run": "cypress run --spec **/*.feature"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are keeping the build scripts using the installed Cypress

x-pack/legacy/plugins/apm/e2e/README.md Outdated Show resolved Hide resolved
x-pack/legacy/plugins/apm/e2e/README.md Outdated Show resolved Hide resolved
@mdelapenya
Copy link
Contributor Author

After #57882 is merged, we can continue with this one, as the cypress+cucumber tests will not be type checked by upstream build.

It seems not relevant to the main purpose of these tests
We are keeping cypress as rootDir to follow project's structure. On the other hand,
having a second cypress directory at the 2nd level is the default structure, as shown
in the examples:
- https://github.com/TheBrainFamily/cypress-cucumber-webpack-typescript-example
- https://github.com/cypress-io/cypress-example-recipes/tree/a240054d7f5626ffcd7bd668dded96d219c4a7eb/examples/preprocessors__typescript-webpack
It was automatically changed by tests
@mdelapenya mdelapenya requested a review from sorenlouv February 19, 2020 10:26
@mdelapenya
Copy link
Contributor Author

Hey @elastic/kibana-operations, is there anything we missed on our side here?

Thanks!

@mdelapenya
Copy link
Contributor Author

@elasticmachine merge upstream

elasticmachine and others added 2 commits February 26, 2020 03:49
This would avoid not reading the background when the number of scenarios grows
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@jbudz jbudz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops files LGTM

@ogupte ogupte merged commit d27b6c0 into elastic:master Feb 26, 2020
ogupte pushed a commit to ogupte/kibana that referenced this pull request Feb 26, 2020
* chore: move gitignore to the cypress directory

* chore: ignore more test files

* fix: do not check the Loading Message

It seems not relevant to the main purpose of these tests

* chore: use cypres + webpack + cucumber scaffolding

See https://github.com/TheBrainFamily/cypress-cucumber-webpack-typescript-example

* chore: add eslint and prettier for code linting

* feat: convert existing Cypress test into BDD style

* feat: add support for using proper Node version in MacOSX

* chore: use tslint

* chore: use old layout

We are keeping cypress as rootDir to follow project's structure. On the other hand,
having a second cypress directory at the 2nd level is the default structure, as shown
in the examples:
- https://github.com/TheBrainFamily/cypress-cucumber-webpack-typescript-example
- https://github.com/cypress-io/cypress-example-recipes/tree/a240054d7f5626ffcd7bd668dded96d219c4a7eb/examples/preprocessors__typescript-webpack

* chore: remove prelint script meanwhile we fix TS lint

* chore: move test results to a specific directory

* chore: rename variable following old code

* chore: remove non-needed lints, as we are going to use kibana build

* chore: import snapshot function from cypress

* chore: add readFile utils back from a bad removal

* chore: change format of JSON spec file

It was automatically changed by tests

* chore: move CI directory to the proper layout in order for Jenkins to work

* chore: store test-results from proper dir on Jenkins

* chore: store artifacts properly on Jenkins

* Fix type issues

* chore: rename test application to e2e (end-to-end)

We are keeping the build system within the test application, isolating dependencies

* docs: reorganise docs for APM UI e2e tests

* fix: Use proper cypress support file

* chore: use existing NPM script for running cypress on CI

* chore: update paths in CI scripts

* docs: document how the CI runs the tests

* chore: use Node 10 for tests

* chore: Use kibana's Node version for tests

* chore: run yarn install

* docs: update docs

* fix: path was wrong

* docs: fix paths and flags used to load data

* docs: elasticsearch fix flag

* docs: Bootstrap kibana before running it

* docs: remove outdated info

* chore: move background steps to the scenario

This would avoid not reading the background when the number of scenarios grows

Co-authored-by: Dario Gieselaar <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
ogupte added a commit that referenced this pull request Feb 27, 2020
* chore: move gitignore to the cypress directory

* chore: ignore more test files

* fix: do not check the Loading Message

It seems not relevant to the main purpose of these tests

* chore: use cypres + webpack + cucumber scaffolding

See https://github.com/TheBrainFamily/cypress-cucumber-webpack-typescript-example

* chore: add eslint and prettier for code linting

* feat: convert existing Cypress test into BDD style

* feat: add support for using proper Node version in MacOSX

* chore: use tslint

* chore: use old layout

We are keeping cypress as rootDir to follow project's structure. On the other hand,
having a second cypress directory at the 2nd level is the default structure, as shown
in the examples:
- https://github.com/TheBrainFamily/cypress-cucumber-webpack-typescript-example
- https://github.com/cypress-io/cypress-example-recipes/tree/a240054d7f5626ffcd7bd668dded96d219c4a7eb/examples/preprocessors__typescript-webpack

* chore: remove prelint script meanwhile we fix TS lint

* chore: move test results to a specific directory

* chore: rename variable following old code

* chore: remove non-needed lints, as we are going to use kibana build

* chore: import snapshot function from cypress

* chore: add readFile utils back from a bad removal

* chore: change format of JSON spec file

It was automatically changed by tests

* chore: move CI directory to the proper layout in order for Jenkins to work

* chore: store test-results from proper dir on Jenkins

* chore: store artifacts properly on Jenkins

* Fix type issues

* chore: rename test application to e2e (end-to-end)

We are keeping the build system within the test application, isolating dependencies

* docs: reorganise docs for APM UI e2e tests

* fix: Use proper cypress support file

* chore: use existing NPM script for running cypress on CI

* chore: update paths in CI scripts

* docs: document how the CI runs the tests

* chore: use Node 10 for tests

* chore: Use kibana's Node version for tests

* chore: run yarn install

* docs: update docs

* fix: path was wrong

* docs: fix paths and flags used to load data

* docs: elasticsearch fix flag

* docs: Bootstrap kibana before running it

* docs: remove outdated info

* chore: move background steps to the scenario

This would avoid not reading the background when the number of scenarios grows

Co-authored-by: Dario Gieselaar <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Manuel de la Peña <[email protected]>
Co-authored-by: Dario Gieselaar <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support v7.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants