Skip to content

Commit c51e117

Browse files
committed
feat: init cypress
initial conversion of wdio tests
1 parent 15ee19a commit c51e117

File tree

67 files changed

+5209
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+5209
-117
lines changed

.github/workflows/cypress.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# This workflow runs Cypress tests in Firefox against a running eXist-db instance.
2+
# It mirrors the build workflow structure but executes Cypress tests instead of smoke tests.
3+
4+
name: Cypress Tests
5+
6+
on: [push]
7+
8+
jobs:
9+
cypress-tests:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
# Test against different eXist-db versions
15+
exist-version: [latest, release]
16+
java-version: [11, 21]
17+
exclude:
18+
- exist-version: release
19+
java-version: 21
20+
- exist-version: latest
21+
java-version: 11
22+
23+
steps:
24+
# Checkout code
25+
- uses: actions/checkout@v6
26+
27+
# Install Test Dependencies
28+
- name: Install Test Dependencies
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y libxml2-utils
32+
33+
# Sanity check
34+
- name: Ensure all XML files are well-formed
35+
run: |
36+
find . -type f -name '*.xml' -print0 | xargs -0 xmllint -noout
37+
38+
# Setup Node.js
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v6
41+
with:
42+
cache: npm
43+
node-version: lts/*
44+
45+
# Install dependencies
46+
- name: Install dependencies
47+
run: npm ci --no-optional
48+
49+
# Build
50+
- name: Setup Java
51+
uses: actions/setup-java@v5
52+
with:
53+
distribution: 'temurin'
54+
java-version: ${{ matrix.java-version }}
55+
56+
- name: Build Expath Package
57+
run: ant -Dapp.version=1.0.0-SNAPSHOT
58+
59+
- name: Add expath dependencies
60+
working-directory: build
61+
run: |
62+
wget https://exist-db.org/exist/apps/public-repo/public/expath-crypto-module-6.0.1.xar -O 000.xar
63+
wget http://exist-db.org/exist/apps/public-repo/public/templating-1.1.0.xar -O 001.xar
64+
wget https://exist-db.org/exist/apps/public-repo/public/tei-publisher-lib-2.10.1.xar -O 002.xar
65+
wget https://exist-db.org/exist/apps/public-repo/public/functx-1.0.1.xar -O 003.xar
66+
wget https://github.com/HistoryAtState/aws.xq/releases/latest/download/aws-xq.xar -O 004.xar
67+
68+
# Install and start eXist-db
69+
- name: Start exist-ci containers
70+
run: |
71+
docker run -dit -p 8080:8080 -v ${{ github.workspace }}/build:/exist/autodeploy \
72+
--name exist --rm --health-interval=2s --health-start-period=4s \
73+
duncdrum/existdb:${{ matrix.exist-version }}
74+
75+
- name: Wait for eXist-db to start
76+
timeout-minutes: 10
77+
run: |
78+
while ! docker logs exist | grep -q "Server has started"; \
79+
do sleep 2s; \
80+
done
81+
82+
# Run Cypress tests in Firefox
83+
- name: Run Cypress tests in Firefox
84+
uses: cypress-io/github-action@v7
85+
with:
86+
install: false
87+
browser: firefox
88+
spec: 'tests/cypress/e2e/**/prod_*.cy.js'
89+
90+
91+
# Upload test results
92+
- name: Upload Cypress screenshots
93+
uses: actions/upload-artifact@v4
94+
if: failure()
95+
with:
96+
name: cypress-screenshots-${{ matrix.exist-version }}-${{ matrix.java-version }}
97+
path: tests/cypress/screenshots
98+
retention-days: 7
99+
100+
- name: Upload Cypress videos
101+
uses: actions/upload-artifact@v4
102+
if: always()
103+
with:
104+
name: cypress-videos-${{ matrix.exist-version }}-${{ matrix.java-version }}
105+
path: tests/cypress/videos
106+
retention-days: 7

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ resources/scripts/app.min.js
1111
tests/reports/errorShots/*
1212
tests/reports/junit-reports/*
1313

14+
test/cypress/screenshots/
15+
test/cypress/videos/
16+
test/cypress/downloads/
17+
18+
.DS_Store
19+
20+
plan/
21+
1422
# local properties
1523
local.node-exist.json
1624

README.md

Lines changed: 46 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -140,106 +140,80 @@ Verify you have a local hsg-project running at localhost:8080/exist/apps/hsg-she
140140

141141
### How to run local web tests
142142

143-
#### 1. Install Chrome
143+
#### 1. Install Dependencies
144144

145-
Make sure you have Google Chrome >= 110 and all required node_modules installed (`npm install`).
145+
Make sure you have all required node_modules installed (`npm install`). Cypress will be installed as part of the devDependencies.
146146

147-
##### Troubleshooting Chromedriver Problems
147+
#### 2. Configuration
148148

149-
If you have problems with installing or running Chromedriver, have a look at these resources: [webdriver.io/docs/wdio-chromedriver-service.html](https://webdriver.io/docs/wdio-chromedriver-service.html), [stackoverflow](https://stackoverflow.com/questions/54940853/chrome-version-must-be-between-71-and-75-error-after-updating-to-chromedriver-2)
149+
Test configuration is in `cypress.config.cjs`. The baseUrl is set to `http://localhost:8080/exist/apps/hsg-shell` by default. Test files are located in `tests/cypress/e2e/` and organized by feature area.
150150

151-
It might be helpful to run
151+
Test files follow naming conventions:
152+
- `prod_*.cy.js` - Production environment tests
153+
- `uat_*.cy.js` - UAT environment tests
152154

153-
```shell
154-
npm install chromedriver --detect_chromedriver_version
155-
```
156-
157-
All available chromedriver versions are listed here: [https://chromedriver.storage.googleapis.com/](https://chromedriver.storage.googleapis.com/).
158-
159-
If your current Chrome version doesn't match the required one.
160-
This command will check the required version and install a suitable Chromedriver for you.
161-
162-
Note: If you are using an Apple M1 computer, the filename for chromedriver has been changed by Chrome between version 105 and 106 [See fix for node_chromedriver: https://github.com/giggio/node-chromedriver/pull/386/](https://github.com/giggio/node-chromedriver/pull/386/commits/7bc8dc46583ca484ca17707d9d98f8a1f98b9be4#).
163-
When running this project's ant script on an M1 with a Chrome version <=105, you should either update Chrome to 110 like defined in file `package.json`, or change the chromedriver version to your current Chrome version to match the expected chromedriver filename.
164-
165-
#### 2. Optional: Edit configuration
166-
167-
* Optional: Edit which test files or suites you would like to run.
168-
Here is the part where to define the test suites:
169-
```
170-
suites: {
171-
dev: [
172-
'./tests/specs/**/dev_*.js'
173-
],
174-
prod: [
175-
'./tests/specs/**/prod_*.js'
176-
]
177-
}
178-
```
179-
180-
#### 3. Run the web test
155+
#### 3. Run the tests
181156

182-
Basic syntax of starting an entire test suite is
157+
**Open Cypress Test Runner (Interactive Mode):**
183158
```bash
184-
npm test
159+
npm run cy:open
185160
```
186161

187-
Use `npx` to execute different test suites
188-
162+
**Run all tests (Headless Mode):**
189163
```bash
190-
npx wdio wdio.conf.js --suite <name-of-the-testsuite>
164+
npm run cy:run
191165
```
192-
for example (runs all development environment test that have been listed in the wdio configuration in `suites: {prod : ...}`):
193166

167+
**Run production tests only:**
194168
```bash
195-
npx wdio wdio.conf.js --suite test-prod
169+
npm run cy:run:prod
196170
```
197171

198-
and for a single test it is
172+
**Run UAT tests only:**
199173
```bash
200-
npx wdio wdio.conf.js --spec path-to-the-testspec
174+
npm run cy:run:uat
201175
```
202-
for example:
176+
177+
**Run jenkins suite (production tests):**
203178
```bash
204-
npx wdio wdio.conf.js --spec tests/specs/error/prod_404.spec.js
179+
npm run cy:run:jenkins
205180
```
206181

207-
In addition, you can define running the test commands in `package.json`
208-
within the `scripts` key, for example:
209-
```json
210-
"test": "./node_modules/.bin/wdio wdio.conf.js --suite test-prod"
211-
```
212-
and run this command with
213-
```shell
214-
npm run-script test-prod
182+
**Run a specific test file:**
183+
```bash
184+
npx cypress run --spec "tests/cypress/e2e/landing/prod_landing_title.cy.js"
215185
```
216186

