在 Azure 管道上运行测试时,我收到 BrowserStack 结果任务的以下错误:按名称找不到构建。这是用于使用 Typescript 运行 Playwright 的自动化测试。
我尝试在不同的位置添加 buildName 变量,但找不到将其放置在代码中的正确位置。
不确定是否相关,但我收到警告“
运行 npm 自定义任务时找不到密钥的 loc 字符串:Info_GotAndMaskAuth'
playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
import { config } from 'dotenv';
const defaultEnv = process.env.ENV_VARS || 'qa';
const buildName = process.env.BROWSERSTACK_BUILD_NAME;
config({
path: `./env/.env.${defaultEnv}`, // or '.env'
});
require('dotenv').config();
export default defineConfig({
metadata: {
actionTimeout: 1000, // The maximum time for running a single action (in milliseconds).
shortTimeout: 3000,
mediumTimeout: 30000,
longTimeout: 40000,
veryLongTimeout: 50000
},
testDir: './tests',
/* 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 ? 1 : 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: 'never' }], ["line"], ['list', { printSteps: true }], ['json', { outputFile: 'test-results.json' }], ['junit', { outputFile: 'results.xml' }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
baseURL: '',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on',
screenshot: 'on',
video: 'on',
actionTimeout: 5000
},
timeout: 0,
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
}
},
],
});
2024-07-22T16:31:13.7669932Z ##[debug]Evaluating condition for step: 'BrowserStack Results.'
2024-07-22T16:31:13.7672186Z ##[debug]Evaluating: succeeded()
2024-07-22T16:31:13.7672559Z ##[debug]Evaluating succeeded:
2024-07-22T16:31:13.7673601Z ##[debug]=> True
2024-07-22T16:31:13.7674296Z ##[debug]Result: True
2024-07-22T16:31:13.7675096Z ##[section]Starting: BrowserStack Results.
2024-07-22T16:31:14.0459711Z ==============================================================================
2024-07-22T16:31:14.0459910Z Task : BrowserStack Results
2024-07-22T16:31:14.0459993Z Description : This task helps in showing BrowserStack results.
2024-07-22T16:31:14.0460131Z Version : 1.1.1
2024-07-22T16:31:14.0460203Z Author : BrowserStack
2024-07-22T16:31:14.0460359Z Help :
2024-07-22T16:31:14.0460418Z ==============================================================================
2024-07-22T16:31:14.0899651Z ##[debug]Using node path: D:\Agents-CloudUI\C201MK27-UI-01\externals\node\bin\node.exe
2024-07-22T16:31:14.7427767Z ##[debug]agent.TempDirectory=D:\Agents-CloudUI\C201MK27-UI-01\_work\_temp
2024-07-22T16:31:14.7466626Z ##[debug]loading inputs and endpoints
2024-07-22T16:31:14.7474077Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2024-07-22T16:31:14.7573886Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2024-07-22T16:31:14.7581044Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2024-07-22T16:31:14.7587576Z ##[debug]loading INPUT_BROWSERSTACKPRODUCT
2024-07-22T16:31:14.7601044Z ##[debug]loaded 4
2024-07-22T16:31:14.7634656Z ##[debug]Agent.ProxyUrl=undefined
2024-07-22T16:31:14.7636390Z ##[debug]Agent.CAInfo=undefined
2024-07-22T16:31:14.7636727Z ##[debug]Agent.ClientCert=undefined
2024-07-22T16:31:14.7637060Z ##[debug]Agent.SkipCertValidation=undefined
2024-07-22T16:31:15.1868759Z ##[debug]browserstackProduct=automate
2024-07-22T16:31:15.1869690Z ##[debug]BROWSERSTACK_USERNAME=***-azure
2024-07-22T16:31:15.1870140Z ##[debug]BROWSERSTACK_ACCESS_KEY=***
2024-07-22T16:31:15.1870603Z ##[debug]BROWSERSTACK_CONNECTED_SERVICE_NAME=7be27815-2703-424c-8f71-c8a41b6beca1
2024-07-22T16:31:15.1871756Z ##[debug]BROWSERSTACK_BUILD_NAME=azure-IRef.AutomatedTests - POC - BS-829099
2024-07-22T16:31:15.1885447Z Publishing reports for Build azure-IRef.AutomatedTests - POC - BS-829099 on automate...
2024-07-22T16:31:15.1976676Z (node:35996) Warning: Use Cipheriv for counter mode of aes-256-ctr
2024-07-22T16:31:15.1977013Z (node:35996) Warning: Use Cipheriv for counter mode of aes-256-ctr
2024-07-22T16:31:15.1977245Z (node:35996) Warning: Use Cipheriv for counter mode of aes-256-ctr
2024-07-22T16:31:15.1977454Z (node:35996) Warning: Use Cipheriv for counter mode of aes-256-ctr
2024-07-22T16:31:15.4463260Z ##[debug]task result: Failed
2024-07-22T16:31:15.4464441Z ##[error] Build not found by name: "azure-IRef.AutomatedTests - POC - BS-829099"
2024-07-22T16:31:15.4465165Z ##[debug]Processed: ##vso[task.issue type=error;] Build not found by name: "azure-IRef.AutomatedTests - POC - BS-829099"
2024-07-22T16:31:15.4466341Z ##[debug]Processed: ##vso[task.complete result=Failed;] Build not found by name: "azure-IRef.AutomatedTests - POC - BS-829099"
2024-07-22T16:31:15.4610708Z ##[section]Finishing: BrowserStack Results.
要在
BROWSERSTACK_BUILD_NAME
文件中使用环境变量 playwright.config.ts
,您可以按如下操作。
const buildName = process.env.BROWSERSTACK_BUILD_NAME;
. . .
// Set the browser capabilities.
const caps = {
"os": "xxxx",
"browser": "xxxx",
"build": buildName,
. . .
}
或
// Set the browser capabilities.
const caps = {
"os": "xxxx",
"browser": "xxxx",
"build": process.env.BROWSERSTACK_BUILD_NAME,
. . .
}
相关 BrowserStack 文档: