你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
重要
Microsoft剧作家测试将于 2026 年 3 月 8 日停用。 若要继续运行 Playwright 测试,请在 Azure 应用测试中创建新的 Playwright 工作区,现已正式发布。 了解如何迁移。
本文介绍如何使用系统生成的 playwright.service.config.ts 文件中可用的选项。
如果你的代码中没有此文件,请按照“快速入门: 使用 Microsoft Playwright Testing 预览版大规模运行端到端测试”
本文介绍如何使用 .runsettings 文件中可用的选项。
如果你的代码中没有此文件,请按照“快速入门: 使用 Microsoft Playwright Testing 预览版大规模运行端到端测试”
重要
Microsoft Playwright Testing 目前以预览版提供。 有关 beta 版、预览版或尚未正式发布的 Azure 功能所适用的法律条款,请参阅 Microsoft Azure 预览版的补充使用条款。
先决条件
- 按照快速入门指南进行操作,并设置一个与 Microsoft Playwright Testing 服务配合运行的项目。 请参阅快速入门:使用 Microsoft Playwright Testing 预览版大规模运行端到端测试
下面是包含所有可用选项的 playwright.service.config.ts 文件版本:
import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
import { defineConfig } from "@playwright/test";
import { AzureCliCredential } from "@azure/identity";
import config from "./playwright.config";
export default defineConfig(
  config,
  getServiceConfig(config, {
    serviceAuthType:'ACCESS_TOKEN' // Use this option when you want to authenticate using access tokens. This mode of auth should be enabled for the workspace.
    os: ServiceOS.WINDOWS, // Select the operating system where you want to run tests.
    runId: new Date().toISOString(), // Set a unique ID for every test run to distinguish them in the service portal.
    credential: new AzureCliCredential(), // Select the authentication method you want to use with Entra.
    useCloudHostedBrowsers: true, // Select if you want to use cloud-hosted browsers to run your Playwright tests.
    exposeNetwork: '<loopback>', // Use this option to connect to local resources from your Playwright test code without having to configure additional firewall settings.
    timeout: 30000 // Set the timeout for your tests.
  }),
  {
    reporter: [
      ["list"],
      [
        "@azure/microsoft-playwright-testing/reporter",
        {
          enableGitHubSummary: true, // Enable/disable GitHub summary in GitHub Actions workflow.
        },
      ],
    ],
  },
);
              playwright.service.config.ts 文件中的设置
- serviceAuthType:- 说明:此设置允许你选择要用于测试运行的身份验证方法。
- 可用选项:- 
              ACCESS_TOKEN表示使用访问令牌。 如果你要使用此选项,则需要启用使用访问令牌的身份验证,具体请参阅管理身份验证。
- 
              ENTRA_ID表示使用 Microsoft Entra ID 进行身份验证。 这是默认模式。
 
- 
              
- 默认值:ENTRA_ID
- 
              示例:serviceAuthType:'ENTRA_ID'
 
- os:- 说明:此设置允许你选择运行操作系统,其中托管了运行 Playwright 测试的浏览器。
- 可用选项:- 
              ServiceOS.WINDOWS(适用于 Windows 操作系统)。
- 
              ServiceOS.LINUX(适用于 Linux 操作系统)。
 
- 
              
- 默认值:ServiceOS.LINUX
- 
              示例:os: ServiceOS.WINDOWS
 
- runId:- 说明:此设置允许你为每个测试运行设置唯一的 ID,以便在服务门户中区分测试运行。 对多个测试运行使用相同的 runId 会导致错误。 对于分片,请在所有分片中保持一致。
- 
              示例:runId: new Date().toISOString()
 
- credential:- 说明:此设置允许你选择要与 Microsoft Entra ID 配合使用的身份验证方法。
- 
              示例:credential: new AzureCliCredential()
 
- useCloudHostedBrowsers- 说明:此设置允许你选择是要使用云托管的浏览器还是客户端计算机上的浏览器来运行 Playwright 测试。 如果禁用此选项,则测试将在客户端计算机的浏览器上而不是云托管的浏览器上运行,并且不会产生任何费用。
- 默认值:true
- 
              示例:useCloudHostedBrowsers: true
 
- exposeNetwork- 说明:此设置允许你从 Playwright 测试代码连接到本地资源,而无需配置其他防火墙设置。 有关详细信息,请参阅如何测试本地应用程序
- 
              示例:exposeNetwork: '<loopback>'
 
- timeout- 说明:此设置允许你设置将测试连接到云托管的浏览器的超时期限。
- 
              示例:timeout: 30000,
 
