Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MOSIP Admin Portal — an Angular 8 SPA used by privileged administrative person

The repo has two independently buildable modules:
- `admin-ui/` — the Angular frontend
- `uitest-admin/` — a Selenium + TestNG automation test suite (Java 21, Maven)
- `uitest-admin/` — a Playwright + Cucumber UI automation suite on the shared `uitest-commons` library (Java 21, Maven)

---

Expand All @@ -31,19 +31,12 @@ ng e2e # end-to-end tests via Protractor

```bash
cd uitest-admin
mvn clean install # build and package the fat JAR

# Run tests against a deployed environment
java -Dpath=https://admin.<env>.mosip.net/ \
-DKeyclockURL=https://iam.<env>.mosip.net \
-Denv.user=api-internal.<env> \
-Denv.endpoint=https://api-internal.<env>.mosip.net \
-jar target/uitest-admin-1.3.0-jar-with-dependencies.jar
mvn test # run every feature against the configured env
mvn test -DscenarioToRun="Center type CRUD" # by exact scenario name (comma-separated)
mvn test -Dcucumber.filter.tags="not @bulkUploadCRUD" # by tag
```

Control test execution via `src/main/resources/TestData.json`:
- `setExcludedGroups`: comma-separated group tags to skip (e.g. `"BL,CT"`)
- `headless`: `"yes"` for headless Chrome
Configure the target environment in `src/test/resources/config/adminui.properties` (tracked with blank secrets — never commit real values) or via environment variables of the same names: `baseUrl`, `apiInternalEndPoint`, `keycloak-external-url`, `mosip_admin_client_secret`, `mosip_testrig_client_secret`. `mvn package` skips the live suite when `CI=true`.

---

