Test Tenant Management System (TMS) Integration#
The Test Tenant Management System (TMS) integration allows you to manage test scenarios and user authentication in a centralized way. This page explains how to configure and use TMS with Playwright tests.
Overview#
TMS integration is provided by the @paeng/playwright-tms package and helps you:
Define scenarios with specific environments and regions
Manage multiple user accounts for testing
Handle authentication automatically
Access scenario details in your tests
Key Benefits#
Secure authentication - No hardcoded credentials
Scenario-based testing - Different users for different scenarios
Consistent configuration - Standardized across teams
Environment management - Easy switching between environments
Configuration#
TMS integration adds a tms section to your config.json file which defines your scenarios:
{
"tms": [
{
"name": "<Name of your scenario, this should be unique>",
"env": "<The environment of your scenario e.g. test, prod, etc. >",
"region": "<The region of your scenario e.g. wus, eus >",
"cluster": "<The cluster number of your scenario as a string e.g. 201>",
"serviceTreeId": "<Your service tree id>",
"scenarioId": "<The scenario id>",
"defaultAlias": "<The default user to authenticate tests with>",
"userScenarios": [
{
"alias": "<An alias for the user associated with the scenario>",
"scenarioId": "<The scenario id of a scenario that provides a user>"
}
]
}
]
}
For detailed information on configuring TMS scenarios, including best practices and troubleshooting tips, see the TMS Scenarios Configuration page.
Example Configuration#
Here’s a sample configuration for a PowerApps maker scenario:
{
"tms": [
{
"name": "PowerAppsMaker",
"env": "test",
"region": "wus",
"cluster": "201",
"serviceTreeId": "12345",
"scenarioId": "67890",
"defaultAlias": "MakerUser",
"userScenarios": [
{
"alias": "AdminUser",
"scenarioId": "54321"
}
]
}
]
}
Authentication Flow#
Set the
TMS_SCENARIOenvironment variable to your scenario nameRun
npm run login-tmsto authenticate with TMSThe TMS fixture provides authentication tokens in tests
export TMS_SCENARIO=PowerAppsMaker
npm run login-tms
TMS Test Fixture#
To use TMS details in your tests, you need to use the test method provided by @paeng/playwright-tms. The fixture gives you access to scenario information and user details during test execution.
Basic Usage#
import { test } from "@paeng/playwright-tms";
test("My TMS test", async ({ page, tms }) => {
console.log("TMS scenario:", tms.scenario);
console.log("TMS user:", tms.user);
// Run your test using TMS information
// ...
});
Merging with Existing Test Fixtures#
If your tests already use custom fixtures, you’ll need to merge them using the mergeTests method:
import { test as baseTest } from "@playwright/test";
import { test as tmsTest } from "@paeng/playwright-tms";
import { mergeTests } from "@playwright/test";
// Merge your base test with TMS test
const test = mergeTests(baseTest, tmsTest);
test("Test with merged fixtures", async ({ page, tms, myCustomFixture }) => {
// Use both TMS and your custom fixtures
});
Using with Integration Test Wrapper#
If you are using the integrationTest function provided by @paeng/playwright-solution, you’ll need to switch to the version provided in src/utils/integrationTest.ts as the existing function doesn’t support custom fixtures.
Key Differences#
The new version of integrationTest wraps several tests with the same environment configuration, while the old version wrapped individual tests directly:
// Old approach
integrationTest(config, owner, title1, async ({ page }) => {});
integrationTest(config, owner, title2, async ({ page }) => {});
// New approach with TMS
integrationTest(config, owner, (format) => {
test(format(title1), async ({ page, tms }) => {});
test(format(title2), async ({ page, tms }) => {});
});
Note that with the new approach:
You receive a format function to apply to test titles
You need to manually format each test title
You can add multiple test cases with the same configuration
You have access to the
tmsfixture in each test
Adding Playwright Global for Compatibility#
If your tests depend on the window.__PLAYWRIGHT__ global being defined (which was added by the old wrapper), you can re-add it:
import {
integrationTest,
addPlaywrightGlobal,
} from "src/utils/integrationTest";
test.beforeEach("Add __PLAYWRIGHT__ global", async ({ context }) => {
await addPlaywrightGlobal(context);
});
Running TMS Tests Locally#
To use TMS locally, follow these steps:
Set the
TMS_SCENARIOenvironment variable to your scenario name fromconfig.json:
# Windows
set TMS_SCENARIO=PowerAppsMaker
# Linux/macOS
export TMS_SCENARIO=PowerAppsMaker
# Or add to your .env file
echo "TMS_SCENARIO=PowerAppsMaker" >> .env
Run the login script to authenticate all users specified in the scenario:
npm run login-tms
Run your tests:
npm run int-test
Running TMS Tests in Pipeline#
To run your TMS tests in a pipeline:
Update your pipeline to call
run-playwright-tests.ymlSpecify your scenario name with the
tmsScenarioparameter:
parameters:
- name: tmsScenario
displayName: TMS Scenario Name
type: string
default: PowerAppsMaker
Best Practices#
Separate user roles: Define different users for different roles (admin, regular user, etc.)
Reuse scenarios: Use the same scenario across related tests
Environment variables: Store sensitive values in environment variables, not in the config
Unique scenario names: Use descriptive, unique names for your scenarios
Clear user aliases: Use clear, descriptive aliases that indicate the user’s role
Common Issues and Solutions#
Issue |
Solution |
|---|---|
Authentication failure |
Run |
Missing scenario |
Verify TMS_SCENARIO matches a name in config.json |
User not found |
Check userScenarios array in your TMS configuration |
Next Steps#
See TMS Scenarios Configuration for details on creating and configuring your own TMS scenarios.