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 情境說明
- Each environment is different, so the URL is different but the method name and parameters are the same 測試每個環境都是不同, 所以URL是不同的但是方法名稱與參數是相同的
- The parameters may be different in different environments測試的參數在不同環境也可能不同
Manage Environments
- Click “cog” icon 點選“齒輪”圖示

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

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

4. Add one more environment for remote server. 為遠端主機定義環境名稱和變量
4.1 click “Duplicate environment”. 點選 “Duplicate environment”

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

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

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

How to use in different environment
- select environment — localhost or remote server. 選擇環境-本地主機或遠程服務器
e.g. {{url}}/{{id}}

remote server
