Skip to content

Commit

Permalink
Run cy manually on 3.15 (#4885)
Browse files Browse the repository at this point in the history
* Run cy manually on 3.15

* Add base url to config
  • Loading branch information
karola312 authored May 27, 2024
1 parent 78d4279 commit e688404
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-crews-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Add manual workflow for cypress tests
96 changes: 96 additions & 0 deletions .github/actions/e2e/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: e2e-parallel
description: "Trigger e2e tests and create reports"
inputs:
apiUrl:
description: "API URL from PR or staging"
required: true
baseUrl:
description: "FE URL from PR or staging"
required: true
commitInfoMessage:
description: "Info displayed in commit"
required: false
cypressGrepTags:
description: "Passed tags that should be executed"
required: true
split:
description: "E2E tests containers number"
required: true
splitIndex:
description: "E2E tests container index"
required: true
install:
description: "Triggers cypress installation"
required: false
browser:
description: "Browser which e2e should test"
required: false
appMountUri:
description: "URL for Apps"
required: true
userName:
description: "Name of user which e2e uses"
required: true
secondUserName:
description: "Name of the second user which e2e uses"
required: true
userPassword:
description: "User password for e2e"
required: true
permissionsUserPassword:
description: "User with limited permissions password"
required: true
mailpitUrl:
description: "Mail provider URL"
required: true
stripeSecretKey:
description: "Payments providers secret"
required: false
stripePublicKey:
description: "Payments providers secret"
required: false
runs:
using: "composite"
steps:
- name: Install dependencies
shell: bash
run: npm ci

- name: e2e with reports
uses: cypress-io/github-action@v6
with:
install: ${{inputs.install}}
browser: ${{inputs.browser}}
env:
API_URI: ${{inputs.apiUrl}}
APP_MOUNT_URI: ${{ inputs.appMountUri }}
BASE_URL: ${{inputs.baseUrl}}
CYPRESS_USER_NAME: ${{ inputs.userName }}
CYPRESS_SECOND_USER_NAME: ${{ inputs.secondUserName }}
CYPRESS_USER_PASSWORD: ${{ inputs.userPassword }}
CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ inputs.permissionsUserPassword }}
CYPRESS_MAILPITURL: ${{ inputs.mailpitUrl }}
CYPRESS_grepTags: ${{ inputs.cypressGrepTags }}
SPLIT: ${{ inputs.split }}
SPLIT_INDEX: ${{ inputs.splitIndex}}
STRIPE_SECRET_KEY: ${{inputs.stripeSecretKey}}
STRIPE_PUBLIC_KEY: ${{inputs.stripePublicKey}}
COMMIT_INFO_MESSAGE: ${{inputs.commitInfoMessage}}
- name: Create reports dir
shell: bash
continue-on-error: true
if: ${{ ! cancelled() }}
run: npm run qa:create-artifacts-dirs
- name: Move screenshots into reports dir
shell: bash
continue-on-error: true
if: ${{ ! cancelled() }}
run: npm run qa:move-screenshots
- name: Upload reports
uses: actions/upload-artifact@v3
if: always()
with:
name: report-${{ strategy.job-index }}
path: ./cypress/reports
retention-days: 5
if-no-files-found: ignore
42 changes: 42 additions & 0 deletions .github/actions/testmo/testmo-init/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: init-testmo
description: "Inits testmo reports"
inputs:
testmoUrl:
description: "Testmo project URL"
required: true
testmoToken:
description: "Testmo token"
required: true
testmoRunName:
description: "Displayed name in testmo"
required: true
outputs:
testmo-run-id:
description: "Testmo run id"
value: ${{ steps.run-tests.outputs.TESTMO_RUN_ID }}
runs:
using: composite
steps:
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: npm
- name: install dependencies
working-directory: .github/workflows
shell: bash
run: npm ci
- name: create testmo run
working-directory: .github/workflows
shell: bash
run: |
ID=$(npx testmo automation:run:create \
--instance "$TESTMO_URL" \
--project-id 1 \
--name "$RUN_NAME" \
--source frontend-e2e-tests)
echo "TESTMO_RUN_ID=$ID" >> $GITHUB_OUTPUT
env:
TESTMO_URL: ${{ inputs.testmoUrl }}
TESTMO_TOKEN: ${{ inputs.testmoToken }}
RUN_NAME: ${{inputs.testmoRunName}}
id: run-tests
89 changes: 89 additions & 0 deletions .github/workflows/postTestsResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const { Command } = require("commander");
const program = new Command();

