代码之家  ›  专栏  ›  技术社区  ›  Matthew

如何使用Postman Runner多次测试同一端点

  •  1
  • Matthew  · 技术社区  · 8 年前

    我正试图写一个自动测试运行在邮递员。我想在一次运行中多次测试同一个端点,同时更改参数的值。

    https://example.com/endpoint/{{item1}}
    https://example.com/endpoint/{{item2}}
    https://example.com/endpoint/{{item3}}
    

    我可以在pass上设置一个全局变量,用它运行一次

    let parameter = 'some value';
    pm.globals.set("parameter", parameter);
    

    如何在一次运行中多次测试端点?

    2 回复  |  直到 8 年前
        1
  •  1
  •   Carasel    6 年前

    你有没有考虑过使用 data files

    [
        {
            "item":"1"
        },
        {
            "item":"2"
        },
        {
            "item":"3"
        },
        {
            "item":"4"
        }
    ]
    

    文件只是一个对象数组 keys 将是您在请求中引用的属性,这些属性将解析为键的值。在JSON文件中,每个对象都是一个单独的迭代 1

    { "item":"1" }

    在您的请求url中,在集合中 https://example.com/endpoint/{{item}} -如果你设置 Iterations 数到 4 ,它将运行相同的请求,但更改值以使用 item 每次都是可变的。

    enter image description here

        2
  •  0
  •   A.Joly    8 年前

    你应该使用邮递员的收集设备(看一看) here ) 您可以构建一个csv文件,例如包含item1、item2等。 然后将其用作集合输入。启动集合将为每个参数值调用一次测试。。。

        3
  •  0
  •   codeblooded    6 年前

    说,开始吧 https://google.com/q={{search}} 您有多个搜索查询(dog、chess、marvel、stackoverflow)

    • 将GET请求添加到 https://google.com/q={{搜索} 有必要的头球和击球 Save
    • 创建一个带有标题的CSV文件 search
    • 点击新创建集合的run按钮
    • Iterations 字段设置为您的查询数。在这个例子中是4
    • 寻找领域 Data ,选择创建的CSV文件
    • 通过点击 Preview
    • 击中 Run test
    • 您可以在 Postman Console

    postman runner

    Head to View in the application menu, and click on "Show Postman Console" or use the keyboard shortcut (CMD/CTRL + ALT + C) to open.