这就是我剧作家配置的样子。
import { resolve } from 'path';
import { defineConfig, devices } from '@playwright/experimental-ct-react';
export default defineConfig({
testDir: './playwright-ct',
/* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
snapshotDir: './playwright-ct/__snapshots__',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [['html', { open: 'on-failure' }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'retain-on-failure',
baseURL: 'https://localhost',
// baseURL: process.env.STAGING === '1' ? 'http://staging.example.test/' : 'http://example.test/',
/* Port to use for Playwright component endpoint. */
ctPort: 3100,
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
},
{
name: 'Mobile Chrome',
use: {
...devices['Pixel 5']
}
}
]
});
这是一些测试示例
test.beforeAll(async ({ mount }) => {
await mount(<ComponentA />);
});
test.beforeEach(async ({ page }) => {
let requestURL;
await page.route('/abcd/sax/**', async (route) => {
requestURL = route.request().url();
route.continue();
});
await page.waitForLoadState('networkidle');
});
test('PRODUCT SHARE CLICK EVENT', async ({ page }) => {
await page.locator('[data-auto-id="btn1"]').click();
expect(requestURL).toContain('SHARE');
});
test('SIZE CHANGE EVENT', async ({ page }) => {
await page.locator('[data-auto-id="BTN2"]').click();
await expect(requestURL).toContain('SIZE');
});
当我在构建管道上运行它们时,它们在本地运行良好,我收到以下错误日志。
2023-03-09 15:00:27 browserType.launch: Browser closed.
2023-03-09 15:00:27 ==================== Browser output: ====================
2023-03-09 15:00:27 <launching> /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-o7zE6N --remote-debugging-pipe --no-startup-window
2023-03-09 15:00:27 <launched> pid=6887
2023-03-09 15:00:27 [pid=6887][err] /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome: symbol lookup error: /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome: undefined symbol: gbm_bo_get_modifier
jenkins 似乎正在尝试打开浏览器来运行测试,这很奇怪,因为它应该无头运行,或者我不确定这里会发生什么。