Skip to content

Commit 7c27353

Browse files
TRACEFOSS-901: Trace-X Test Pipeline integration with Cypress + CuCumber and Xray (#3)
* tst: cypress with xray integration TRACEFOSS-901 --------- Co-authored-by: Darek Skrzypczak <[email protected]>
1 parent 3142c0a commit 7c27353

File tree

9 files changed

+125
-26
lines changed

9 files changed

+125
-26
lines changed
Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
name: E2E Tests
1+
# Require to set secrets:
2+
# - ORG_IRS_JIRA_USERNAME
3+
# - ORG_IRS_JIRA_PASSWORD
4+
name: E2E Tests - Xray
25

36
on:
7+
# triggered manually by Test Manager
8+
workflow_dispatch:
9+
inputs:
10+
jira_filter_id:
11+
description: 'Jira filter ID to fetch test scenarios'
12+
required: false
13+
# by default, we use this filter: https://jira.catena-x.net/issues/?filter=11645
14+
default: 11645
15+
# or automatically by merge to main
416
push:
517
branches: [ main ]
18+
# or in PR
619
pull_request:
720

821
jobs:
922
install:
1023
runs-on: ubuntu-latest
11-
container:
12-
# if you need to change image please make sure use the same version in all places
13-
# (here and in cypress/Dockerfile)
14-
image: cypress/browsers:node16.16.0-chrome107-ff107-edge
15-
options: --user 1001
16-
1724
# Install YARN dependencies, cache them correctly
1825
steps:
1926
- name: Checkout
@@ -29,10 +36,28 @@ jobs:
2936
with:
3037
cmd: install # will run `yarn install` command
3138

39+
# Fetch feature files
40+
- name: Fetch .feature files from Jira Xray
41+
env:
42+
JIRA_USERNAME: ${{ secrets.ORG_IRS_JIRA_USERNAME }}
43+
JIRA_PASSWORD: ${{ secrets.ORG_IRS_JIRA_PASSWORD }}
44+
JIRA_FILTER_ID: ${{ github.event.inputs.jira_filter_id }}
45+
run: |
46+
./scripts/xray-download-feature-files.sh
47+
48+
- name: Save cypress/e2e folder
49+
uses: actions/upload-artifact@v3
50+
with:
51+
name: cypress - e2e
52+
if-no-files-found: error
53+
path: cypress/e2e
54+
3255
cypress-run-chrome:
3356
timeout-minutes: 15
3457
runs-on: ubuntu-latest
3558
container:
59+
# if you need to change image please make sure use the same version in all places
60+
# (here and in cypress/Dockerfile)
3661
image: cypress/browsers:node16.16.0-chrome107-ff107-edge
3762
options: --user 1001
3863
needs: install
@@ -41,6 +66,12 @@ jobs:
4166
- name: Checkout
4267
uses: actions/checkout@v3
4368

69+
- name: Download the cypress/e2e folder
70+
uses: actions/download-artifact@v3
71+
with:
72+
name: cypress - e2e
73+
path: cypress/e2e
74+
4475
- name: Use Node.js 18.x
4576
uses: actions/setup-node@v3
4677
with:
@@ -54,6 +85,15 @@ jobs:
5485
wait-on-timeout: 120
5586
browser: chrome
5687

88+
- name: Submit results to Xray
89+
# we don't want to submit results to xray when it was run by PR
90+
if: github.event_name != 'pull_request' && (success() || failure())
91+
env:
92+
JIRA_USERNAME: ${{ secrets.ORG_IRS_JIRA_USERNAME }}
93+
JIRA_PASSWORD: ${{ secrets.ORG_IRS_JIRA_PASSWORD }}
94+
run: |
95+
./scripts/xray-push-test-results.sh
96+
5797
- name: Archive cypress artifacts
5898
if: success() || failure()
5999
uses: actions/upload-artifact@v3
@@ -67,6 +107,8 @@ jobs:
67107
timeout-minutes: 15
68108
runs-on: ubuntu-latest
69109
container:
110+
# if you need to change image please make sure use the same version in all places
111+
# (here and in cypress/Dockerfile)
70112
image: cypress/browsers:node16.16.0-chrome107-ff107-edge
71113
options: --user 1001
72114
needs: install
@@ -75,6 +117,12 @@ jobs:
75117
- name: Checkout
76118
uses: actions/checkout@v3
77119

120+
- name: Download the cypress/e2e folder
121+
uses: actions/download-artifact@v3
122+
with:
123+
name: cypress - e2e
124+
path: cypress/e2e
125+
78126
- name: Use Node.js 18.x
79127
uses: actions/setup-node@v3
80128
with:
@@ -88,6 +136,15 @@ jobs:
88136
wait-on-timeout: 120
89137
browser: firefox
90138

139+
- name: Submit results to Xray
140+
# we don't want to submit results to xray when it was run by PR
141+
if: github.event_name != 'pull_request' && (success() || failure())
142+
env:
143+
JIRA_USERNAME: ${{ secrets.ORG_IRS_JIRA_USERNAME }}
144+
JIRA_PASSWORD: ${{ secrets.ORG_IRS_JIRA_PASSWORD }}
145+
run: |
146+
./scripts/xray-push-test-results.sh
147+
91148
- name: Archive cypress artifacts
92149
if: success() || failure()
93150
uses: actions/upload-artifact@v3
@@ -106,6 +163,12 @@ jobs:
106163
- name: Checkout
107164
uses: actions/checkout@v3
108165

166+
- name: Download the cypress/e2e folder
167+
uses: actions/download-artifact@v3
168+
with:
169+
name: cypress - e2e
170+
path: cypress/e2e
171+
109172
# commented because if we use it here, we face with that problem:
110173
# "http://localhost:4200 timed out on retry 151 of 5, elapsed 150449ms, limit 150000ms
111174
# Error: connect ECONNREFUSED 127.0.0.1:4200"
@@ -132,6 +195,15 @@ jobs:
132195
wait-on-timeout: 120
133196
browser: webkit
134197

198+
- name: Submit results to Xray
199+
# we don't want to submit results to xray when it was run by PR
200+
if: github.event_name != 'pull_request' && (success() || failure())
201+
env:
202+
JIRA_USERNAME: ${{ secrets.ORG_IRS_JIRA_USERNAME }}
203+
JIRA_PASSWORD: ${{ secrets.ORG_IRS_JIRA_PASSWORD }}
204+
run: |
205+
./scripts/xray-push-test-results.sh
206+
135207
- name: Archive cypress artifacts
136208
if: success() || failure()
137209
uses: actions/upload-artifact@v3

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ testem.log
3636
/typings
3737
/audit-reports
3838
src/tests/test-report.xml
39-
cypress/videos
40-
cypress/screenshots
4139

4240
# e2e
43-
/e2e/*.js
44-
/e2e/*.map
41+
cypress/videos
42+
cypress/screenshots
43+
cypress/reports/*
44+
cucumber-messages.ndjson
4545

4646
# System Files
4747
.DS_Store

AUTHORS.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@ The following people have contributed to this repository:
1616
- Nobert Geczi,msg Systems Romania SRL,https://github.com/norbertgeczi
1717
- Markus Kreuz,FEV Consulting GmbH,https://github.com/CXkreuz
1818
- Thomas Braun,ZF Friedrichshafen AG,https://github.com/tbraun-zf
19-
20-

cypress/cucumber-json-formatter

1.57 MB
Binary file not shown.

cypress/e2e/dashboard.feature

Lines changed: 0 additions & 11 deletions
This file was deleted.

docs/e2e.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,45 @@ To be able to use Behavior-driven development (BDD) approach we have configured
2424

2525
### Using docker browsers
2626

27-
- local env - docker image (use the same browser engine versions as github CI/CD)
27+
- local env - docker image (use the same browser engine versions as GitHub CI/CD)
2828
- run this command first to build docker image with cypress browsers: `docker compose -f cypress/docker-compose.yml build `
2929
- then make sure you have running frontend app: `yarn start` because docker image uses localhost url to connect run tests
3030
- then we can run E2E cypress tests on these browsers:
3131
- chrome - `docker compose -f cypress/docker-compose.yml run cypress --browser=chrome`
3232
- firefox - `docker compose -f cypress/docker-compose.yml run cypress --browser=firefox`
3333
- webkit (safari's engine) - `docker compose -f cypress/docker-compose.yml run cypress --browser=webkit`
3434

35-
## How it works on github actions (CI/CD)
35+
## How it works on GitHub actions (CI/CD)
36+
37+
### Overview
3638

3739
- configuration file is here: `.github/workflows/e2e-tests.yml`
40+
- this job is triggered by 3 ways:
41+
- automatically - for every PR or on push to main
42+
- manually - by Test Manager
3843
- we run in parallel e2e tests for 3 browser engines: chrome, firefox and webkit (used by Safari)
3944
- we use one common pre-stage named 'install'
4045
- then base on 'install' stage cache result it runs 3 separated threads for every browser
4146
- cypress-run-chrome
4247
- cypress-run-firefox
4348
- cypress-run-webkit
4449
- every thread as a part of result has an Artifact section with cypress generated files like videos or screenshots. we can download zip file with those files and open video/screenshot to check what happened.
50+
51+
### Xray (Jira) integration
52+
53+
### Configuration
54+
55+
By default, to fetch .feature files with Cucumber scenarios we use this jira filter: https://jira.catena-x.net/issues/?filter=11645.
56+
But when we run GitHub job manually, we can set different value in parameter "jira_filter_id".
57+
58+
#### Cucumber scenarios in Xray
59+
60+
- in first initial step "install" we fetch .feature files from Xray by scripts/xray-download-feature-files.sh
61+
- then every cypress browser execution use these scenarios
62+
- we keep a package with downloaded scenarios as artifact in GitHub job (named: cypress - e2e)
63+
64+
#### Xray Test Execution Reports
65+
66+
- after every cypress browser execution we generate test results in cucumber format (we use cypress/cucumber-json-formatter: https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/docs/json-report.md)
67+
- those test executions results are imported to Xray by this script: scripts/xray-push-test-results.sh
68+
- IMPORTANT! - we don't send reports if the job was triggered by PR event

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,12 @@
121121
},
122122
"msw": {
123123
"workerDirectory": "src"
124+
},
125+
"cypress-cucumber-preprocessor": {
126+
"json": {
127+
"enabled": true,
128+
"formatter": "cypress/cucumber-json-formatter",
129+
"output": "cypress/reports/cucumber-report.json"
130+
}
124131
}
125132
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# https://docs.getxray.app/display/XRAY/Exporting+Cucumber+Tests+-+REST
2+
curl -u $JIRA_USERNAME:$JIRA_PASSWORD "https://jira.catena-x.net/rest/raven/1.0/export/test?filter=${JIRA_FILTER_ID:-11645}&fz=true" -o features.zip
3+
unzip -o features.zip -d cypress/e2e
4+
rm -f features.zip

scripts/xray-push-test-results.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
curl --request POST \
2+
-u $JIRA_USERNAME:$JIRA_PASSWORD \
3+
--header 'Content-Type: application/json' \
4+
--data-binary '@cypress/reports/cucumber-report.json' \
5+
"https://jira.catena-x.net/rest/raven/1.0/import/execution/cucumber"

0 commit comments

Comments
 (0)