1// Copyright (C) 2024 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {defineConfig} from '@playwright/test'; 16import * as os from 'os'; 17 18const isMac = os.platform() === 'darwin'; 19const isCi = Boolean(process.env.CI); 20const outDir = process.env.OUT_DIR ?? '../out/ui'; 21 22// Installed by test/ci/ui_tests.sh 23const ciChromePath = '/ci/ramdisk/chrome/opt/google/chrome/google-chrome'; 24 25export default defineConfig({ 26 testDir: './src', 27 snapshotDir: '../test/data/ui-screenshots', 28 snapshotPathTemplate: '{snapshotDir}/{testFileName}/{testName}/{arg}{ext}', 29 outputDir: `${outDir}/ui-test-results`, 30 fullyParallel: true, 31 retries: isCi ? 2 : 0, // Retry only in CI 32 workers: isCi ? 1 : undefined, // No parallelism in CI. 33 reporter: [ 34 [ 35 'html', 36 { 37 outputFolder: `${outDir}/ui-test-artifacts`, 38 open: isCi ? 'never' : 'on-failure', 39 }, 40 ], 41 ], 42 43 expect: { 44 timeout: 5000, 45 toHaveScreenshot: { 46 // Rendering is not 100% identical on Mac. Be more tolerant. 47 maxDiffPixelRatio: isMac ? 0.05 : undefined, 48 }, 49 }, 50 51 use: { 52 baseURL: 'http://127.0.0.1:10000', 53 trace: 'off', 54 }, 55 56 projects: [ 57 { 58 name: 'chromium', 59 use: { 60 headless: true, 61 viewport: {width: 1920, height: 1080}, 62 launchOptions: { 63 executablePath: isCi ? ciChromePath : undefined, 64 args: [ 65 '--disable-accelerated-2d-canvas', 66 '--disable-font-subpixel-positioning', 67 '--disable-gpu', 68 '--disable-lcd-text', 69 '--font-render-hinting=none', 70 '--force-device-scale-factor=1', 71 '--hide-scrollbars', 72 '--enable-skia-renderer', 73 '--js-flags=--random-seed=1', 74 ], 75 }, 76 ignoreHTTPSErrors: true, 77 trace: 'off', 78 screenshot: 'on', 79 channel: 'chrome', 80 video: 'off', 81 }, 82 }, 83 ], 84 85 webServer: { 86 command: './run-dev-server ' + (process.env.DEV_SERVER_ARGS ?? ''), 87 url: 'http://127.0.0.1:10000', 88 reuseExistingServer: true, 89 timeout: 5 * 60 * 1000, 90 stdout: 'pipe', 91 }, 92}); 93