首页 > 解决方案 > 使用对象数组中的数据在循环中量角器 it() 规范

问题描述

我正在尝试使用规范(它)设置一个 e2e 测试套件来测试在应用程序中打开文件。我想稍后在每个测试规范上收集一些性能数据(基于文件大小、时间等)。

由于除了文件和相关属性之外,测试规范几乎相同,因此我使用了一个 json 对象(数据数组)来获取文件名。我尝试使用此处列出的解决方案。

我尝试使用此处提到的 jasmine-data-provider 遍历测试规范。但是规格被跳过了。

describe("App File Open", () => {
let fileNames: string[] = [];
const filePath: string = "common filepath for files"
  beforeAll(() => {        
    fileNames = jsonFile["files"];     

    // ...
  });

  beforeEach(function (): void {        
    // ...
  });

  using(fileNames, (data: string) => {
    it("open file " + data, () => {
      // ...
      inputElement.sendKeys(filePath + data);
      // ...
    });
  });

  afterEach(function (): void {
    // ...
  });

  afterAll(function (): void {
    // ...
  });
});

测试跳过块而不拿起测试规范(它)。

“茉莉花开始

在 0 秒内执行 0 个规范中的 0 个成功。”

是否可以遍历规格?如果是这样,我在这里错过了什么?(抱歉,如果这是重复的)

标签: typescriptprotractorkarma-jasmine

解决方案


我不知道 jasmine-data-provider 但这个块

using(fileNames, (data: string) => {
    it("open file " + data, () => {
      // ...
      inputElement.sendKeys(filePath + data);
      // ...
    });
  });

在 之前进行评估fileNames = jsonFile["files"];,因此fileNames是一个空字符串。


推荐阅读