【问题标题】:How to store and reuse schema within different collections in Postman?如何在 Postman 的不同集合中存储和重用模式?
【发布时间】:2019-07-29 16:32:39
【问题描述】:

我正在进行 Postman 测试,我想根据响应验证架构。该模式适用于工作空间中的许多不同集合,因此我想将其存储在单独的文件中并重复使用。

有没有办法在集合中引用该文件,并在导出集合时提取该文件。

  • 例如:example.postman_collection.json 也会包含引用的文件。
  • 从我的research 到目前为止,我发现可以在运行集合时导入文件,这不是我想要的。我不想要任何外部依赖项。

如果不是,在 Postman 中处理此问题并在不同集合中重用架构的另一种方法是什么?

谢谢!

【问题讨论】:

    标签: json testing automated-tests schema postman


    【解决方案1】:

    您是否有任何理由要将其存储为文件? 您可以将模式存储为全局或环境变量,并且可以轻松访问它们。

    //Var for schema
    const customerSchema = {
      "required": ["id"],
      "properties": {
        "id": {
          "type": "integer",
          "minimum": 100,
          "maximum": 1000
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 25
        }
      }
    };
    
    //Store it as environmental variable (or global).
    pm.environment.set("customerSchema", customerSchema);
    
    //Get it from environmental variable (or global).
    var expectedSchema = pm.environment.get("customerSchema");
    
    //validate
    pm.test('Customer schema is matching expected result', function() {
         pm.expect(tv4.validate(responseBody, expectedSchema)).to.be.true;
    });
    

    【讨论】:

    • 目前我以与您描述的相同的方式将模式存储为变量。但我希望它的范围也扩展到其他系列。它是由多个集合共享的架构。
    • 您可以对多个集合使用相同的环境。我知道这不是你要找的答案。只是说。
    • 完全同意!这是我计划使用的最后手段,因为它会在集合之间引入排序依赖性。包含模式的那个总是需要首先运行。但是,感谢您的调查!
    猜你喜欢
    • 2015-01-29
    • 2016-05-01
    • 2014-06-09
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    相关资源
    最近更新 更多