-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fleet] cypress setup #113106
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 d74478d
Merge branch 'elastic:master' into fleet-cypress
juliaElastic 648bf47
updated readme
juliaElastic 7099dc1
fixed types
juliaElastic bb21e5c
fix unused
juliaElastic 98164cf
starting up fleet server in cypress
juliaElastic 5f28762
added more fleet tests
juliaElastic 4261fde
added package update test
juliaElastic 72fa3f7
updated readme
juliaElastic f47cafd
trying jenkins run
juliaElastic 6c557ef
trying jenkins run
juliaElastic ec6714e
trying jenkins run
juliaElastic 9411f5d
fix types, cypress config
juliaElastic f1e8984
Merge branch 'master' into fleet-cypress
kibanamachine 15ddd5c
example of mocked requests
juliaElastic 8fa29b3
Merge branch 'master' into fleet-cypress
juliaElastic 9464634
Merge branch 'master' into fleet-cypress
kibanamachine a3983bd
added getBySel
juliaElastic f285b11
Merge branch 'master' into fleet-cypress
kibanamachine 2f7bacd
fix test after refactor
juliaElastic a4896df
Merge branch 'master' into fleet-cypress
kibanamachine 10b67ac
Merge branch 'master' into fleet-cypress
kibanamachine a8fdde8
removed duplication
juliaElastic 2f6ccc9
Merge branch 'fleet-cypress' of https://github.com/juliaElastic/kiban…
juliaElastic 2019a5b
fix tests
juliaElastic 0dca80c
Merge branch 'elastic:master' into fleet-cypress
juliaElastic c0daca1
Merge branch 'master' into fleet-cypress
kibanamachine ef7dd15
Merge branch 'master' into fleet-cypress
kibanamachine 6c0c44e
Merge branch 'master' into fleet-cypress
kibanamachine d4f8c62
Merge branch 'master' into fleet-cypress
kibanamachine b47d46c
added to buildkite
juliaElastic 2566117
Merge branch 'master' into fleet-cypress
kibanamachine 5d7b7b1
updated tests
juliaElastic d78ff94
Merge branch 'fleet-cypress' of https://github.com/juliaElastic/kiban…
juliaElastic a0d6e17
Merge branch 'master' into fleet-cypress
kibanamachine 1628a93
starting agent with docker
juliaElastic 71f58a8
Merge branch 'fleet-cypress' of https://github.com/juliaElastic/kiban…
juliaElastic 8e04d5a
trying to fix ip address
juliaElastic 7f21722
ifconfig
juliaElastic 7b796dd
ip address
juliaElastic a9ed685
ip address
juliaElastic bb6e4e9
ip address
juliaElastic 0514434
type fix
juliaElastic 8ba315a
remove extra logging
juliaElastic 7298bc8
fixed test
juliaElastic 6b5a2c8
fix buildkite
juliaElastic fb00562
Merge branch 'master' into fleet-cypress
kibanamachine 8858ed7
Merge branch 'master' into fleet-cypress
kibanamachine 1051cc8
Merge branch 'master' into fleet-cypress
kibanamachine 265020a
cleanup
juliaElastic 8586adf
cleanup
juliaElastic 94ca5e6
using docker for fleet_server
juliaElastic c86ed5a
fix
juliaElastic 893687c
fix
juliaElastic e550286
trying to fix
juliaElastic bd01ccb
Merge branch 'master' of github.com:elastic/kibana into fleet-cypress
patrykkopycinski 4a5d233
update config
patrykkopycinski 9d63e66
test
patrykkopycinski c22af32
test
patrykkopycinski cd83d72
test
patrykkopycinski 66e87ba
test
patrykkopycinski 10d36bf
revert changes
patrykkopycinski 722994a
test
patrykkopycinski 3faaa90
test
patrykkopycinski 6bf2915
Merge branch 'main' into fleet-cypress
kibanamachine ebb8f64
static ip on linux
juliaElastic 2a65c57
docker version
juliaElastic db35a93
try again
juliaElastic c29d688
fixed review comments
juliaElastic 7819abc
fixed types
juliaElastic ce6c85b
Merge branch 'main' into fleet-cypress
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,3 +86,8 @@ report.asciidoc | |
/bazel | ||
/bazel-* | ||
.bazelrc.user | ||
|
||
elastic-agent-* | ||
fleet-server-* | ||
elastic-agent.yml | ||
fleet-server.yml | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
elastic-agent-* | ||
fleet-server-* | ||
elastic-agent.yml | ||
fleet-server.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: new line