program
.name("Send tests results")
.description(
"Get tests results from testmo and post message to slack or on release PR",
)
.option("--run_id <run_id>", "Testmo run id")
.option(
"--testmo_token <testmo_token>",
"Bearer token for authorization in testmo",
)
.option(
"--slack_webhook_url <slack_webhook_url>",
"Should send notification on slack",
)
.option("--environment <environment>", "Environment")
.option("--url_to_action <url_to_action>", "Url to enter github action")
.option("--ref_name <ref_name>", "Ref to point where tests where run")
.action(async options => {
const runId = options.run_id;
const testmoAuthToken = options.testmo_token;
const testsResults = await getTestsStatus(runId, testmoAuthToken);
const testsStatus = convertResults(
testsResults,
options.environment,
options.ref_name,
);

await sendMessageOnSlack(
testsStatus,
options.slack_webhook_url,
options.url_to_action,
);
})
.parse();

async function getTestsStatus(runId, testmoToken) {
const runResult = await fetch(
`https://saleor.testmo.net/api/v1/automation/runs/${runId}`,
{
headers: {
Authorization: `Bearer ${testmoToken}`,
},
},
);
return await runResult.json();
}

function convertResults(results, environment, refName) {
let status = results?.result?.status === 2 ? "SUCCESS" : "FAILURE";
let message = `Tests run on environment: \n${environment}\n`;
const linkToResults = `https:\/\/saleor.testmo.net\/automation\/runs\/view\/${results.result.id}`;

message += `See results at ${linkToResults}`;

return {
status,
message,
title: `Tests run on ${refName}`,
linkToResults,
};
}

async function sendMessageOnSlack(testsStatus, webhookUrl, urlToAction) {
const JOB_STATUS_COLOR_MAP = {
SUCCESS: "#5DC292",
FAILURE: "#FE6E76",
};

const messageData = {
attachments: [
{
fallback: testsStatus.message,
pretext: testsStatus.status,
title: testsStatus.title,
title_link: urlToAction,
text: testsStatus.message,
color: JOB_STATUS_COLOR_MAP[testsStatus.status],
},
],
};
await fetch(webhookUrl, {
body: JSON.stringify(messageData),
method: "post",
headers: { "content-type": "application/json" },
});
}
145 changes: 145 additions & 0 deletions .github/workflows/run-test-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Run test manually
run-name: Run cypress tests

on:
workflow_dispatch:
inputs:
tags:
required: true
description: "Select tests to run"
default: "@allEnv"
type: choice
options:
- "@allEnv"
- "@critical"
- "@stable"
- "@oldRelease"
browser:
required: true
description: "Browser"
default: "electron"
type: choice
options:
- electron
- firefox
- all
jobs:

testmo-report-preparation:
runs-on: ubuntu-22.04
outputs:
TESTMO_RUN_ID: ${{ steps.init-testmo.outputs.testmo-run-id }}
BASE_URL: ${{ steps.set_variables.outputs.BASE_URL }}
API_URL: ${{ steps.set_variables.outputs.API_URL }}
steps:
- uses: actions/checkout@v4

