forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC for running cypress tests outside FT repo
Signed-off-by: Manasvini B Suryanarayana <[email protected]>
- Loading branch information
1 parent
b796940
commit 3c50158
Showing
10 changed files
with
848 additions
and
23 deletions.
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
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,161 @@ | ||
name: remote_cypress_workflow | ||
run-name: remote_cypress_workflow [${{ inputs.UNIQUE_ID}}] # Unique workflow number appended to the workflow run-name to filter the run results based on that. | ||
# trigger on every PR for all branches | ||
on: | ||
push: | ||
branches: [ '**' ] | ||
workflow_dispatch: | ||
inputs: | ||
test_repo: | ||
description: 'Cypress test repo' | ||
default: '' | ||
required: false | ||
type: string | ||
test_branch: | ||
description: 'Cypress test branch (default: source branch)' | ||
required: false | ||
type: string | ||
specs: | ||
description: 'Tests to run (default: osd:ciGroup)' | ||
required: false | ||
type: string | ||
build_id: | ||
description: 'Build Id' | ||
required: false | ||
type: string | ||
OS_URL: | ||
description: 'OpenSearch release artifact' | ||
default: 'https://artifacts.opensearch.org/releases/bundle/opensearch/2.11.0/opensearch-2.11.0-linux-x64.tar.gz' | ||
required: false | ||
type: string | ||
OSD_URL: | ||
description: 'OpenSearch Dashboards release artifact' | ||
required: false | ||
type: string | ||
UNIQUE_ID: | ||
description: 'Unique Id for the workflow execution' | ||
required: true | ||
type: string | ||
|
||
env: | ||
TEST_REPO: ${{ inputs.test_repo != '' && inputs.test_repo || github.repository }} | ||
TEST_BRANCH: "${{ inputs.test_branch != '' && inputs.test_branch || github.base_ref }}" | ||
OSD_PATH: 'osd' | ||
START_CMD: 'node ../scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true' | ||
OPENSEARCH_SNAPSHOT_CMD: 'node ../scripts/opensearch snapshot -E cluster.routing.allocation.disk.threshold_enabled=false' | ||
CYPRESS_BROWSER: 'chromium' | ||
JOB_ID: ${{ inputs.UNIQUE_ID}} | ||
OPENSEARCH_URL: 'https://artifacts.opensearch.org/releases/bundle/opensearch/2.11.0/opensearch-2.11.0-linux-x64.tar.gz' | ||
OSD_URL: 'https://artifacts.opensearch.org/releases/bundle/opensearch-dashboards/2.11.0/opensearch-dashboards-2.11.0-linux-x64.tar.gz' | ||
OPENSEARCH_DIR: 'cypress/opensearch' | ||
|
||
jobs: | ||
cypress-tests: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: docker://opensearchstaging/ci-runner:ci-runner-rockylinux8-opensearch-dashboards-integtest-v2 | ||
options: --user 1001 | ||
env: | ||
# prevents extra Cypress installation progress messages | ||
CI: 1 | ||
# avoid warnings like "tput: No value for $TERM and no -T specified" | ||
TERM: xterm | ||
name: Run cypress tests (${{ inputs.UNIQUE_ID}}) | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: ${{ env.SOURCE_REPO }} | ||
ref: '${{ env.SOURCE_BRANCH }}' | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version-file: '.nvmrc' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Setup Yarn | ||
run: | | ||
npm uninstall -g yarn | ||
npm i -g [email protected] | ||
- name: Download and extract Opensearch artifacts | ||
run: | | ||
current_directory=$(pwd) | ||
echo "Current working directory: $current_directory" | ||
mkdir -p $current_directory/${{ env.OPENSEARCH_DIR }} | ||
source scripts/bwc/utils.sh | ||
open_artifact $current_directory/${{ env.OPENSEARCH_DIR }} ${{ env.OPENSEARCH_URL }} | ||
- name: Run OpenSearch | ||
run: | | ||
current_directory=$(pwd) | ||
echo "Current working directory: $current_directory" | ||
source scripts/cypress_tests.sh | ||
run_opensearch | ||
- name: Check OpenSearch status | ||
run: | | ||
current_directory=$(pwd) | ||
echo "Current working directory: $current_directory" | ||
source scripts/cypress_tests.sh | ||
check_opensearch_status | ||
- name: Run bootstrap | ||
run: yarn osd bootstrap | ||
|
||
- name: Build plugins | ||
run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 12 | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
path: ${{ env.OSD_PATH }} | ||
repository: ${{ env.TEST_REPO }} | ||
ref: '${{ env.TEST_BRANCH }}' | ||
|
||
- name: Get Cypress version | ||
id: cypress_version | ||
run: | | ||
echo "name=cypress_version::$(cat ./${{ env.OSD_PATH }}/package.json | jq '.devDependencies.cypress' | tr -d '"')" >> $GITHUB_OUTPUT | ||
- name: Cache Cypress | ||
id: cache-cypress | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.cache/Cypress | ||
key: cypress-cache-v2-${{ runner.os }}-${{ hashFiles('**/package.json') }} | ||
env: | ||
CYPRESS_INSTALL_BINARY: ${{ steps.cypress_version.outputs.cypress_version }} | ||
- run: npx cypress cache list | ||
- run: npx cypress cache path | ||
|
||
- name: Run tests | ||
uses: cypress-io/github-action@v2 | ||
with: | ||
working-directory: ${{ env.OSD_PATH }} | ||
start: ${{ env.OPENSEARCH_SNAPSHOT_CMD }}, ${{ env.START_CMD }} | ||
wait-on: 'http://localhost:9200, http://localhost:5601' | ||
command: yarn cypress:run-without-security --browser ${{ env.CYPRESS_BROWSER }} --spec ${{ env.OSD_PATH }}/integration/dasboard_sanity_test.spec.js | ||
|
||
# Screenshots are only captured on failure, will change this once we do visual regression tests | ||
- uses: actions/upload-artifact@v3 | ||
if: failure() | ||
with: | ||
name: osd-cypress-screenshots | ||
path: ${{ env.OSD_PATH }}/screenshots | ||
retention-days: 1 | ||
|
||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: osd-cypress-videos | ||
path: ${{ env.OSD_PATH }}/videos | ||
retention-days: 1 | ||
|
||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: osd-cypress-results | ||
path: ${{ env.OSD_PATH }}/results | ||
retention-days: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"defaultCommandTimeout": 60000, | ||
"requestTimeout": 60000, | ||
"responseTimeout": 60000, | ||
"baseUrl": "http://localhost:5601", | ||
"viewportWidth": 2000, | ||
"viewportHeight": 1320, | ||
"env": { | ||
"openSearchUrl": "http://localhost:9200", | ||
"SECURITY_ENABLED": false | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "[email protected]", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
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,49 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
CommonUI, | ||
MiscUtils, | ||
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; | ||
|
||
/** | ||
* dashboard_sample_data test suite description: | ||
* 1) Visit the dev tool page of opensearchdashboard, check key UI elements display | ||
*/ | ||
export function dashboardSanityTests() { | ||
const commonUI = new CommonUI(cy); | ||
const miscUtils = new MiscUtils(cy); | ||
|
||
describe('dashboard sample data validation', () => { | ||
before(() => {}); | ||
|
||
after(() => {}); | ||
describe('checking Dev Tools', () => { | ||
before(() => { | ||
// Go to the Dev Tools page | ||
miscUtils.visitPage('app/dev_tools#/console'); | ||
}); | ||
|
||
after(() => {}); | ||
|
||
it('checking welcome panel display', () => { | ||
commonUI.checkElementExists('div[data-test-subj="welcomePanel"]', 0); | ||
}); | ||
|
||
it('checking dismiss button display', () => { | ||
commonUI.checkElementExists('button[data-test-subj="help-close-button"]', 1); | ||
}); | ||
|
||
it('checking console input area display', () => { | ||
commonUI.checkElementExists('div[data-test-subj="request-editor"]', 1); | ||
}); | ||
|
||
it('checking console output area display', () => { | ||
commonUI.checkElementExists('div[data-test-subj="response-editor"]', 1); | ||
}); | ||
}); | ||
}); | ||
} | ||
dashboardSanityTests(); |
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,29 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) |
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,24 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands'; | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
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,62 @@ | ||
#!/bin/bash | ||
|
||
# Copyright OpenSearch Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -e | ||
|
||
function setup_opensearch() { | ||
cd "$OPENSEARCH_DIR" | ||
echo "network.host: 0.0.0.0" >> config/opensearch.yml | ||
echo "discovery.type: single-node" >> config/opensearch.yml | ||
[ $SECURITY_ENABLED == "false" ] && [ -d "plugins/opensearch-security" ] && echo "plugins.security.disabled: true" >> config/opensearch.yml | ||
# Required for IM | ||
[ -d "plugins/opensearch-index-management" ] && echo "path.repo: [/tmp]" >> config/opensearch.yml | ||
# Required for Alerting | ||
[ -d "plugins/opensearch-alerting" ] && echo "plugins.destination.host.deny_list: [\"10.0.0.0/8\", \"127.0.0.1\"]" >> config/opensearch.yml | ||
# Required for SQL | ||
[ -d "plugins/opensearch-sql" ] && echo "script.context.field.max_compilations_rate: 1000/1m" >> config/opensearch.yml | ||
# Required for PA | ||
[ -d "plugins/opensearch-performance-analyzer" ] && echo "webservice-bind-host = 0.0.0.0" >> config/opensearch-performance-analyzer/performance-analyzer.properties | ||
} | ||
|
||
# Starts OpenSearch, if verifying a distribution it will install the certs then start. | ||
function run_opensearch() { | ||
echo "[ Attempting to start OpenSearch for cypress tests... ]" | ||
cd "$OPENSEARCH_DIR" | ||
# Check if opensearch-tar-install.sh exists | ||
if [ -f "./opensearch-tar-install.sh" ]; then | ||
./opensearch-tar-install.sh > ${OPENSEARCH_DIR}/opensearch.log 2>&1 | ||
else | ||
./bin/opensearch > ${OPENSEARCH_DIR}/opensearch.log 2>&1 | ||
fi | ||
} | ||
|
||
# Checks the running status of OpenSearch | ||
# if success, the while loop in the check_status will end and it prints out "OpenSearch is up!" | ||
function check_opensearch_status() { | ||
echo "Checking the status OpenSearch..." | ||
OPENSEARCH_GREEN_STATUS="\"status\":\"green\"" | ||
cd "$OPENSEARCH_DIR" | ||
|
||
# Calculate end time as 180s from now | ||
check_status_end_time=$(expr 180 + "$(date '+%s')") | ||
|
||
while true; do | ||
# Break if the current time exceeds the end time | ||
if [ $check_status_end_time -lt $(date '+%s') ]; then | ||
echo "Error: Status check has timed out" | ||
exit 1 | ||
fi | ||
|
||
# Use curl to fetch data and check for the specified message | ||
if curl -s $OPENSEARCH_URL | grep -q "$OPENSEARCH_GREEN_STATUS"; then | ||
echo "Status check successful" | ||
break | ||
fi | ||
|
||
# Pause for a short interval before the next check | ||
sleep 1 | ||
done | ||
echo "OpenSearch is up!" | ||
} |
Oops, something went wrong.