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

[Fleet] cypress setup #113106

Merged
merged 71 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
3cb4113
added cypress setup for fleet
juliaElastic Sep 27, 2021
d74478d
Merge branch 'elastic:master' into fleet-cypress
juliaElastic Sep 27, 2021
648bf47
updated readme
juliaElastic Sep 27, 2021
7099dc1
fixed types
juliaElastic Sep 27, 2021
bb21e5c
fix unused
juliaElastic Sep 27, 2021
98164cf
starting up fleet server in cypress
juliaElastic Sep 28, 2021
5f28762
added more fleet tests
juliaElastic Sep 28, 2021
4261fde
added package update test
juliaElastic Sep 29, 2021
72fa3f7
updated readme
juliaElastic Sep 29, 2021
f47cafd
trying jenkins run
juliaElastic Sep 29, 2021
6c557ef
trying jenkins run
juliaElastic Sep 29, 2021
ec6714e
trying jenkins run
juliaElastic Sep 29, 2021
9411f5d
fix types, cypress config
juliaElastic Sep 29, 2021
f1e8984
Merge branch 'master' into fleet-cypress
kibanamachine Sep 29, 2021
15ddd5c
example of mocked requests
juliaElastic Sep 30, 2021
8fa29b3
Merge branch 'master' into fleet-cypress
juliaElastic Sep 30, 2021
9464634
Merge branch 'master' into fleet-cypress
kibanamachine Oct 1, 2021
a3983bd
added getBySel
juliaElastic Oct 1, 2021
f285b11
Merge branch 'master' into fleet-cypress
kibanamachine Oct 4, 2021
2f7bacd
fix test after refactor
juliaElastic Oct 4, 2021
a4896df
Merge branch 'master' into fleet-cypress
kibanamachine Oct 7, 2021
10b67ac
Merge branch 'master' into fleet-cypress
kibanamachine Oct 11, 2021
a8fdde8
removed duplication
juliaElastic Oct 11, 2021
2f6ccc9
Merge branch 'fleet-cypress' of https://github.com/juliaElastic/kiban…
juliaElastic Oct 11, 2021
2019a5b
fix tests
juliaElastic Oct 11, 2021
0dca80c
Merge branch 'elastic:master' into fleet-cypress
juliaElastic Oct 11, 2021
c0daca1
Merge branch 'master' into fleet-cypress
kibanamachine Oct 13, 2021
ef7dd15
Merge branch 'master' into fleet-cypress
kibanamachine Oct 18, 2021
6c0c44e
Merge branch 'master' into fleet-cypress
kibanamachine Oct 20, 2021
d4f8c62
Merge branch 'master' into fleet-cypress
kibanamachine Oct 21, 2021
b47d46c
added to buildkite
juliaElastic Oct 21, 2021
2566117
Merge branch 'master' into fleet-cypress
kibanamachine Oct 21, 2021
5d7b7b1
updated tests
juliaElastic Oct 21, 2021
d78ff94
Merge branch 'fleet-cypress' of https://github.com/juliaElastic/kiban…
juliaElastic Oct 21, 2021
a0d6e17
Merge branch 'master' into fleet-cypress
kibanamachine Oct 24, 2021
1628a93
starting agent with docker
juliaElastic Oct 26, 2021
71f58a8
Merge branch 'fleet-cypress' of https://github.com/juliaElastic/kiban…
juliaElastic Oct 26, 2021
8e04d5a
trying to fix ip address
juliaElastic Oct 26, 2021
7f21722
ifconfig
juliaElastic Oct 26, 2021
7b796dd
ip address
juliaElastic Oct 26, 2021
a9ed685
ip address
juliaElastic Oct 26, 2021
bb6e4e9
ip address
juliaElastic Oct 26, 2021
0514434
type fix
juliaElastic Oct 26, 2021
8ba315a
remove extra logging
juliaElastic Oct 26, 2021
7298bc8
fixed test
juliaElastic Oct 26, 2021
6b5a2c8
fix buildkite
juliaElastic Oct 26, 2021
fb00562
Merge branch 'master' into fleet-cypress
kibanamachine Oct 26, 2021
8858ed7
Merge branch 'master' into fleet-cypress
kibanamachine Oct 27, 2021
1051cc8
Merge branch 'master' into fleet-cypress
kibanamachine Oct 28, 2021
265020a
cleanup
juliaElastic Oct 28, 2021
8586adf
cleanup
juliaElastic Oct 28, 2021
94ca5e6
using docker for fleet_server
juliaElastic Oct 28, 2021
c86ed5a
fix
juliaElastic Oct 28, 2021
893687c
fix
juliaElastic Oct 28, 2021
e550286
trying to fix
juliaElastic Oct 28, 2021
bd01ccb
Merge branch 'master' of github.com:elastic/kibana into fleet-cypress
patrykkopycinski Oct 29, 2021
4a5d233
update config
patrykkopycinski Oct 29, 2021
9d63e66
test
patrykkopycinski Oct 29, 2021
c22af32
test
patrykkopycinski Oct 29, 2021
cd83d72
test
patrykkopycinski Oct 29, 2021
66e87ba
test
patrykkopycinski Oct 29, 2021
10d36bf
revert changes
patrykkopycinski Oct 29, 2021
722994a
test
patrykkopycinski Oct 29, 2021
3faaa90
test
patrykkopycinski Oct 29, 2021
6bf2915
Merge branch 'main' into fleet-cypress
kibanamachine Nov 1, 2021
ebb8f64
static ip on linux
juliaElastic Nov 1, 2021
2a65c57
docker version
juliaElastic Nov 1, 2021
db35a93
try again
juliaElastic Nov 1, 2021
c29d688
fixed review comments
juliaElastic Nov 2, 2021
7819abc
fixed types
juliaElastic Nov 2, 2021
ce6c85b
Merge branch 'main' into fleet-cypress
kibanamachine Nov 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .buildkite/pipelines/pull_request/fleet_cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
- command: .buildkite/scripts/steps/functional/fleet_cypress.sh
label: 'Fleet Cypress Tests'
agents:
queue: ci-group-6
depends_on: build
timeout_in_minutes: 120
retry:
automatic:
- exit_status: '*'
limit: 1
10 changes: 10 additions & 0 deletions .buildkite/scripts/pipelines/pull_request/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ const uploadPipeline = (pipelineContent) => {
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/apm_cypress.yml'));
}