- name: Set variables
id: set_variables
run: |
CURRENT_BRANCH=$(echo "${GITHUB_REF}" | sed "s/refs\/heads\///")
VERSION_SLUG=$(echo "${CURRENT_BRANCH}" | sed "s/\.//")
echo "BASE_URL=https://v${VERSION_SLUG}.staging.saleor.cloud/dashboard/" >> $GITHUB_OUTPUT
echo "API_URL=https://v${VERSION_SLUG}.staging.saleor.cloud/graphql/" >> $GITHUB_OUTPUT
- uses: ./.github/actions/testmo/testmo-init
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunName: "Cypress run ${{ github.ref_name }}"
id: init-testmo

run-tests-in-parallel:
needs: testmo-report-preparation
runs-on: ubuntu-22.04
container:
image: cypress/browsers:node18.12.0-chrome106-ff106
options: --user 1001
env:
GREP_TAGS: ${{ github.event.inputs.tags || '@critical'}}
BROWSER: ${{ inputs.browser || 'electron' }}
strategy:
fail-fast: false
matrix:
containers: [1, 2, 3, 4, 5, 6]
steps:
- uses: actions/checkout@v4


- name: Cypress run
id: cypress-run
uses: ./.github/actions/e2e
continue-on-error: true
with:
apiUrl: ${{ needs.testmo-report-preparation.outputs.API_URL}}
appMountUri: ${{ secrets.APP_MOUNT_URI }}
baseUrl: ${{ needs.testmo-report-preparation.outputs.BASE_URL}}
userName: ${{ secrets.CYPRESS_USER_NAME }}
secondUserName: ${{ secrets.CYPRESS_SECOND_USER_NAME }}
userPassword: ${{ secrets.CYPRESS_USER_PASSWORD }}
permissionsUserPassword: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
mailpitUrl: ${{ secrets.CYPRESS_MAILPITURL }}
stripeSecretKey: ${{ secrets.STRIPE_SECRET_KEY }}
stripePublicKey: ${{ secrets.STRIPE_PUBLIC_KEY }}
cypressGrepTags: ${{ env.GREP_TAGS }}
split: ${{ strategy.job-total }}
splitIndex: ${{ strategy.job-index }}
commitInfoMessage: All tests triggered via ${{ github.event_name}} on ${{ steps.get-env-uri.outputs.ENV_URI }}
install: false
browser: ${{ env.BROWSER }}

- name: Testmo threads submit
uses: ./.github/actions/testmo/testmo-threads-submit
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunId: ${{ needs.testmo-report-preparation.outputs.TESTMO_RUN_ID }}


post-tests-results:
defaults:
run:
shell: bash
working-directory: .github/workflows
runs-on: ubuntu-22.04
needs: [run-tests-in-parallel, testmo-report-preparation]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"

- name: Install dependencies
run: npm ci

- uses: ./.github/actions/combineReportsFromE2E

- name: complete testmo report
uses: ./.github/actions/testmo/testmo-finish
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunId: ${{ needs.testmo-report-preparation.outputs.TESTMO_RUN_ID }}

- name: send message on slack
working-directory: ".github"
env:
run_id: ${{ needs.testmo-report-preparation.outputs.TESTMO_RUN_ID }}
url_to_action: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
testmo_token: ${{ secrets.TESTMO_TOKEN }}
environment: ${{ needs.testmo-report-preparation.outputs.BASE_URL }}
slack_webhook_url: ${{ secrets.SLACK_QA_STATUSES_WEBHOOK_URL }}
ref_name: ${{github.ref_name}}

run: |
node workflows/postTestsResults.js \
--run_id "$run_id" \
--testmo_token "$testmo_token" \
--slack_webhook_url "$slack_webhook_url" \
--environment "$environment" \
--url_to_action "$url_to_action" \
--ref_name "$ref_name"
1 change: 1 addition & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = defineConfig({
numTestsKeptInMemory: 10,
experimentalMemoryManagement: true,
},
baseUrl: process.env.BASE_URL,
setupNodeEvents(on, config) {
config = require("./cypress/support/cypress-grep/plugin")(config);
config = require("./cypress/plugins/index.js")(on, config);
Expand Down

0 comments on commit e688404

Please sign in to comment.