217-
This test runs in "headless" mode. It means the test will run in the background without opening a browser window.
218-
If you want to observe all actions in the web test in a browser, just comment out the `headless` argument in the `wdio.conf.js`:
187+
#### 4. Test Structure
219188

220-
```
221-
chromeOptions: {
222-
args: [
223-
//'headless',
224-
'disable-gpu',
225-
'--window-size=1280,1024',
226-
'ignore-certificate-errors',
227-
'ignore-urlfetcher-cert-requests'
228-
],
229-
binary: process.env.WDIO_CHROME_BINARY
230-
},
231-
```
189+
Tests are organized in `tests/cypress/e2e/` by feature:
190+
- `conferences/` - Conference pages
191+
- `countries/` - Countries pages
192+
- `departmenthistory/` - Department history pages
193+
- `developer/` - Developer resources
194+
- `education/` - Education pages
195+
- `error/` - Error pages (404, etc.)
196+
- `historical-documents/` - FRUS and historical documents
197+
- `iiif-images/` - IIIF image viewer tests
198+
- `landing/` - Landing page tests
199+
- `milestones/` - Milestones pages
200+
- `open/` - Open Government Initiative
201+
- `search/` - Search functionality
202+
- `tags/` - Tags pages
203+
- `ui-components/` - UI component tests (breadcrumb, etc.)
204+
205+
Custom commands are available in `tests/cypress/support/commands.js` which provide helper methods converted from the original WebdriverIO Page Objects.
232206