if (
(await doAnyChangesMatch([
/^x-pack\/plugins\/fleet/,
/^x-pack\/test\/fleet_cypress/,
])) ||
process.env.GITHUB_PR_LABELS.includes('ci:all-cypress-suites')
) {
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/fleet_cypress.yml'));
}

if (await doAnyChangesMatch([/^x-pack\/plugins\/uptime/])) {
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/uptime.yml'));
}
Expand Down
20 changes: 20 additions & 0 deletions .buildkite/scripts/steps/functional/fleet_cypress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -euo pipefail

source .buildkite/scripts/common/util.sh

.buildkite/scripts/bootstrap.sh
.buildkite/scripts/download_build_artifacts.sh

export JOB=kibana-fleet-cypress

echo "--- Fleet Cypress tests"

cd "$XPACK_DIR"

checks-reporter-with-killswitch "Fleet Cypress Tests" \
node scripts/functional_tests \
--debug --bail \
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \
--config test/fleet_cypress/cli_config.ts
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ report.asciidoc
/bazel
/bazel-*
.bazelrc.user

elastic-agent-*
fleet-server-*
elastic-agent.yml
fleet-server.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: new line

3 changes: 3 additions & 0 deletions src/dev/typescript/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export const PROJECTS = [
name: 'apm/ftr_e2e',
disableTypeCheck: true,
}),
createProject('x-pack/plugins/fleet/cypress/tsconfig.json', {
name: 'fleet/cypress',
}),

createProject('x-pack/plugins/uptime/e2e/tsconfig.json', {
name: 'uptime/synthetics-e2e-tests',
Expand Down
15 changes: 15 additions & 0 deletions test/scripts/jenkins_fleet_cypress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

source test/scripts/jenkins_test_setup_xpack.sh

echo " -> Running fleet cypress tests"
cd "$XPACK_DIR"

checks-reporter-with-killswitch "Fleet Cypress Tests" \
node scripts/functional_tests \
--debug --bail \
--kibana-install-dir "$KIBANA_INSTALL_DIR" \
--config test/fleet_cypress/cli_config.ts

echo ""
echo ""
8 changes: 8 additions & 0 deletions vars/tasks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ def functionalXpack(Map params = [:]) {
task(kibanaPipeline.functionalTestProcess('xpack-UptimePlaywright', './test/scripts/jenkins_uptime_playwright.sh'))
}
}

whenChanged([
juliaElastic marked this conversation as resolved.
Show resolved Hide resolved
'x-pack/plugins/fleet/',
]) {
if (githubPr.isPr()) {
task(kibanaPipeline.functionalTestProcess('xpack-FleetCypress', './test/scripts/jenkins_fleet_cypress.sh'))
}
}

}
}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
elastic-agent-*
fleet-server-*
elastic-agent.yml
fleet-server.yml
148 changes: 148 additions & 0 deletions x-pack/plugins/fleet/cypress/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Cypress Tests

