要在 Azure 上托管 Playwright 测试,可以按照以下步骤进行操作:
创建一个 Azure Functions 应用程序:
在 Azure Functions 应用程序中创建一个函数:
安装 Playwright 包:
npm install playwright
在函数中编写 Playwright 测试代码:
const { chromium } = require('playwright');
module.exports = async function (context, req) {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
const title = await page.title();
await browser.close();
context.res = {
body: `Title: ${title}`
};
};
部署函数应用程序:
func azure functionapp publish <函数应用名称>
测试函数应用程序:
这样,你就可以在 Azure 上托管 Playwright 测试了。记得根据实际需求修改函数代码,并根据需要设置其他配置,如应用程序设置和连接字符串等。