monocart-reporter @owner 标签不会附加到我正在运行的测试

问题描述 投票:0回答:1

我正在使用 playwright 来运行我的 e2e 测试,并且我已经安装了 monocart-reporter https://www.npmjs.com/package/monocart-reporter#examples 尝试为每个添加“所有者”标签测试,以便当特定测试失败时,特定所有者会收到电子邮件。

但是,对于我的一生,我无法弄清楚如何添加 @owner 标签,根据 monocart-reporter 文档,这应该非常简单

这是我的剧作家配置:

export function createConfig(options: ICreatePlaywrightConfig): PlaywrightTestConfig {
 ...(other info here)....
      reporter: [
          ['monocart-reporter', {
              name: "My Test Report",
              outputFile: './test-results/report.html',
              embedAnnotationsAsProperties: true,

              // custom columns
              columns: (defaultColumns) => {

                  // insert custom column(s) before a default column
                  const index = defaultColumns.findIndex((column) => column.id === 'duration');
                  defaultColumns.splice(index, 0, {
                      // define the column in reporter
                      id: 'owner',
                      name: 'Owner',
                      align: 'center',
                      searchable: true,
                      styleMap: {
                          'font-weight': 'normal'
                      }
                  }, {
                      // another column for JIRA link
                      id: 'jira',
                      name: 'JIRA Key',
                      width: 100,
                      searchable: true,
                      styleMap: 'font-weight:normal;',
                      formatter: (v, rowItem, columnItem) => {
                          const key = rowItem[columnItem.id];
                          return `<a href="https://your-jira-url/${key}" target="_blank">${v}</a>`;
                      }
                  });

              }
          }]
      ]

  };
  return config;
}

这是我的测试:(test-name.spec.ts)

import { test, expect } from "@playwright/test";
import { goToPage, waitForSuccessApi } from "../../common/testUtils";
import { customReporter, addWorkItem } from "../../common/custom-reporter";  // hackathon
import type { TestResult } from '@playwright/test/reporter';

/*
 * @owner Kevin
 * @jira MCR-16888
 */
test.describe("HomePage", () => {
    // @owner Steve
    test("should load the homepage with a user id", async ({ page }) => {
        // @owner Steve
        await goToPage(page, "/mainpage");
        await page.locator("'Search using a User Id'").waitFor();
        await expect(page.locator('h2:has-text("Welcome to HomePage")')).toBeVisible();
    });

});

^所有所有者标签都是我试图将所有者标签附加到此测试中但无济于事

monocart 正在工作(运行测试后我能够看到报告和故障,但看不到所有者)

jira playwright npm-scripts playwright-test test-reporting
1个回答
0
投票

将此添加到“列”之后

visitor: (data: any, metadata: any, collect: any) => {

      // auto collect data from comments
      const parserOptions = {
        // Indicate the mode the code should be parsed in.
        // Can be one of "script", "module", or "unambiguous". Defaults to "script".
        sourceType: 'module',
        // enable typescript syntax. more https://babeljs.io/docs/babel-parser
        plugins: ['typescript']
      };
      const comments = collect.comments(parserOptions);
      if (comments) {
        Object.assign(data, comments);
      }
      if (metadata.annotations) {
        const jiraItem = metadata.annotations.find((item: { type: string; }) => item.type === 'jira');
        if (jiraItem && jiraItem.description) {
          data.jira = jiraItem.description;
        }
        const ownerItem = metadata.annotations.find((item: { type: string; }) => item.type === 'owner');
        if (ownerItem && ownerItem.description) {
          data.owner = ownerItem.description;
        }
      }
      delete data.annotations;
    },

<!-- begin snippet: js hide: false console: true babel: false -->

© www.soinside.com 2019 - 2024. All rights reserved.