Expand Down Expand Up @@ -91,7 +84,7 @@ API paths are constructed in `app.constants.ts` as `<baseUrl> + <MASTERDATA_BASE

### UI Test Suite Structure

15 test classes run in parallel (8 threads) via TestNG, one per master-data entity/feature. `KnownIssueListener` cross-references `Known_Issues.txt` to suppress known failures. Test reports go to `admintest/Reports/` (ExtentReports) and `testng-report/`.
15 Cucumber feature files (`src/test/resources/features/`), one per master-data entity/resource plus bulk upload, run 4 at a time through `AdminTestRunner` (JUnit5 Platform). Step definitions in `steps/` are generic (`MasterDataSteps` covers every CRUD page) and drive Playwright page objects in `pages/`; feature files use `${data}`-style placeholders for per-run test data. `AdminHooks` creates a per-run Keycloak admin user, maps it to a zone, and after the run deletes the master data it created. Browser lifecycle, Extent reporting (`test-output/`) and `Known_Issues.txt` handling come from `uitest-commons`. See `uitest-admin/README.md`.

---

Expand Down
5 changes: 5 additions & 0 deletions uitest-admin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target/
/test-output/
/testng-report/
/logs/
/src/logs/
70 changes: 29 additions & 41 deletions uitest-admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,47 @@
# --- Base image ---
FROM eclipse-temurin:21-jre-alpine
# Microsoft's official Playwright Java image — ships the matching browser binaries and all
# OS-level dependencies for the Playwright version uitest-commons depends on (playwright.version
# in mosip-functional-tests/uitestrig-platform/pom.xml). Keep this tag in sync with that property.
FROM mcr.microsoft.com/playwright/java:v1.44.0-jammy

USER root

# Maven isn't bundled in the Playwright base image.
RUN apt-get update && \
apt-get install -y maven && \
rm -rf /var/lib/apt/lists/*

# --- Build-time arguments (MUST be declared before LABEL) ---
ARG SOURCE
ARG COMMIT_HASH
ARG COMMIT_ID
ARG BUILD_TIME

# --- Metadata labels (used by CI for validation) ---
LABEL source=${SOURCE}
LABEL commit_hash=${COMMIT_HASH}
LABEL commit_id=${COMMIT_ID}
LABEL build_time=${BUILD_TIME}

# --- Additional build-time args ---
ARG container_user=mosip
ARG container_user_group=mosip
ARG container_user_uid=1001
ARG container_user_gid=1001
ARG KUBECTL_VERSION=1.22.9

# --- Environment variables ---
ENV DISPLAY=:99
ENV work_dir=/home/${container_user}

# --- Install dependencies & setup user ---
RUN apk -q update && \
apk add --no-cache wget curl unzip xvfb libxi chromium chromium-chromedriver bash shadow && \
\
addgroup -g ${container_user_gid} ${container_user_group} && \
adduser -s /bin/sh -u ${container_user_uid} -G ${container_user_group} -h /home/${container_user} --disabled-password ${container_user} && \
\
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl" && \
chmod +x kubectl && mv kubectl /usr/local/bin/ && \
\
mkdir -p ${work_dir}/src/test/resources/ \
${work_dir}/test-output/SparkReport/ \
${work_dir}/screenshots/ && \
chmod -R 775 ${work_dir}

# Copy your application files into the container
COPY --chown=${container_user_uid}:${container_user} --chmod=771 ./entrypoint.sh ${work_dir}/entrypoint.sh
COPY --chown=${container_user}:${container_user} ./src/main/resources/ ${work_dir}/resources/
COPY --chown=${container_user_uid}:${container_user} ./target/*.jar ${work_dir}

# --- Fix permissions for entrypoint and JARs ---
RUN chmod +x ${work_dir}/entrypoint.sh && \
find ${work_dir} -name "*.jar" -exec chmod 644 {} \; && \
chown -R ${container_user}:${container_user} ${work_dir};

# --- Switch to non-root user ---
USER ${container_user_uid}:${container_user_gid}

# --- Set working directory ---
ENV work_dir=/home/${container_user}/

RUN groupadd -g ${container_user_gid} ${container_user_group} \
&& useradd -u ${container_user_uid} -g ${container_user_group} -s /bin/bash -m ${container_user} -d ${work_dir} \
&& chown -R ${container_user}:${container_user} /home/${container_user}/

USER ${container_user_uid}:${container_user_gid}
WORKDIR ${work_dir}

# --- Default entrypoint ---
ENTRYPOINT ["bash", "entrypoint.sh"]
# Source only — no fat jar. The suite runs via `mvn test` (Surefire → JUnit5 Platform →
# AdminTestRunner → Cucumber), same as a local run.
COPY --chown=${container_user_uid}:${container_user_group} pom.xml ${work_dir}
COPY --chown=${container_user_uid}:${container_user_group} src/ ${work_dir}src/
COPY --chown=${container_user_uid}:${container_user_group} entrypoint.sh ${work_dir}

# Resolves and caches all dependencies (including uitest-commons/apitest-commons) into this
# image's own .m2 and compiles the test sources, so a container start only has to run the suite.
RUN mvn -B test-compile -Dgpg.skip=true

ENTRYPOINT ["/bin/bash", "./entrypoint.sh"]
197 changes: 144 additions & 53 deletions uitest-admin/README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,148 @@
# Admin Automation

## Overview
Selenium webdriver based Admin Portal Automation covers CRUD(create, read, update and delete) operation performed via UI with Chrome driver

## Build
1. Build jar `mvn clean install`
2. Place jar in one folder along with src/main/resources files and folder
3. Run jar with vm args- ``` -Dpath=https://admin.dev.mosip.net/ -DKeyclockURL=https://iam.dev.mosip.net -Denv.user=api-internal.dev -Denv.endpoint=https://api-internal.dev.mosip.net jar nameofAdminJar.jar```

## Configurations
1. Update below keys from `Config.properties`
* langcode:eng -- Admin login page language selection description placed in `TestData.json`
* bulkwait:10000 -- Bulk upload wait

2. Update below keys from `TestData.json`
* setExcludedGroups:"" -- To run all the scenario mentioned below
* setExcludedGroups:"BL,CT" -- To exclude testcases execution based on below tags

3. Chrome driver place under working directory inside folder name chromedriver

## Below tags with scenarios
* blocklistedwordsCRUD: BL
* bulkUploadCRUD: BU
* centerCRUD: CTR
* centerTypeCRUD: CT
* deviceSpecCRUD: DS
* deviceCRUD: D
* deviceTypesCRUD: DT
* documentCategoriesCRUD: DOC
* documentTypesCRUD: DOCT
* dynamicFieldCRUD: DF
* holidaysCRUD: H
* machineSpecCRUD: MS
* machineCRUD: M
* machineTypesCRUD: MT
* templateCRUD: T

## Headless Mode
*Update below key from `TestData.json`
* hedless: "no" --To run in normal mode.
* hedless : "yes" --To run in headless mode

## Execution result and logs
1. Verify the failure in the logs file `\logs\AutomationLogs.log`
2. Execution results present under test-output folder file `emailable-report.html`
3. Extent results are present `\admintest\Reports`

