# Automation Test Code: testgen

**English** · [Tiếng Việt](https://git.xylentis.com/tools/automation-test-code/-/blob/main/README.vi.md)

Record your actions on a website **once** with Playwright's recorder, then generate UI tests for **several frameworks and languages**.
It works like `npx playwright codegen`, but besides Playwright code it also generates Selenium tests, and it adds Go.
In the web UI you can edit each step, replay the recording and review warnings before saving the tests: **record → edit → replay → export**.

Step-by-step guide with examples for every target: **[User guide](https://git.xylentis.com/tools/automation-test-code/-/blob/main/docs/user-guide.md)** (`docs/user-guide.md`).

![The testgen UI](https://cdn.jsdelivr.net/npm/@xylentis/testgen@1/docs/testgen-ui.png)

| Target | Framework | Language | Generated files |
| --- | --- | --- | --- |
| `playwright-ts` | Playwright Test (`@playwright/test`) | TypeScript | `login.spec.ts` |
| `playwright-go` | [playwright-go](https://github.com/mxschmitt/playwright-go) + testify | Go | `login_test.go` |
| `selenium-java` | Selenium 4 + JUnit 5 | Java 17+ | `LoginTest.java` + `TestgenSupport.java` |
| `selenium-java-testng` | Selenium 4 + TestNG | Java 17+ | `LoginTest.java` + `TestgenSupport.java` |
| `selenium-js` | Selenium 4 + Mocha | JavaScript | `login.spec.js` + `testgen-support.js` |

## Install

Requires **Node.js 22+** (LTS 24 recommended).

```bash
npm install -g @xylentis/testgen     # installs the `testgen` command
testgen ui

npx @xylentis/testgen ui             # or run it directly, without installing
npm i -D @xylentis/testgen           # or install it in your project, then run `npx testgen ...`
```

Recording needs a browser. If **Google Chrome** is installed, just pick Chrome. To use Playwright's Chromium instead, download it with:

```bash
npx playwright-core install chromium
```

## Using the web UI (recommended)

```bash
testgen ui                  # opens http://127.0.0.1:9323
```

1. Enter a URL, pick a browser and click **Record**.
2. A browser window opens. Use the site like a real user would: click, type, select…
   - The recorder toolbar at the top of the page adds assertions: *Assert visibility*, *Assert text*, *Assert value*.
   - The Playwright Inspector window is hidden, so you only see the browser you are working in. To show it, use `testgen record --inspector`.
3. As you go, the testgen UI updates the **step list** and the **code for every target**.
4. Close the browser or click **Stop** when you are done.
5. Edit the steps if needed, click **Replay** to try them, then review **Checks** (see below).
6. For each target you can **Copy**, **Download**, or **Save files** straight into your project folder. Paths are relative to the folder where you ran `testgen ui`.

Other actions:

- **Change Test name / Package:** the code is regenerated immediately.
- **Test id attribute:** set it before clicking **Record**. The code always uses the attribute the recording used, so changing it after recording only affects the next recording. The UI shows a note when the two differ. See **Locators and multilingual sites (i18n)** below.
- **Log steps** (Selenium targets) and **Data-driven (CSV)** (all targets): see **Step logging and data-driven tests** below.
- **Download recording:** saves a `.jsonl` file so you can regenerate the code later. The file does not contain typed passwords; see **Passwords and sensitive data**.
- **Open recording…:** opens a saved file.

### Editing steps, Replay and Checks

- **Edit a step:** hover over a step (or Tab to it) to show **Edit**, **↑**, **↓**, **✕**. **Edit** lets you change:
  - the locator, written as in a Playwright test: `getByRole('button', { name: 'Sign in' })`, `getByLabel('Email')`, `getByTestId('save')`, `locator('#email')`;
  - the typed text, the selected value, the expected text or value of an assertion, the key (`Enter`, `Shift+Tab`), the URL, the upload file path;
  - the **Secret** field of a typing step: which environment variable the value is read from.

  **↑ ↓** reorder steps, **✕** deletes one, **Undo** reverts the last change. testgen blocks changes that would make a page get used before it is opened or after it is closed, for example deleting the step that opens a popup while later steps still work in that popup.
- **Replay:** runs the steps again with Playwright, in the browser the recording used. Each step shows ✓ or ✗. A failed step shows the error and a screenshot of the page at that moment; click **Edit step N** to fix it, then replay again. Replay runs the recording itself, so it tells you that the locators and data still work in Playwright. It does **not** tell you whether the Selenium code works (see **Current limitations**).
- **Checks:** things to review before using the test, for example: the recording has no assertions, the last steps are not checked, a locator relies on position (`nth(1)`) or page structure (XPath), an upload only has a file name, and things the current target cannot do (`// TODO(testgen)`). Click a line to jump to that step. `testgen record` and `testgen generate` print these warnings after generating code.

## Using the command line

```bash
# Record, then generate when you close the browser. Output goes to ./generated/<target>/ by default
testgen record https://your-app.example --channel chrome

# Only some targets, custom output folder
testgen record https://your-app.example -t selenium-java,playwright-go -d tests/generated

# Regenerate from a saved recording
testgen generate generated/recording.jsonl -t selenium-java -o src/test/java/com/acme/e2e/LoginTest.java
testgen generate generated/recording.jsonl -t playwright-go -o e2e/login_test.go
testgen generate generated/recording.jsonl -d out          # all targets, one folder per target

# TestNG, step logging, data read from src/test/resources/com/acme/e2e/SearchTest.csv
testgen generate generated/recording.jsonl -t selenium-java-testng --log-steps --data-driven \
  -o src/test/java/com/acme/e2e/SearchTest.java

# Playwright, data read from tests/search.csv; Go reads e2e/testdata/search.csv
testgen generate generated/recording.jsonl -t playwright-ts --data-driven -o tests/search.spec.ts
testgen generate generated/recording.jsonl -t playwright-go --data-driven -o e2e/search_test.go

testgen targets                                            # list the targets
```

| Option | Meaning |
| --- | --- |
| `-t, --target` | Comma-separated list of targets. Defaults to all of them. |
| `-o, --output` | Test file to write, only with a single target. Support files go next to the test file. |
| `-d, --out-dir` | Output folder. With several targets, each target gets its own subfolder. |
| `-n, --name` | Test name. Defaults to the `--output` file name, otherwise `recorded`. |
| `--package` | Java/Go package. Java takes it from the path after `src/test/java/`, Go from the folder name. |
| `--test-id-attribute` | Attribute the recorder uses for `getByTestId` (default `data-testid`). When generating code, testgen uses the attribute stored in the recording; this option only applies to recordings with no `getByTestId` steps. |
| `--log-steps` | (Selenium) Log each step and each assertion result while the test runs. |
| `--data-driven` | Typed, selected and asserted values become columns of a CSV file, and the test runs once per row. An existing CSV file is never overwritten. |
| `--save` | (`record`) Where to save the `.jsonl` recording, without typed passwords. |
| `--browser`, `--channel`, `--device`, `--viewport-size`, `--lang`, `--timezone`, `--color-scheme`, `--user-agent`, `--ignore-https-errors`, `--load-storage`, `--save-storage` | (`record`) Same as `playwright codegen`. |
| `--inspector` | (`record`) Also show the Playwright Inspector window (hidden by default). |

## Locators and multilingual sites (i18n)

testgen keeps the locators that Playwright's recorder picks. The recorder prefers, in this order:

1. test id: `getByTestId('welcome')`, using the `data-testid` attribute or the attribute set with `--test-id-attribute`;
2. role + name (the accessible name, usually the visible text): `getByRole('button', { name: 'Sign in' })`;
3. placeholder, label, alt, text, title;
4. `#id`; only then tag names and position.

`#id` comes late because ids are often generated by frameworks and change between builds (React's `:r1:`, Angular Material's `mat-input-0`). The recorder skips ids that look random altogether. For example, in the demo app `<input id="email">` has the label "Email", so it becomes `getByRole('textbox', { name: 'Email' })`, not `#email`.

So if the app has no test ids, most locators depend on the text on the page. A test recorded against the English UI breaks on the Vietnamese UI: `getByRole('button', { name: 'Sign in' })` does not match the button "Đăng nhập". There are three ways to handle this:

- **Pin the language when running tests.** Record with `--lang`, and the generated code sets the same locale (Selenium: adds `--lang` for Chrome and Edge):

  ```bash
  testgen record https://your-app.example --lang en-US
  ```

  This only helps when the app picks its language from the browser. If the app picks it from the URL (`/en/...`), a cookie or the account settings, pin the language there instead, for example by recording from a `/en/...` URL or using a test account with a fixed language.

- **Add test ids to the app.** This is the most robust option when one test has to run in several languages, because test ids always win. If the app uses a different attribute, declare it when recording, for example `--test-id-attribute data-qa`.

- **Use existing `id`s as test ids:** `--test-id-attribute id`, or enter `id` in the **Test id attribute** field of the UI. Elements with an id become `getByTestId('email')`; elements without one still use role + name. Only do this when the ids are written by people, because for test ids the recorder does not filter out generated ids.

The test id attribute is stored in the recording, and the generated code always uses that attribute. So choose it **before recording**. `--test-id-attribute` on `generate` only applies to recordings with no `getByTestId` steps.

## Passwords and sensitive data

Playwright's recorder records everything you type, including passwords. testgen keeps those values out of the tests:

- **Detection:** a typing step into a field whose locator calls it a password, PIN, OTP, verification code, token, API key… (in English, Vietnamese and a few other languages, for example `getByRole('textbox', { name: 'Mật khẩu' })`, `#txtPwd`, `input[type="password"]`) is a **secret** step.
- **The generated code reads an environment variable** named after the field: `TEST_PASSWORD`, `TEST_MAT_KHAU`, `TEST_OLD_PASSWORD`… Typing the same value twice (password and confirm password) shares one variable. An assertion that checks that exact value reads the same variable.

  ```java
  page.getByRole("textbox", "Password").fill(TestgenSupport.secret("TEST_PASSWORD"));   // Java
  ```
  ```ts
  await page.getByRole('textbox', { name: 'Password' }).fill(secret('TEST_PASSWORD'));  // TypeScript, JavaScript
  ```
  ```go
  testPassword, ok := os.LookupEnv("TEST_PASSWORD")                                     // Go
  require.True(t, ok, "set the environment variable TEST_PASSWORD, ...")
  ```

  If the variable is missing, the test stops right at the start with a message naming it. Java also reads system properties, so `mvn test -DTEST_PASSWORD=...` works too.
- **Values are not saved:** the recording saved by `testgen record` and the file from **Download recording** replace the value with `""` and store the variable name in the step (`"secret": "TEST_PASSWORD"`). Regenerating from that file gives the same code. When you replay such a recording, the UI asks for the value and keeps it only in the memory of `testgen ui`. `testgen generate` warns you when an older recording file still contains values.
- **Secrets inside other text** (for example an assertion on an element that shows the password, or the expected text `Saved for hunter2!`): the code uses `secret(...)` in that exact spot, for example `page.getByText(secret('TEST_PASSWORD'))`, and the recording stores `${TEST_PASSWORD}` instead of the value.
- **Logs:** `--log-steps` and the error messages of Selenium and Replay show secret values as `***`.
- **Fixing wrong guesses:** in the UI, **Edit** a typing step, then turn **Secret** on or off or rename the variable. A step that is already secret stays secret when you edit its locator. With the CLI, add `"secret": false` (not a secret) or `"secret": "VAR_NAME"` to that step's line in the `.jsonl` file.

## Running the generated tests

`e2e/projects/` has a sample project for each target. They are the very projects used to test testgen, so you can copy them and use them right away.

**playwright-ts**: needs `@playwright/test` (see `e2e/projects/playwright-ts`):

```bash
npm i -D @playwright/test && npx playwright install chromium
npx playwright test
```

**playwright-go**: note that the current module path is `github.com/mxschmitt/playwright-go`:

```bash
go get github.com/mxschmitt/playwright-go@v0.6201.1 github.com/stretchr/testify
go run github.com/mxschmitt/playwright-go/cmd/playwright install --with-deps chromium
go test ./...                 # HEADED=1 go test ./... to see the browser
```

**selenium-java**: needs `selenium-java` and `junit-jupiter` (see `e2e/projects/selenium-java/pom.xml`). `LoginTest.java` and `TestgenSupport.java` must be in the same package. Run it with `mvn test`.

**selenium-java-testng**: like `selenium-java`, but runs on TestNG (`@BeforeMethod`, `@AfterMethod`, `@Test`) and needs `selenium-java` and `testng` (see `e2e/projects/selenium-java-testng/pom.xml`). `TestgenSupport.java` is identical to the JUnit one. A failed assertion throws `AssertionError`, so TestNG reports that test as failed. Run it with `mvn test`.

**selenium-js**: needs `selenium-webdriver` and `mocha` (see `e2e/projects/selenium-js`). `testgen-support.js` must sit next to the test file. Run it with `npx mocha`.

Environment variables the Selenium tests understand:

- `HEADED=1`: show the browser.
- `SELENIUM_REMOTE_URL=http://grid:4444`: run on a Selenium Grid.
- `TESTGEN_TIMEOUT=15000`: auto-wait timeout in ms, 10000 by default.

The tests of every target also need their secret variables, for example `TEST_PASSWORD=... npx playwright test` (see **Passwords and sensitive data**).

### What the Selenium code looks like

Selenium has no `getByRole` or `getByText`, and it does not wait for elements on its own. So Selenium tests come with a **support file** (`TestgenSupport.java` / `testgen-support.js`) that keeps the generated code short and stable:

```java
page.navigate("http://127.0.0.1:4321/");
page.getByRole("textbox", "Email").fill("qa@example.com");
page.getByLabel("Country").selectOption("jp");
page.getByRole("button", "Sign in").click();
page.getByTestId("welcome").shouldContainText("Welcome, qa@example.com (jp)");
page.getByRole("listitem").filterHasText("Buy milk Delete").getByRole("button").click();
var page1 = page.waitForPopup(() -> page.getByRole("link", "Open help").click());
```

The JavaScript version uses **Playwright's own API** (`page.getByRole('button', { name: 'Sign in' })`, `expect(...).toHaveText(...)`). Its test body is therefore identical to the `playwright-ts` one; only the driver setup differs.

Underneath, it is still Selenium WebDriver: actions use `WebElement.click()`, `sendKeys()`, `Select` and `Actions`. The `driver` variable is still available in the test if you need to write plain Selenium code.

### Step logging and data-driven tests

These two options match the **Log steps** and **Data-driven (CSV)** fields in the UI.

**`--log-steps`** (`selenium-java`, `selenium-java-testng`, `selenium-js`): the test calls `page.setLogger(...)`. Each action is logged with its actual value (secrets show as `***`), and each assertion logs `passed` or `FAILED`. The TestNG version logs through `Reporter.log` (into the TestNG report and to the console); the JUnit and JavaScript versions print to the console. The two Playwright targets don't need this option: Playwright's report and trace already show every step.

```
02:51:07.955 page.getByRole("textbox", "Email").fill("dev@example.com")
02:51:08.121 page.getByTestId("welcome").shouldContainText("Welcome, dev@example.com (vn)") passed
02:51:28.390 page.getByTestId("welcome").shouldContainText("Welcome, wrong (vn)") FAILED, received: Welcome, dev@example.com (vn)
```

**`--data-driven`** (all targets): typed (`fill`), selected (`selectOption`) and asserted (`shouldHaveText`, `shouldContainText`, `shouldHaveValue`) values become columns of a CSV file. The test runs once per row, and each row gets its own pass/fail result. Secret values do not become columns: they are still read from environment variables.

```java
@DataProvider(name = "loginData")
public static Object[][] loginData() {
    return TestgenSupport.readCsv(LoginTest.class, "LoginTest.csv", "email", "password", "expectedWelcome");
}

@Test(dataProvider = "loginData")
public void login(String email, String password, String expectedWelcome) {
    page.getByRole("textbox", "Email").fill(email);
    page.getByRole("textbox", "Password").fill(password);
    page.getByRole("button", "Sign in").click();
    page.getByTestId("welcome").shouldContainText(expectedWelcome);
}
```

The TypeScript, JavaScript and Go versions read each line into `row`:

```ts
const rows = readCsv(path.join(__dirname, 'login.csv'), ['email', 'expectedWelcome']);

for (const [index, row] of rows.entries()) {
  test(`login (row ${index + 1})`, async ({ page }) => {
    await page.getByRole('textbox', { name: 'Email' }).fill(row.email);
    await page.getByRole('textbox', { name: 'Password' }).fill(secret('TEST_PASSWORD'));
    await page.getByRole('button', { name: 'Sign in' }).click();
    await expect(page.getByTestId('welcome')).toContainText(row.expectedWelcome);
  });
}
```

| Target | CSV file | Each row runs as |
| --- | --- | --- |
| `selenium-java`, `selenium-java-testng` | `<Name>Test.csv`, a resource in the same package as the test class. When the test file is under `src/test/java/<package>/`, testgen writes the CSV to `src/test/resources/<package>/`. | one run of `@ParameterizedTest` (JUnit) or `@Test(dataProvider = ...)` (TestNG) |
| `playwright-ts` | `<name>.csv` next to the `.spec.ts` file, plus the support file `testgen-data.ts` | a test `<name> (row N)` |
| `selenium-js` | `<name>.csv` next to the `.spec.js` file | an `it` `<name> (row N)` |
| `playwright-go` | `testdata/<name>.csv`, plus the support file `testgen_data_test.go` | a subtest `row_N` (`go test -run 'TestLogin/row_2'`) |

- **Rows in the CSV:** the first line holds the column names, the second the values from the recording. Add lines to add data sets.
- **No overwriting:** testgen never overwrites an existing CSV file (it reports `kept`). To regenerate it from scratch, delete the file.
- **Column names** come from the input or the asserted element: `Email` → `email`, the placeholder `Tìm kiếm sản phẩm...` ("Search products...") → `timKiemSanPham`, an assertion on `getByTestId("welcome")` → `expectedWelcome`. Typing the same value several times shares one column.
- **Locators follow the data** when the text in a locator equals, or contains as whole words, a value typed earlier. For example, you search for "Những Kẻ Mê Sách" and then click the link "Những Kẻ Mê Sách": the link uses the same column as the search term. You add the to-do "Buy milk" and then click the delete button of the item "Buy milk Delete": the locator becomes `filterHasText(whatNeedsToBeDone + " Delete")`. Values shorter than 3 characters are only replaced on an exact match, because "1" could be part of any number. All other text stays as recorded.
- **Assertions get their own column:** expected text such as `Welcome, qa@example.com (jp)` is a separate column, even when it contains a typed value. Each row must hold the exact expected text for that row.
- **Opening in Excel:** generated files have a BOM, so Excel shows Vietnamese and other non-ASCII text correctly. Every target reads both commas and semicolons (Excel saves with `;` in some locales), and skips blank lines and extra columns, for example a `note` column that describes each row.

## How it works

```
 You use the site in a browser
        │  Playwright's recorder (like `playwright codegen --target=jsonl`, Inspector hidden) records each step
        ▼
 recording.jsonl   ── a list of steps, not tied to any language (click, fill, assertText…)
        │  selector → locator string: reuses Playwright's code (src/vendor/playwright)
        ▼
 Generators (src/generators/*)
   ├─ playwright-ts          like `playwright codegen --target playwright-test`
   ├─ playwright-go          playwright-go API + require.NoError
   ├─ selenium-java          JUnit 5 + TestgenSupport.java
   ├─ selenium-java-testng   TestNG + TestgenSupport.java
   └─ selenium-js            Mocha + testgen-support.js
                                 └─ runtime/selenium/engine.js: runs in the page (executeScript)
                                    to find elements by role / text / label / test id… like Playwright
```

- **Recorder:** Playwright's recorder as is, so locators are chosen (test id first, then role + name, label…) exactly as in Playwright codegen.
- **Locator engine for Selenium:** tested by comparing its results with Playwright's own on 70 sample locators (`test/engine.test.ts`).
- **Between the recording and the generators:** `src/secrets.ts` finds secret steps, `src/generators/test-data.ts` decides whether each value is a literal, a CSV column or an environment variable, and `src/checks.ts` produces the warnings. The UI edits the recording with `src/editing.ts` (locators typed by hand are turned back into selectors with Playwright's code) and replays it with `src/replay.ts` (`playwright-core`).

## Current limitations

- **The JSONL format is Playwright's internal format.** That is why `playwright-core` is pinned at `1.63.0`. When upgrading, rerun `npm test` and `npm run e2e` (see `src/vendor/playwright/README.md`).
- **Selenium cannot do the following**, so those places get a `// TODO(testgen)` comment:
  - wait for downloads;
  - aria snapshot assertions (replaced with a visibility check);
  - middle click;
  - full device emulation (only the viewport and user agent are applied);
  - `colorScheme` / `timezone` / `geolocation`;
  - saving the storage state.
- **`getByRole` on Selenium is approximate**, because the accessible name algorithm is simplified. When it gets something wrong, add a `data-testid` to the app, or add that case to `test/engine.test.ts`.
- **Recordings do not store the full path of uploaded files**, only the file name. Edit that step in the UI (the **Files** field, one path per line) or fix `setInputFiles(...)` in the test. Replay skips the upload step when it cannot find the file.
- **Replay runs the recording on Playwright**, not the generated code. A passing replay does not guarantee that the Selenium test passes, because `getByRole` on Selenium is approximate (see above). To be sure, run the generated test itself, as `npm run e2e` does with the demo app.
- **Secret detection relies on the locator**, not on the field's `type="password"`. A field with no telling label or id (for example `#field3`) is not detected: review **Checks** and turn on **Secret** in the UI. Conversely, turn it off for a field that has "password" in its name but is not a password.
- **Playwright's report and trace still show the values typed into fields**, including values read from environment variables. Don't share them outside your team if the tests use real passwords.
- **`--log-steps` is for Selenium only.** The two Playwright targets ignore it, and the CLI and UI tell you when they do.

## Development

The npm package only contains the build. To change the code, work in the repository:

```bash
npm ci            # builds automatically (prepare script); run the tool with `node dist/cli.js`
npm test          # vitest: compares the engine with Playwright, snapshots generated code, tests the UI (needs Chrome)
npm run e2e       # generates tests for every target and runs them against the demo app e2e/app (needs Go, JDK 17+ and Maven, Chrome)
E2E_TARGETS="selenium-js playwright-go" npm run e2e
```

- **Re-recording the demo:** start the app (`e2e/app`) on port 4321, then run `node e2e/record-demo.mjs`. The script drives Playwright's real recorder, so nobody has to click through it.
- **The code generated for the 2 sample recordings** is stored as snapshots in `test/__snapshots__/`. After changing a generator, run `npx vitest run -u` and review the diff.
- **Adding a new target:**
  1. Write a `Generator` in `src/generators/` and register it in `src/generators/index.ts`.
  2. Add a sample project in `e2e/projects/`.
  3. Add a run step in `e2e/run.sh`.

```
src/            CLI (cli.ts), recording reader, generators, UI server (ui/server.ts)
src/vendor/     code taken from Playwright (Apache-2.0), see NOTICE
runtime/        Selenium support files (Java, JS) + the in-page locator engine
ui/             web UI (plain HTML/CSS/JS, no build step)
test/           unit tests, fixtures, snapshots
e2e/            demo app, real recordings, sample projects for each target, run.sh
scripts/        npm release script (release.mjs)
```

### Publishing to npm

GitLab CI ([.gitlab-ci.yml](.gitlab-ci.yml)) runs the tests on every push. To release a new version:

1. Write the changes under `## Unreleased` at the top of `CHANGELOG.md` and commit.
2. Run `npm run release -- patch` (or `minor`, `major`, `1.2.3`). The script runs its checks and the tests, bumps the version in `package.json` and `package-lock.json`, renames `## Unreleased` to `## <version> (<date>)`, commits `chore: release <version>`, then pushes `main` together with the tag `v<version>`.
3. The tag's pipeline runs the tests, then stages that version on npm (`npm stage publish`).
4. Approve it with 2FA to make it live: `npm stage list @xylentis/testgen`, then `npm stage approve <stage-id>`, or click **Approve** in the **Staged Packages** tab of the package page on npmjs.com.

```bash
npm run release -- patch        # or minor, major, 1.2.3
npm run release                 # release the version already in package.json (CHANGELOG.md must have a `## <version>` section)
npm run release -- --dry-run    # dry run: checks, tests and `npm pack --dry-run`, changes nothing
```

Before tagging, the script checks that you are on `main`, have no uncommitted changes and are not behind `origin/main`, that the version is not on npm yet and is newer than `latest`, and that there is no `v<version>` tag yet. `npm run e2e` needs Go, a JDK and Maven, so neither the script nor CI runs it; run it yourself when you change a generator or the Selenium runtime.

**Why approval is still manual:** npm does not support trusted publishing (OIDC) for self-hosted GitLab yet, and tokens that bypass 2FA lose the right to publish directly from January 2027. So CI only uses a "stage only" token: even if it leaks, it cannot publish.

**Approve in version order.** The version you approve becomes `latest`, even if a newer version already exists. Drop stages you no longer need with `npm stage reject <stage-id>`.

**One-time setup:**

1. On npmjs.com: **Access Tokens → Generate New Token**, permission **Read and write (stage only)**, for the `@xylentis/testgen` package only. Tokens with write access expire after 90 days at most, so recreate it regularly.
2. Save the token as the project's CI/CD variable `NPM_TOKEN` with **Masked** and **Protected** turned on: in GitLab (**Settings → CI/CD → Variables**), or copy the token and run `pbpaste | glab variable set NPM_TOKEN --masked --protected`.
3. Protect `v*` tags (**Settings → Repository → Protected tags**) so that tag pipelines receive protected variables: `glab api -X POST projects/:id/protected_tags -f name='v*' -f create_access_level=40`.

## License

[GNU AGPL-3.0-only](LICENSE), Copyright (C) 2026 Xylentis.

- **testgen:** anyone who modifies testgen and distributes it, including running it as a network service, must publish the source of their modified version under the AGPL.
- **Generated code:** tests generated by testgen and the support files that come with them (`TestgenSupport.java`, `testgen-support.js`, the engine) may be used, modified and distributed **freely** in your tests, under an additional permission granted under section 7 of the AGPL. That permission does not allow using those files to build another code generator. See [NOTICE](NOTICE).
- **Code taken from Playwright:** the files in `src/vendor/playwright` remain under the Apache License 2.0.
