你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

@azure/playwright package

类型别名

AuthenticationType

Azure Playwright 支持的身份验证类型。

BrowserConnectOptions

服务的浏览器连接选项。 这包括端点选项和连接选项。

示例

import playwright, { test, expect, BrowserType } from "@playwright/test";
import { getConnectOptions, BrowserConnectOptions } from "@azure/playwright";

test("has title", async ({ browserName }) => {
 const { wsEndpoint, options } : BrowserConnectOptions = await getConnectOptions();
 const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
 const context = await browser.newContext();
 const page = await context.newPage();

 await page.goto("https://playwright.dev/");
 await expect(page).toHaveTitle(/Playwright/);

 await page.close();
 await context.close();
 await browser.close();
});
EndpointOptions

服务的终结点选项。

OsType

Azure Playwright 支持的 OS 类型。

PlaywrightServiceAdditionalOptions

服务的其他选项。

函数

createAzurePlaywrightConfig(PlaywrightTestConfig<{}, {}>, PlaywrightServiceAdditionalOptions)

生成与 Azure Playwright 集成的剧作家配置。

示例

import { defineConfig } from "playwright/test";
import { createAzurePlaywrightConfig } from "@azure/playwright";
import playwrightConfig from "./playwright.config";

export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig));

示例

import { defineConfig } from "playwright/test";
import { createAzurePlaywrightConfig, ServiceOS, ServiceAuth } from "@azure/playwright";
import playwrightConfig from "./playwright.config";
import { DefaultAzureCredential } from '@azure/identity';

export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig, {
 credential: new DefaultAzureCredential(),
 serviceAuthType: ServiceAuth.ENTRA_ID,
 os: ServiceOS.WINDOWS
}));
getConnectOptions(PlaywrightServiceAdditionalOptions)

获取连接到 Azure Playwright 的云托管浏览器所需的连接选项。

示例

import playwright, { test, expect, BrowserType } from "@playwright/test";
import { getConnectOptions } from "@azure/playwright";

test('has title', async ({ browserName }) => {
 const { wsEndpoint, options } = await getConnectOptions();
 const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
 const context = await browser.newContext();
 const page = await context.newPage();

 await page.goto('https://playwright.dev/');
 await expect(page).toHaveTitle(/Playwright/);

 await page.close();
 await context.close();
 await browser.close();
});

变量

ServiceAuth

Azure Playwright 支持的认证类型

ServiceEnvironmentVariable

Azure Playwright 使用的环境变量

ServiceOS

Azure Playwright 云托管浏览器支持的作系统类型

函数详细信息

createAzurePlaywrightConfig(PlaywrightTestConfig<{}, {}>, PlaywrightServiceAdditionalOptions)

生成与 Azure Playwright 集成的剧作家配置。

示例

import { defineConfig } from "playwright/test";
import { createAzurePlaywrightConfig } from "@azure/playwright";
import playwrightConfig from "./playwright.config";

export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig));

示例

import { defineConfig } from "playwright/test";
import { createAzurePlaywrightConfig, ServiceOS, ServiceAuth } from "@azure/playwright";
import playwrightConfig from "./playwright.config";
import { DefaultAzureCredential } from '@azure/identity';

export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig, {
 credential: new DefaultAzureCredential(),
 serviceAuthType: ServiceAuth.ENTRA_ID,
 os: ServiceOS.WINDOWS
}));
function createAzurePlaywrightConfig(baseConfig: PlaywrightTestConfig<{}, {}>, options?: PlaywrightServiceAdditionalOptions): PlaywrightTestConfig<{}, {}>

参数

baseConfig

PlaywrightTestConfig<{}, {}>

基本剧作家配置

options
PlaywrightServiceAdditionalOptions

服务的其他选项

返回

PlaywrightTestConfig<{}, {}>

剧作家配置

getConnectOptions(PlaywrightServiceAdditionalOptions)

获取连接到 Azure Playwright 的云托管浏览器所需的连接选项。

示例

import playwright, { test, expect, BrowserType } from "@playwright/test";
import { getConnectOptions } from "@azure/playwright";

test('has title', async ({ browserName }) => {
 const { wsEndpoint, options } = await getConnectOptions();
 const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
 const context = await browser.newContext();
 const page = await context.newPage();

 await page.goto('https://playwright.dev/');
 await expect(page).toHaveTitle(/Playwright/);

 await page.close();
 await context.close();
 await browser.close();
});
function getConnectOptions(options?: PlaywrightServiceAdditionalOptions): Promise<BrowserConnectOptions>

参数

options
PlaywrightServiceAdditionalOptions

服务的其他选项

返回

浏览器连接选项

变量详细信息

ServiceAuth

Azure Playwright 支持的认证类型

ServiceAuth: { ACCESS_TOKEN: "ACCESS_TOKEN", ENTRA_ID: "ENTRA_ID" }

类型

{ ACCESS_TOKEN: "ACCESS_TOKEN", ENTRA_ID: "ENTRA_ID" }

ServiceEnvironmentVariable

Azure Playwright 使用的环境变量

ServiceEnvironmentVariable: { PLAYWRIGHT_SERVICE_ACCESS_TOKEN: string, PLAYWRIGHT_SERVICE_URL: string }

类型

{ PLAYWRIGHT_SERVICE_ACCESS_TOKEN: string, PLAYWRIGHT_SERVICE_URL: string }

ServiceOS

Azure Playwright 云托管浏览器支持的作系统类型

ServiceOS: { LINUX: "linux", WINDOWS: "windows" }

类型

{ LINUX: "linux", WINDOWS: "windows" }