- reporter- 说明: 文件扩展设置的 Playwright 配置文件playwright.service.config.ts。 此选项将替代现有的报告程序并设置 Microsoft Playwright Testing 报告程序。 你可以添加或修改此列表,以包含你要使用的报告程序。 如果添加@azure/microsoft-playwright-testing/reporter,则你需要为 Microsoft Playwright Testing 报告付费。
- 默认值:["@azure/microsoft-playwright-testing/reporter"]
- 
              示例:reporter: [ ["list"], ["@azure/microsoft-playwright-testing/reporter"],
 
- 说明: 文件扩展设置的 Playwright 配置文件
- enableGitHubSummary:- 说明:此设置允许你配置 Microsoft Playwright Testing 服务报告程序。 你可以选择在 GitHub Actions 中运行时是否将测试运行摘要包含在 GitHub 摘要中。
- 默认值:true
- 示例:
 - reporter: [ ["list"], [ "@azure/microsoft-playwright-testing/reporter", { enableGitHubSummary: true, }, ], ]
下面是包含所有可用选项的 .runsettings 文件版本:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
    <TestRunParameters>
        <!-- Use this option when you want to authenticate using access tokens. This mode of auth should be enabled for the workspace. -->
         <Parameter name="ServiceAuthType" value="EntraId" />
        <!-- Select the operating system where you want to run tests. -->
        <Parameter name="Os" value="linux" />
        <!-- Set a unique ID for every test run to distinguish them in the service portal.-->
        <Parameter name="RunId" value="sample-run-id1" />
        <!--Select if you want to use cloud-hosted browsers to run your Playwright tests.-->
        <Parameter name="UseCloudHostedBrowsers" value="true" />
        <!--Use this option to connect to local resources from your Playwright test code without having to configure additional firewall-->
        <Parameter name="ExposeNetwork" value="loopback" />
        <!--Select the authentication method you want to use with Entra-->
        <Parameter name="AzureTokenCredentialType" value="DefaultAzureCredential" />
        <!--Enable/disable GitHub summary in GitHub Actions workflow.-->
        <Parameter name="EnableGitHubSummary" value="false" />
    </TestRunParameters>
  <!-- NUnit adapter -->  
  <NUnit>
    <!-- Adjust parallel workers, parallel worker would also be bound by number of unit test files -->
    <NumberOfTestWorkers>10</NumberOfTestWorkers>
  </NUnit>
  <!-- General run configuration -->
  <RunConfiguration>
    <EnvironmentVariables>
      <!-- For debugging selectors, it's recommend to set the following environment variable -->
      <DEBUG>pw:api</DEBUG>
    </EnvironmentVariables>
  </RunConfiguration>
  <!-- Playwright -->  
  <Playwright>
    <BrowserName>chromium</BrowserName>
    <!--Set the timeout for your tests.-->
    <ExpectTimeout>5000</ExpectTimeout>
    <LaunchOptions>
      <Headless>false</Headless>
      <!--Channel>msedge</Channel-->
    </LaunchOptions>
  </Playwright>
    <LoggerRunSettings>
        <Loggers>
            <!--microsoft playwright testing service logger for reporting -->
            <Logger friendlyName="microsoft-playwright-testing" enabled="true" />
            <!--could enable any logger additionally -->
            <Logger friendlyName="trx" enabled="false" />
        </Loggers>
    </LoggerRunSettings>
</RunSettings>
              .runsettings 文件中的配置选项
- serviceAuthType:- 说明:此设置允许你选择要用于测试运行的身份验证方法。
- 可用选项:- 
              AccessToken表示使用访问令牌。 如果你要使用此选项,则需要启用使用访问令牌的身份验证,具体请参阅管理身份验证。
- 
              EntraId表示使用 Microsoft Entra ID 进行身份验证。 这是默认模式。
 
- 
              
- 默认值:EntraId
- 
              示例:<Parameter name="ServiceAuthType" value="EntraId" />
 
- os:- 说明:此设置允许你选择运行操作系统,其中托管了运行 Playwright 测试的浏览器。
- 可用选项:- 适用于 Windows 操作系统的“Windows”。
- 适用于 Linux OS 的“linux”。
 
- 默认值:“linux”
- 
              示例:<Parameter name="Os" value="linux" />
 
- RunId:- 说明:此设置允许你为每个测试运行设置唯一的 ID,以便在服务门户中区分测试运行。 对多个测试运行使用相同的 runId 会导致错误。 如果未设置,服务包将在每次触发测试运行时生成唯一 ID。 对于分片,请在所有分片中保持一致。
- 
              示例:<Parameter name="RunId" value="sample-run-id1" />
 
- AzureTokenCredentialType:- 说明:此设置允许你选择要与 Microsoft Entra ID 配合使用的身份验证方法。
- 
              示例:<Parameter name="AzureTokenCredentialType" value="DefaultAzureCredential" />
 
- UseCloudHostedBrowsers- 说明:此设置允许你选择是要使用云托管的浏览器还是客户端计算机上的浏览器来运行 Playwright 测试。 如果禁用此选项,则测试将在客户端计算机的浏览器上而不是云托管的浏览器上运行,并且不会产生任何费用。
- 默认值:true
- 
              示例:<Parameter name="UseCloudHostedBrowsers" value="true" />
 
- ExposeNetwork- 说明:此设置允许你从 Playwright 测试代码连接到本地资源,而无需配置其他防火墙设置。 有关详细信息,请参阅如何测试本地应用程序
- 
              示例:<Parameter name="ExposeNetwork" value="loopback" />
 
- reporter- 
              
              说明: 可以使用 microsoft-playwright-testing记录器将测试结果和项目发布到服务。 可以通过从.runsettings中删除报告或将其设置为 false 来禁用报告。
- 默认值:true
- 
              示例:<Logger friendlyName="microsoft-playwright-testing" enabled="true" />
 
- 
              
              说明: 可以使用 
- EnableGitHubSummary:- 说明:此设置允许你配置 Microsoft Playwright Testing 服务报告程序。 你可以选择在 GitHub Actions 中运行时是否将测试运行摘要包含在 GitHub 摘要中。
- 默认值:true
- 示例:
 - <Parameter name="EnableGitHubSummary" value="false" />