import { defineConfig, devices } from '@playwright/test';
import { nxE2EPreset } from '@nx/playwright/preset';
import { workspaceRoot } from '@nx/devkit';
// For CI, you may want to set BASE_URL to the deployed application.
const baseURL = process.env['BASE_URL'] || 'http://localhost:4200';
const isCI = process.env['CI'] === 'true' || process.env['GITHUB_ACTIONS'] === 'true';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
...nxE2EPreset(__filename, { testDir: './src' }),
/* Global test timeout - prevent hanging tests in CI */
timeout: 45000, // 45 seconds per test for server startup
/* Expect timeout for assertions */
expect: {
timeout: 15000, // 15 seconds for expect assertions
},
/* Fail the build on CI if you accidentally left test.only in the source code */
forbidOnly: !!isCI,
/* Retry on CI only */
retries: isCI ? 2 : 0,
/* Opt out of parallel tests on CI */
workers: isCI ? 1 : undefined,
/* Reporter to use */
reporter: isCI ? [['line'], ['github']] : [['html', { open: 'never' }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
/* Screenshot only on failure to reduce artifacts */
screenshot: 'only-on-failure',
/* Video only on failure in CI */
video: isCI ? 'retain-on-failure' : 'off',
},
/* Run your local dev server before starting the tests */
webServer: isCI ? undefined : {
command: 'npx nx run askme-ui:serve',
url: 'http://localhost:4200',
reuseExistingServer: true,
cwd: workspaceRoot,
timeout: 120000, // 2 minutes max for server startup
stdout: 'pipe',
stderr: 'pipe',
},
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
hasTouch: true, // Enable touch support for testing mobile interactions
},
},
{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
hasTouch: true, // Enable touch support for testing mobile interactions
},
},
{
name: 'webkit',
use: {
...devices['Desktop Safari'],
hasTouch: true, // Enable touch support for testing mobile interactions
},
},
// Uncomment for mobile browsers support
/* {
name: 'Mobile Chrome',
use: { ...devices['Pixel 5'] },
},
{
name: 'Mobile Safari',
use: { ...devices['iPhone 12'] },
}, */
// Uncomment for branded browsers
/* {
name: 'Microsoft Edge',
use: { ...devices['Desktop Edge'], channel: 'msedge' },
},
{
name: 'Google Chrome',
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
} */
],
});