How to set user environment variables for test?

Postman is a common tool we use when developing APIs. Not only are developers testing it for themselves, but also collections can store several test scenarios and share them with others in the team, which greatly improves the efficiency of API integration.

Postman 是我們在開發 api 時的常用工具,不僅是開發者自行測試好用,還有 collection 可以儲存數個測試情境,分享給團隊其他人使用,大幅提高 api 整合的效率。

SCENARIO 情境說明

  1. Each environment is different, so the URL is different but the method name and parameters are the same 測試每個環境都是不同, 所以URL是不同的但是方法名稱與參數是相同的

Manage Environments

  1. Click “cog” icon 點選“齒輪”圖示
Image for post
Image for post

2. There are three ways to create variable- Global, Import and Add. I choose Add. 有三種創建變量的方法-Global, ImportAdd. 我選擇Add

Image for post
Image for post

3. define Environment name and variable for localhost. 為本地主機定義環境名稱和變量.

Image for post
Image for post

4. Add one more environment for remote server. 為遠端主機定義環境名稱和變量

4.1 click “Duplicate environment”. 點選 “Duplicate environment”

Image for post
Image for post

4.2 double click “localhost copy” 雙點擊“localhost copy”

Image for post
Image for post

4.3 rename environment and change the value of variable for remote server. 重命名環境並更改遠程服務器的變量值

Image for post
Image for post

5. close “MANAGE ENVIRONMENT” 關掉“MANAGE ENVIRONMENT”

Image for post
Image for post

How to use in different environment

  1. select environment — localhost or remote server. 選擇環境-本地主機或遠程服務器

e.g. {{url}}/{{id}}

Image for post
Image for post

remote server

Image for post
Image for post

Written by

撰寫任何事情,O型水瓶混魔羯,咖啡愛好者,Full stack/blockchain developer,Founder of Blockchain&Dapps meetup and DeFi-Decentralized-Finance-SG meetup,Udemy teacher。

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store