【问题标题】:run playwright tests in azure function在 azure 函数中运行剧作家测试
【发布时间】:2021-05-26 22:42:16
【问题描述】:

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

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

/* 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');
  });
});

【问题讨论】:

  • 刚刚遇到这个并且有几乎相同的情况。您是否曾经构建过完整的解决方案?

标签: javascript azure playwright


【解决方案1】:

您应该定义一个export function FunctionName(){...} 并将代码放入export function FunctionName(){...} 正文中。

然后你可以在你的定时器触发函数中调用它。

【讨论】:

    猜你喜欢
    • 2021-01-28
    • 2022-06-24
    • 2021-12-16
    • 2021-08-14
    • 1970-01-01
    • 2022-09-24
    • 2022-10-06
    • 2022-12-10
    • 1970-01-01
    相关资源
    最近更新 更多