The `fleet/cypress` directory contains functional UI tests that execute using [Cypress](https://www.cypress.io/).

## Running the tests

There are currently three ways to run the tests, comprised of two execution modes and two target environments, which will be detailed below.

### Execution modes

#### Interactive mode

When you run Cypress in interactive mode, an interactive runner is displayed that allows you to see commands as they execute while also viewing the application under test. For more information, please see [cypress documentation](https://docs.cypress.io/guides/core-concepts/test-runner.html#Overview).

#### Headless mode

A headless browser is a browser simulation program that does not have a user interface. These programs operate like any other browser, but do not display any UI. This is why meanwhile you are executing the tests on this mode you are not going to see the application under test. Just the output of the test is displayed on the terminal once the execution is finished.

### Target environments

#### FTR (CI)

This is the configuration used by CI. It uses the FTR to spawn both a Kibana instance (http://localhost:5620) and an Elasticsearch instance (http://localhost:9220) with a preloaded minimum set of data (see preceding "Test data" section), and then executes cypress against this stack. You can find this configuration in `x-pack/test/fleet_cypress`

### Test Execution: Examples

#### FTR + Headless (Chrome)

Since this is how tests are run on CI, this will likely be the configuration you want to reproduce failures locally, etc.

```shell
# bootstrap kibana from the project root
yarn kbn bootstrap

# build the plugins/assets that cypress will execute against
node scripts/build_kibana_platform_plugins

# launch the cypress test runner
cd x-pack/plugins/fleet
yarn cypress:run-as-ci
```
#### FTR + Interactive

This is the preferred mode for developing new tests.

```shell
# bootstrap kibana from the project root
yarn kbn bootstrap

# build the plugins/assets that cypress will execute against
node scripts/build_kibana_platform_plugins

# launch the cypress test runner
cd x-pack/plugins/fleet
yarn cypress:open-as-ci
```

Alternatively, kibana test server can be started separately, to pick up changes in UI (e.g. change in data-test-subj selector)

```
# launch kibana test server
node scripts/functional_tests_server --config x-pack/test/fleet_cypress/config.ts

# launch cypress runner
node scripts/functional_test_runner --config x-pack/test/fleet_cypress/visual_config.ts
```

Note that you can select the browser you want to use on the top right side of the interactive runner.

## Folder Structure

### integration/

Cypress convention. Contains the specs that are going to be executed.

### fixtures/

Cypress convention. Fixtures are used as external pieces of static data when we stub responses.

### plugins/

Cypress convention. As a convenience, by default Cypress will automatically include the plugins file cypress/plugins/index.js before every single spec file it runs.

### screens/

Contains the elements we want to interact with in our tests.

Each file inside the screens folder represents a screen in our application.

### tasks/

_Tasks_ are functions that may be reused across tests.

Each file inside the tasks folder represents a screen of our application.

## Test data

The data the tests need:

- Is generated on the fly using our application APIs (preferred way)
- Is ingested on the ELS instance using the `es_archive` utility

### How to generate a new archive

**Note:** As mentioned above, archives are only meant to contain external data, e.g. beats data. Due to the tendency for archived domain objects (rules, signals) to quickly become out of date, it is strongly suggested that you generate this data within the test, through interaction with either the UI or the API.

We use es_archiver to manage the data that our Cypress tests need.

1. Set up a clean instance of kibana and elasticsearch (if this is not possible, try to clean/minimize the data that you are going to archive).
2. With the kibana and elasticsearch instance up and running, create the data that you need for your test.
3. When you are sure that you have all the data you need run the following command from: `x-pack/plugins/fleet`

```sh
node ../../../scripts/es_archiver save <nameOfTheFolderWhereDataIsSaved> <indexPatternsToBeSaved> --dir ../../test/fleet_cypress/es_archives --config ../../../test/functional/config.js --es-url http://<elasticsearchUsername>:<elasticsearchPassword>@<elasticsearchHost>:<elasticsearchPort>
```

Example:

```sh
node ../../../scripts/es_archiver save custom_rules ".kibana",".siem-signal*" --dir ../../test/fleet_cypress/es_archives --config ../../../test/functional/config.js --es-url http://elastic:changeme@localhost:9220
```

Note that the command will create the folder if it does not exist.

## Development Best Practices

### Clean up the state

Remember to clean up the state of the test after its execution, typically with the `cleanKibana` function. Be mindful of failure scenarios, as well: if your test fails, will it leave the environment in a recoverable state?

### Minimize the use of es_archive

When possible, create all the data that you need for executing the tests using the application APIS or the UI.

### Speed up test execution time

Loading the web page takes a big amount of time, in order to minimize that impact, the following points should be
taken into consideration until another solution is implemented:

- Group the tests that are similar in different contexts.
- For every context login only once, clean the state between tests if needed without re-loading the page.
- All tests in a spec file must be order-independent.

Remember that minimizing the number of times the web page is loaded, we minimize as well the execution time.

## Linting

Optional linting rules for Cypress and linting setup can be found [here](https://github.com/cypress-io/eslint-plugin-cypress#usage)
17 changes: 17 additions & 0 deletions x-pack/plugins/fleet/cypress/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"baseUrl": "http://localhost:5620",
"defaultCommandTimeout": 60000,
"execTimeout": 120000,
"pageLoadTimeout": 120000,
"nodeVersion": "system",
"retries": {
"runMode": 2
},
"screenshotsFolder": "../../../target/kibana-fleet/cypress/screenshots",
"trashAssetsBeforeRuns": false,
"video": false,
"videosFolder": "../../../target/kibana-fleet/cypress/videos",
"viewportHeight": 900,
"viewportWidth": 1440,
"screenshotOnRunFailure": true
}
Loading