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 Nov 20, 2023
1 parent b796940 commit b925e1e
Show file tree
Hide file tree
Showing 9 changed files with 746 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
121 changes: 121 additions & 0 deletions .github/workflows/remote_cypress_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: remote_cypress_workflow
run-name: remote_cypress_workflow [${{ inputs.build_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:
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: 'Unique Id for Job'
required: false
type: string

env:
TEST_REPO: ${{ inputs.test_repo != '' && inputs.test_repo || github.repository }}
TEST_BRANCH: "${{ inputs.test_branch != '' && inputs.test_branch || github.base_ref }}"
FTR_PATH: 'cypress'
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.build_id}}

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.build_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: 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.FTR_PATH }}
repository: ${{ env.TEST_REPO }}
ref: '${{ env.TEST_BRANCH }}'

- name: Get Cypress version
id: cypress_version
run: |
echo "name=cypress_version::$(cat ./${{ env.FTR_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.FTR_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.FTR_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: ftr-cypress-screenshots
path: ${{ env.FTR_PATH }}/screenshots
retention-days: 1

- uses: actions/upload-artifact@v3
if: always()
with:
name: ftr-cypress-videos
path: ${{ env.FTR_PATH }}/videos
retention-days: 1

- uses: actions/upload-artifact@v3
if: always()
with:
name: ftr-cypress-results
path: ${{ env.FTR_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"]', 1);
});

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
Loading

0 comments on commit b925e1e

Please sign in to comment.