Skip to content

Commit

Permalink
POC for running cypress tests outside FT repo
Browse files Browse the repository at this point in the history
Signed-off-by: Manasvini B Suryanarayana <[email protected]>
  • Loading branch information
manasvinibs committed Jan 11, 2024
1 parent b796940 commit 0b8db67
Show file tree
Hide file tree
Showing 10 changed files with 841 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@ jobs:
#### Link to results:
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
edit-mode: replace
edit-mode: replace
154 changes: 154 additions & 0 deletions .github/workflows/remote_cypress_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
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: 'osd/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: |
source ../scripts/bwc/utils.sh
open_artifact ${{ env.OPENSEARCH_DIR }} ${{ env.OPENSEARCH_URL }}
- name: Run OpenSearch
run: |
source ../scripts/cypress_tests.sh
run_opensearch
- name: Check OpenSearch status
run: |
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
12 changes: 12 additions & 0 deletions cypress.json
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
}
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
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"
}
49 changes: 49 additions & 0 deletions cypress/integration/dasboard_sanity_test.spec.js
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();
29 changes: 29 additions & 0 deletions cypress/support/commands.js
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) => { ... })
24 changes: 24 additions & 0 deletions cypress/support/index.js
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')
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
"docs:acceptApiChanges": "scripts/use_node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"osd:bootstrap": "scripts/use_node scripts/build_ts_refs && scripts/use_node scripts/register_git_hook",
"spec_to_console": "scripts/use_node scripts/spec_to_console",
"pkg-version": "scripts/use_node -e \"console.log(require('./package.json').version)\""
"pkg-version": "scripts/use_node -e \"console.log(require('./package.json').version)\"",
"cypress:run-without-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --headless --env SECURITY_ENABLED=false"

},
"repository": {
"type": "git",
Expand Down Expand Up @@ -224,7 +226,9 @@
"type-detect": "^4.0.8",
"uuid": "3.3.2",
"whatwg-fetch": "^3.0.0",
"yauzl": "^2.10.0"
"yauzl": "^2.10.0",
"@opensearch-dashboards-test/opensearch-dashboards-test-library": "https://github.com/opensearch-project/opensearch-dashboards-test-library/archive/refs/tags/1.0.6.tar.gz"

},
"devDependencies": {
"@babel/core": "^7.16.5",
Expand Down Expand Up @@ -353,6 +357,7 @@
"chromedriver": "^107.0.3",
"classnames": "2.3.1",
"compare-versions": "3.5.1",
"cypress": "9.5.4",
"d3": "3.5.17",
"d3-cloud": "1.2.5",
"dedent": "^0.7.0",
Expand Down
62 changes: 62 additions & 0 deletions scripts/cypress_tests.sh
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!"
}
Loading

0 comments on commit 0b8db67

Please sign in to comment.