#Usercreation
1.In config folder `\config\kernal.property`
2.on line no 27,36,38 chnage we can change the user(keep same at all three place)
3.
# Admin Portal UI Automation

Playwright + Cucumber (BDD) UI automation suite for the MOSIP Admin Portal, run through JUnit5's
Platform Suite engine. It covers create → filter → edit → activate → edit → deactivate (and
decommission, for resources) for every master data entity and resource the portal manages, plus
master data bulk upload (insert, update, delete).

Built on the shared [`uitest-commons`](https://github.com/mosip/mosip-functional-tests/tree/develop/uitestrig-platform)
library (browser lifecycle, Cucumber hooks, Extent reporting, Keycloak test users), the same way
as the Resident Portal suite in [`mosip/resident-ui/ui-test`](https://github.com/mosip/resident-ui/tree/develop/ui-test).

## Setup

`src/test/resources/config/adminui.properties` ships tracked in git with blank/default values. At
minimum, fill in `baseUrl`, `apiInternalEndPoint`, `keycloak-external-url`,
`mosip_admin_client_secret` and `mosip_testrig_client_secret` for your target environment —
**never commit real values back into this file**. Consider
`git update-index --skip-worktree src/test/resources/config/adminui.properties` locally so your
filled-in values never show up in `git status` (`--no-skip-worktree` to undo).

Every key can also be supplied as an environment variable of the same name, which wins over the file.

## Run the full suite

```
mvn test
```

Surefire only picks up `AdminTestRunner`, which runs every `.feature` file under
`src/test/resources/features/` through the Cucumber JUnit5 engine, 4 scenarios in parallel
(`-Dcucumber.execution.parallel.config.fixed.parallelism=<n>` to change).

## Run a subset

By exact scenario name (case-insensitive, comma-separated):
```
mvn test -DscenarioToRun="Center type CRUD,Device CRUD"
```
or set `scenarioToRun=` in `adminui.properties`; the `-D` flag wins if both are set.

By tag — each feature carries the name of the TestNG test it replaces, so the old
`setExcludedGroups` codes map as follows:
```
mvn test -Dcucumber.filter.tags="@centerCRUD or @deviceCRUD"
mvn test -Dcucumber.filter.tags="not @bulkUploadCRUD"
```

| Old code | Tag | Feature |
|---|---|---|
| BL | `@blocklistedwordsCRUD` | `blocklisted-words.feature` |
| BU | `@bulkUploadCRUD` | `bulk-upload.feature` |
| CTR | `@centerCRUD` | `center.feature` |
| CT | `@centerTypeCRUD` | `center-type.feature` |
| DS | `@deviceSpecCRUD` | `device-specification.feature` |
| D | `@deviceCRUD` | `device.feature` |
| DT | `@deviceTypesCRUD` | `device-type.feature` |
| DOC | `@documentCategoriesCRUD` | `document-category.feature` |
| DOCT | `@documentTypesCRUD` | `document-type.feature` |
| DF | `@dynamicFieldCRUD` | `dynamic-field.feature` |
| H | `@holidaysCRUD` | `holiday.feature` |
| MS | `@machineSpecCRUD` | `machine-specification.feature` |
| M | `@machineCRUD` | `machine.feature` |
| MT | `@machineTypesCRUD` | `machine-type.feature` |
| T | `@templateCRUD` | `template.feature` |

Area tags `@masterdata`, `@resources` and `@bulkupload` select whole groups.

## Run in Docker

```
docker build -t uitest-admin .
docker run -e ADMINUI_CONFIG_PATH=/home/mosip/config/adminui.properties \
-v /path/to/local/adminui.properties:/home/mosip/config/adminui.properties \
uitest-admin
```

The image (Microsoft's Playwright Java base image) compiles the test sources at build time and
runs `mvn -o test` at container start. `entrypoint.sh` copies the mounted config file over the
tracked `adminui.properties`; plain environment variables work too. The pre-Playwright
`adminPortalPath` variable is still accepted when `baseUrl` is not set.

## Local portal (ng serve)

When `baseUrl` points at `localhost`, the suite skips the Keycloak login (localhost is not an
allowed redirect, KER-ACP-009) and instead stores the admin token as an `Authorization` cookie on
`masterdatabaseurl` (e.g. a local kernel-masterdata-service on `http://localhost:8086`), launches
Chromium with web security off for the cross-origin calls, and answers the portal's audit-log
calls itself, since a local admin service does not serve them.

## Configuration

Property layers (lowest → highest), loaded by `AdminConfigManager.init()`:
1. `Kernel.properties` (apitest-commons JAR — MOSIP-wide defaults)
2. `uitest.properties` (uitest-commons JAR — browser defaults)
3. `adminui.properties` (this module)
4. Environment variables

Notable keys in `adminui.properties`: `loginlang` (Keycloak login language and the
`BulkUploadFiles/<loginlang>/` folder), `preappend` (prefix of the generated `${data}` value),
`bulkUploadStatusWaitSeconds`, and `cleanupMasterData` with `db-server`/`postgres-password`
(post-run deletion of the master data rows this run created; skipped while the password is blank).

## Architecture

1. `AdminTestRunner` (`runner/`) — JUnit5 `@Suite` entry point, no logic.
2. `AdminHooks` (`hooks/`) — suite lifecycle: loads config, creates the run's Keycloak admin user
(`<run-id>_admin-ui-auto`) and maps it to a leaf zone, generates the run's test data
(`AdminTestData`), and after the run cleans up master data (`AdminDbCleanup`) and the user.
3. Feature files drive generic steps in `steps/` (`MasterDataSteps` for every CRUD page,
`CenterSteps`, `BulkUploadSteps`), which drive page objects in `pages/`.

Feature files reference generated test data as `${name}` placeholders: `${data}`,
`${blocklistedWord}`, `${holidayDate}`, `${holidayDateCenter}`, `${validityDate}`, `${publicKey}`,
`${signPublicKey}`.

Scenarios that create types/specs and scenarios whose forms pick the first type/spec from a
dropdown are kept from running at the same time via Cucumber exclusive resources in
`junit-platform.properties`.

## Known issues

Add `bugId------Scenario name` lines to `src/test/resources/config/Known_Issues.txt`; matching
scenarios are skipped and reported with a link to the bug.

## Reports

Each run writes an Extent HTML report to `reportOutputDir` (default `test-output/`), named
`admin-ui-<env>-<date>-<time>-T-<total>-P-<passed>-F-<failed>-S-<skipped>-KI-<known>.html`.
Open the newest one in a browser. Per scenario it shows:

- each Gherkin step's text (with its data table) and every action under it, with locators;
- a screenshot before every element interaction, the element outlined in red
(`screenshotEveryAction=yes|no`);
- an embedded screen recording (`recordVideo=always|onFailure|off`; the default `onFailure` keeps it only for failed scenarios);
- for failed scenarios, a screenshot at the failing action and a Playwright trace — download
it from the report and drop it onto [trace.playwright.dev](https://trace.playwright.dev) (runs
locally in the browser) to replay every action with DOM snapshots, network calls and console
output (`traceOnFailure=yes|no`);
- the portal's own message after each create/update/activate/deactivate/decommission;
- API errors (HTTP ≥ 400, and MOSIP responses with an `errors` array such as `KER-MSD-…`) and
browser console errors seen after sign-in.

Screenshots, recordings and traces are embedded in the HTML, so the single report file can be
shared as is (and is what `push-reports-to-s3=yes` uploads). Each kept recording adds a few MB;
`recordVideo=always` makes the file large, and `screenshotEveryAction=no` keeps it small.

## License
This project is licensed under the terms of [Mozilla Public License 2.0](../LICENSE).

18 changes: 17 additions & 1 deletion uitest-admin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
#!/bin/bash
set -e

java --version
java -jar uitest-admin-*-jar-with-dependencies.jar
mvn --version

# Rancher mounts the equivalent of adminui.properties (URLs, secrets) as a ConfigMap/Secret file —
# not baked into the image, since the tracked file only holds blank defaults. Drop it where
# Maven's resource handling expects it, so `mvn test` picks it up exactly like a local run.
ADMINUI_CONFIG_PATH="${ADMINUI_CONFIG_PATH:-/home/mosip/config/adminui.properties}"
if [ -f "$ADMINUI_CONFIG_PATH" ]; then
cp "$ADMINUI_CONFIG_PATH" src/test/resources/config/adminui.properties
echo "Mounted config applied from $ADMINUI_CONFIG_PATH"
else
echo "No mounted config found at $ADMINUI_CONFIG_PATH — using adminui.properties from the image plus environment variables."
fi

# -o: dependencies were already resolved into this image's .m2 at build time.
# Exit code propagates mvn's own (non-zero on any test failure), so Rancher sees a failed Job.
mvn -o test -Dgpg.skip=true
Loading
Loading