Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Bài viết này tài liệu cấu hình Playwright được sử dụng bởi các thử nghiệm mẫu và giải thích làm thế nào để điều chỉnh nó cho môi trường của riêng bạn.
playwright.config.ts
Tệp cấu hình là tại packages/e2e-tests/playwright.config.ts:
import { defineConfig, devices } from '@playwright/test';
import path from 'path';
import { getStorageStatePath } from 'power-platform-playwright-toolkit';
import dotenv from 'dotenv';
dotenv.config();
const storageStatePath = getStorageStatePath(process.env.MS_AUTH_EMAIL!);
const mdaStorageStatePath = path.join(
path.dirname(storageStatePath),
`state-mda-${process.env.MS_AUTH_EMAIL}.json`
);
export default defineConfig({
testDir: './tests',
fullyParallel: false, // Power Platform tests share a single org; run serially
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
workers: 1, // Single worker prevents auth conflicts
reporter: [
['html', { outputFolder: 'playwright-report' }],
['junit', { outputFile: 'test-results/results.xml' }],
],
use: {
baseURL: process.env.CANVAS_APP_URL,
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
projects: [
{
name: 'canvas',
use: {
...devices['Desktop Chrome'],
storageState: storageStatePath,
},
testMatch: '**/canvas/**/*.test.ts',
},
{
name: 'mda',
use: {
...devices['Desktop Chrome'],
storageState: mdaStorageStatePath,
},
testMatch: '**/mda/**/*.test.ts',
},
],
globalSetup: './globals/global-setup',
globalTeardown: './globals/global-teardown',
});
Các tùy chọn cấu hình chính
Các phần sau đây giải thích các thiết đặt quan trọng nhất trong tệp cấu hình và thời điểm thay đổi chúng.
fullyParallel và workers
Kiểm tra Power Platform chia sẻ một môi trường Dataverse duy nhất. Chạy kiểm tra song song sẽ tạo ra xung đột dữ liệu, chẳng hạn như hai kiểm tra xóa cùng một bản ghi. Đặt cả hai tùy chọn để thực hiện nối tiếp hóa:
fullyParallel: false,
workers: 1,
Lưu ý
Nếu bạn có nhiều môi trường, bạn có workers.env thể tăng và cô lập mỗi dự án vào một môi trường khác nhau bằng cách sử dụng các tệp riêng biệt hoặc các biến mức môi trường.
retries
Retries có thể mặt nạ flakiness trong CI. Sử dụng retries: 1 ci để xử lý các vấn đề mạng thoáng qua. Đặt cục retries: 0 bộ để nhận phản hồi ngay lập tức:
retries: process.env.CI ? 1 : 0,
trace, , screenshotvideo
Chỉ chụp chẩn đoán khi không tiết kiệm dung lượng đĩa:
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
Trong CI, artifacts được tải lên sau khi chạy thử nghiệm. Xem tích hợp CI/CD.
projects
Sử dụng các dự án Playwright để phân tách bức vẽ và bộ kiểm tra dựa trên mô hình. Mỗi dự án có thể sử dụng một trạng thái lưu trữ khác nhau:
projects: [
{
name: 'canvas',
use: { storageState: storageStatePath },
testMatch: '**/canvas/**/*.test.ts',
},
{
name: 'mda',
use: { storageState: mdaStorageStatePath },
testMatch: '**/mda/**/*.test.ts',
},
],
Chạy một dự án duy nhất:
npx playwright test --project=canvas
npx playwright test --project=mda
globalSetup
Script thiết lập toàn cầu chạy một lần trước khi tất cả các xét nghiệm. Quy trình xác thực trạng thái xác thực và chạy xác thực không có đầu nếu trạng thái lưu trữ hết hạn hoặc bị thiếu:
// global-setup.ts
import { validateAndRefreshAuthState } from './utils/validate-auth-state';
export default async function globalSetup() {
await validateAndRefreshAuthState();
}
Kiểm tra xác thực:
- Tệp trạng thái lưu trữ tồn tại
- Mã thông báo truy nhập MSAL chưa hết hạn (kiểm tra UX thế hệ/bảng tùy biến)
- Cookie phiên CRM có mặt và hợp lệ (kiểm tra MDA)
tsconfig.json
Tệp tsconfig.json điều khiển thiết đặt biên dịch TypeScript cho gói kiểm tra:
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"outDir": "dist",
"rootDir": "."
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
.env Tập tin
Tệp .env lúc đặt packages/e2e-tests/.env biến môi trường cho chạy cục bộ. Để tham khảo đầy đủ, hãy xem Biến môi trường.
MS_AUTH_EMAIL=testuser@contoso.com
MS_AUTH_CREDENTIAL_TYPE=password
MS_USER_PASSWORD=<your-password>
CANVAS_APP_URL=https://apps.powerapps.com/play/<app-id>?tenantId=<tenant-id>
MODEL_DRIVEN_APP_URL=https://<org>.crm.dynamics.com/main.aspx?appid=<app-id>
CUSTOM_PAGE_NAME=AccountsCustomPage
package.json Kịch bản
Các tập lệnh npm sau đây có sẵn để xác packages/e2e-tests/package.json thực và thực thi kiểm tra:
| Kịch bản | Lệnh | Description |
|---|---|---|
auth:headful |
ts-node auth/auth-maker-portal.ts |
Xác thực tương tác cho Power Apps (kiểm tra bức vẽ) |
auth:mda:headful |
ts-node auth/auth-mda.ts |
Xác thực tương tác cho các ứng dụng dựa trên mô hình |
auth |
ts-node auth/auth-maker-portal.ts --headless |
Xác thực không đầu (CI) |
auth:mda |
ts-node auth/auth-mda.ts --headless |
Xác thực ứng dụng điều khiển bằng mô hình không đầu (CI) |
test |
playwright test |
Chạy tất cả các kiểm tra |
test:ui |
playwright test --ui |
Chạy với Giao diện Người dùng Playwright |
test:debug |
playwright test --debug |
Chạy với trình kiểm tra gỡ lỗi |