Testing OpenWeather APIs in Postman – Step-by-Step

Опубликовано: 22 Апрель 2026
на канале: QA_AI_WIZARDS
24
0

✅ 1. Prerequisites
✅ Install Postman

✅ Sign up on https://openweathermap.org

✅ Generate your API key from:
👉 https://home.openweathermap.org/api_keys

🛠️ 2. Create a Postman Environment (Recommended)
Go to Environments -- Create new

Add variables:

base_url → https://api.openweathermap.org

api_key → your actual API key

city_name → e.g. London

lat → e.g. 51.51

lon → e.g. -0.13

This helps reuse variables across requests.

🌐 3. Basic Test: Current Weather by City Name
Method: GET

URL:
{{base_url}}/data/2.5/weather?q={{city_name}}&appid={{api_key}}&units=metric

🔍 Postman Tests:
javascript

pm.test("Status is 200 OK", function () {
pm.response.to.have.status(200);
});

pm.test("City name is correct", function () {
const data = pm.response.json();
pm.expect(data.name).to.eql(pm.variables.get("city_name"));
});

pm.test("Temperature is present", function () {
const data = pm.response.json();
pm.expect(data.main.temp).to.be.a('number');
});
🌐 4. Test: 5 Day / 3 Hour Forecast
Method: GET

URL:
{{base_url}}/data/2.5/forecast?q={{city_name}}&appid={{api_key}}&units=metric

✅ What to check:
Status code is 200

Forecast list contains at least 10 entries

Each entry has main.temp, weather[0].description

🌐 5. Test: One Call API (Current + Forecast + Alerts)
Method: GET

URL:
{{base_url}}/data/3.0/onecall?lat={{lat}}&lon={{lon}}&appid={{api_key}}&units=metric

🔍 Tests:
javascript

pm.test("Contains current weather", function () {
let res = pm.response.json();
pm.expect(res.current).to.have.property("temp");
});

pm.test("Contains daily forecast", function () {
let res = pm.response.json();
pm.expect(res.daily.length).to.be.above(1);
});
🌐 6. Test: Air Pollution API
Method: GET

URL:
{{base_url}}/data/2.5/air_pollution?lat={{lat}}&lon={{lon}}&appid={{api_key}}

✅ What to test:
Status is 200

Response includes PM2.5, PM10, and AQI values

❌ 7. Negative Test: Invalid City
Method: GET

URL:
{{base_url}}/data/2.5/weather?q=InvalidCityName&appid={{api_key}}

🔍 Test:
javascript

pm.test("City not found returns 404", () = {
pm.response.to.have.status(404);
let res = pm.response.json();
pm.expect(res.message).to.include("city not found");
});
🧪 8. Suggested Postman Collection Structure
📁 OpenWeather API Testing

📄 Get Current Weather (Positive)

📄 Get Forecast 5 Days

📄 Get One Call API

📄 Get Air Pollution

📄 Negative Tests

Add tests to each request

Use folders to separate types: Current, Forecast, Pollution, Errors

🧰 9. Exporting Collection & Automating with Newman
Export collection: File → Export → Collection v2.1

Run it via CLI with Newman:

newman run "OpenWeather API Testing.postman_collection.json" --env-var "api_key=your_actual_key"
🧠 10. QA Best Practices for API Testing
Validate status codes (200, 400, 404)

Check presence and correctness of key fields (temp, humidity, weather)

Test edge cases (e.g., cities with special characters, empty inputs)

Monitor API limits and error responses

Use Postman Monitors to run tests daily/hourly

📚 Official OpenWeather API Docs
👉 https://openweathermap.org/api

🏷️Hashtags
#OpenWeatherAPI, #Postman, #APITesting, #QATesting, #WeatherAPI, #RestAPI, #TestAutomation, #PostmanScripts, #Newman, #SDET, #AutomationEngineer, #WeatherForecastAPI, #APIValidation, #WeatherAutomation, #QACommunity