233-
#### 4. Further documentation
207+
#### 5. Further documentation
234208

235-
This web test is configured to use the framework `Mocha` with `Chai` and activated Chai plugin `assert` (`global.assert = chai.assert;`) for assertions.
209+
This test suite uses Cypress with Mocha and Chai for assertions. The `assert` global is available (matching the previous WebdriverIO setup).
236210

237211
Have a look at the documentation:
238212

239-
* General overview about "webdriver.io": [webdriver.io/docs/gettingstarted](https://webdriver.io/docs/gettingstarted.html)
240-
* Webdriver.io functions: [webdriver.io/docs/api](https://webdriver.io/docs/api.html)
241-
* List of all functions in the Chai Assertion library: [chaijs.com/api/assert](https://www.chaijs.com/api/assert/)
242-
* Overview about mocha.js: [mochajs.org](https://mochajs.org/)
213+
* Cypress documentation: [docs.cypress.io](https://docs.cypress.io/)
214+
* Cypress API: [docs.cypress.io/api](https://docs.cypress.io/api)
215+
* Chai Assertion library: [chaijs.com/api/assert](https://www.chaijs.com/api/assert/)
216+
* Mocha documentation: [mochajs.org](https://mochajs.org/)
243217

244218
## Release
245219

build.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@
9494
<exclude name="package-lock.json"/>
9595
<exclude name=".idea/**"/>
9696
<exclude name=".vscode/**"/>
97+
<exclude name=".plan/**"/>
9798
<exclude name="tests/reports/**"/>
99+
<exclude name="tests/cypress/**"/>
98100
<exclude name="npm-shrinkwrap.json"/>
99101
<exclude name="build.properties.local.xml"/>
100102
<exclude name="local.node-exist.json"/>
101103
<exclude name="wdio*"/>
104+
<exclude name="cypress.config.cjs"/>
102105
<exclude name=".github/**"/>
103106
<exclude name=".releaserc"/>
104107
<exclude name="commitlint.config.cjs"/>

cypress.config.cjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { defineConfig } = require('cypress');
2+
const glob = require('glob');
3+
4+
module.exports = defineConfig({
5+
e2e: {
6+
setupNodeEvents(on, config) {
7+
on('task', {
8+
findFiles({ pattern }) {
9+
// Use glob.sync to get the files synchronously
10+
return glob.sync(pattern, { nodir: true });
11+
}
12+
});
13+
return config;
14+
},
15+
baseUrl: 'http://localhost:8080/exist/apps/hsg-shell',
16+
viewportWidth: 1280,
17+
viewportHeight: 720,
18+
trashAssetsBeforeRuns: true,
19+
includeShadowDom: true,
20+
retries: 1,
21+
supportFile: 'tests/cypress/support/e2e.js',
22+
specPattern: 'tests/cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
23+
screenshotsFolder: 'tests/cypress/screenshots',
24+
videosFolder: 'tests/cypress/videos',
25+
fixturesFolder: 'tests/cypress/fixtures',
26+
downloadsFolder: 'tests/cypress/downloads'
27+
},
28+
});
29+

0 commit comments

Comments
 (0)