gpt4 book ai didi

javascript - 在 azure 函数中运行剧作家测试

转载 作者:行者123 更新时间:2023-12-03 03:51:52 24 4
gpt4 key购买 nike

我必须编写一个 Azure javascript 函数(由计时器触发器调用),然后运行在另一个文件中的 playwright 中定义的测试。然后将结果写入应用洞察日志。

我已经编写了azure函数计时器触发器,但我不知道如何调用剧作家测试。请帮助我

/* azure function */

module.exports = async function (context, myTimer) {
var timeStamp = new Date().toISOString();

/* run the tests below */

if (myTimer.isPastDue)
{
context.log('JavaScript is running late!');
}
context.log('JavaScript timer trigger function ran!', timeStamp);
};

/* playwright tests */

const { it, beforeEach, afterEach, describe, expect } = require('@playwright/test');

describe('site', function() {
beforeEach(async function login({ page }) {
await page.setViewportSize({ width: 1920, height: 1080 });

await page.goto('https://example.com/');

const {
TEST_EMAIL = 'email-value',
TEST_PASSWORD = 'password-value',
} = process.env;

const usernameField = await page.waitForSelector('#username', { timeout: 2000 });
const passwordField = await page.waitForSelector('#password', { timeout: 2000 });
const button = await page.waitForSelector('button[name="action"]', { timeout: 2000 });

await usernameField.isVisible();
await passwordField.isVisible();
await button.isVisible();

await usernameField.fill(TEST_EMAIL);
await passwordField.fill(TEST_PASSWORD);
await button.click({ timeout: 2000 });
await page.waitForNavigation();
await page.waitForSelector('app');
});

afterEach(async function({ page }) {
await page.waitForSelector('#profile-link');
await page.isVisible('#profile-link');
await page.click('#profile-link');
await page.click('#logout');
});

it('logs in to the dashboard', async function({ page }) {
const dashboard = await page.waitForSelector('app > main > dashboard');
await dashboard.isVisible();
expect(await page.title()).toEqual('Dashboard | Site');
});

it('navigates to sites page', async function({ page }) {
const dashboard = await page.waitForSelector('app > main > dashboard');
await dashboard.isVisible();
const sitesButton = await page.waitForSelector('app mwc-button[label*="Add site" i]');
await sitesButton.click();
await page.isVisible('sites');
expect(await page.title()).toEqual('Add Sites | Site');
});

it('navigates to calc page', async function({ page }) {
const dashboard = await page.waitForSelector('app > main > dashboard');
await dashboard.isVisible();
const calcLink = await page.waitForSelector('[href="/calc"]');
await calcLink.click();
await page.isVisible('calc');
expect(await page.title()).toEqual('calc | Site');
});
});

最佳答案

您应该定义一个导出函数FunctionName(){...}并将代码放入导出函数FunctionName(){...}主体。

然后您可以在计时器触发函数中调用它。

关于javascript - 在 azure 函数中运行剧作家测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66353829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com