0% found this document useful (0 votes)
42 views

API Testing

Uploaded by

excelworduse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

API Testing

Uploaded by

excelworduse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

API testing ke liye aapko kuch key concepts aur skills seekhne ki zaroorat hoti hai:

1. API Basics: API kya hota hai, REST, SOAP, aur GraphQL ke concepts samjhe.
2. HTTP Methods: GET, POST, PUT, DELETE jaise HTTP methods ka istemal kaise hota
hai.
3. Request aur Response Structure: JSON, XML jaise data formats ko samjhein aur kaise
API requests aur responses ka structure hota hai.
4. Tools: Postman, SoapUI, ya curl jaise tools ka istemal karna seekhein.
5. Authentication: API ke security mechanisms jaise OAuth, API keys, aur JWT ko
samjhein.
6. Testing Strategies: Functional testing, performance testing, aur security testing ki
strategies seekhein.
7. Automation: Automation frameworks jaise RestAssured, JMeter, ya Selenium ke sath
API testing kaise karna hota hai.
8. Error Handling: API errors aur response codes (jese 200, 404, 500) ko samjhein.

In topics par acchi command hasil karke aap API testing mein proficient ho sakte hain.

4o mini

You said:

HTTP methods kya hn with example


ChatGPT said:

ChatGPT

HTTP methods web applications aur APIs ke sath communication ke liye use hote hain. Yeh
kuch common HTTP methods hain:

1. GET: Data retrieve karne ke liye use hota hai.


o Example: GET /users (Yeh request server se users ki list maangti hai.)
2. POST: Naya data create karne ke liye use hota hai.
o Example: POST /users (Yeh request server ko ek naya user create karne ke liye
data send karti hai.)
3. PUT: Existing data ko update karne ke liye use hota hai.
o Example: PUT /users/1 (Yeh request user ID 1 ke data ko update karne ke liye
hoti hai.)
4. DELETE: Data ko delete karne ke liye use hota hai.
o Example: DELETE /users/1 (Yeh request user ID 1 ko delete karne ke liye hai.)
5. PATCH: Partial update karne ke liye use hota hai, sirf kuch fields ko modify karne ke
liye.
o Example: PATCH /users/1 (Yeh request sirf user ID 1 ke kuch fields ko update
karne ke liye hoti hai.)
6. HEAD: GET request ki tarah hota hai lekin sirf headers return karta hai, body nahi.
o Example: HEAD /users (Yeh request sirf users ki information ke headers return
karegi.)

In methods ka istemal karte waqt, yeh dhyaan rakhna zaroori hai ke kaunsa method kaise aur kis
context mein use hota hai.

4o mini

You said:

What is JSON and XML


ChatGPT said:

ChatGPT

JSON (JavaScript Object Notation) aur XML (eXtensible Markup Language) dono data
interchange formats hain.

JSON:

 Simple aur lightweight hota hai, human-readable format mein data ko key-value pairs
mein represent karta hai.
 Example:

json
Copy code
{
"name": "Alice",
"age": 30,
"isStudent": false
}

XML:

 More verbose aur flexible hota hai, tags ke sath structured data ko represent karta hai.
 Example:

xml
Copy code
<person>
<name>Alice</name>
<age>30</age>
<isStudent>false</isStudent>
</person>

JSON zyada popular hai web APIs ke liye kyunki yeh concise aur easy to parse hai, jabki XML
ka istemal complex documents ke liye hota hai.
4o mini

You said:

functional testing, performance testing, security testing ki strategies kya hn?


ChatGPT said:

ChatGPT

Functional testing, performance testing, aur security testing ke liye alag-alag strategies hoti hain.
Yahan inka summary diya gaya hai:

1. Functional Testing:

 Objective: Ensure karein ke application ke features aur functionalities expected tarike se


kaam kar rahe hain.
 Strategies:
o Test Case Design: Requirement specifications ke base par test cases design
karein.
o Positive and Negative Testing: Valid inputs ke sath saath invalid inputs bhi test
karein.
o Boundary Value Analysis: Input ranges ke edge cases ko test karein.
o Equivalence Partitioning: Inputs ko groups mein classify karke unke liye
representative cases select karein.
o Regression Testing: Application ke naye changes ke baad existing functionalities
ko dubara test karein.

2. Performance Testing:

 Objective: Application ki speed, scalability, aur stability ko test karein under varying
loads.
 Strategies:
o Load Testing: Normal aur peak load conditions par application ka performance
measure karein.
o Stress Testing: Application ko usse zyada load dene ki koshish karein jisse wo
crash ho sakta hai.
o Endurance Testing: Long duration ke liye application ki performance check
karein.
o Spike Testing: Sudden load increase par application ka reaction check karein.
o Benchmark Testing: Application ki performance ko industry standards ya
previous versions ke sath compare karein.

3. Security Testing:
 Objective: Application ko vulnerabilities se protect karne ke liye security measures ki
effectiveness test karein.
 Strategies:
o Static Application Security Testing (SAST): Source code ke analysis se
vulnerabilities identify karein.
o Dynamic Application Security Testing (DAST): Running application par attack
vectors ko test karein.
o Penetration Testing: Ethical hackers ki madad se application ke security
measures ko test karein.
o Threat Modeling: Potential threats aur vulnerabilities ko identify karein aur unke
against defenses develop karein.
o Security Scanning: Automated tools se application ko scan karein taake known
vulnerabilities identify ho sakein.

In strategies ka istemal karke aap ek comprehensive testing approach develop kar sakte hain jo
application ki quality aur security ko ensure karegi.

Successful Responses

 200 OK: The request was successful, and the server returned the requested data.
 201 Created: The request was successful, and a new resource was created (often used in
POST requests).
 204 No Content: The request was successful, but there is no content to return (commonly
used for DELETE requests).

Client Errors

 400 Bad Request: The server could not understand the request due to invalid syntax.
 401 Unauthorized: The request requires user authentication. The user must log in to
access the resource.
 403 Forbidden: The server understood the request, but it refuses to authorize it (the user
does not have permission).
 404 Not Found: The server could not find the requested resource. This often indicates
that the endpoint is incorrect or the resource does not exist.
 409 Conflict: The request could not be completed due to a conflict with the current state
of the resource.

Server Errors

 500 Internal Server Error: The server encountered an unexpected condition that
prevented it from fulfilling the request.
 502 Bad Gateway: The server received an invalid response from an upstream server it
accessed while trying to fulfill the request.
 503 Service Unavailable: The server is currently unable to handle the request due to
temporary overloading or maintenance of the server.

Additional Codes

 301 Moved Permanently: The requested resource has been permanently moved to a new
URL.
 302 Found: The requested resource is temporarily located at a different URL.

These response codes help developers diagnose issues with API calls and understand the status
of their requests. If you have specific questions about any codes or need further clarification, feel
free to ask!

Scenario: User Login API Testing

Objective: Validate ke user correct aur incorrect credentials ke sath login kar sakta
hai ya nahi.

1. Scenario 1: Successful Login with Valid Credentials


o Request:
 Method: POST
 Endpoint: /api/login
 Body:

json
Copy code
{
"username": "testuser",
"password": "password123"
}

o Expected Response:
 Status Code: 200 OK
 Response Body:

json
Copy code
{
"message": "Login successful",
"user": {
"id": "123",
"name": "testuser"
}
}

o Validation: Status code 200 ho, aur "Login successful" message aaye.

2. Scenario 2: Login with Invalid Password


o Request:
 Method: POST
 Endpoint: /api/login
 Body:

json
Copy code
{
"username": "testuser",
"password": "wrongpass"
}

o Expected Response:
 Status Code: 401 Unauthorized
 Response Body:

json
Copy code
{
"error": "Invalid credentials"
}

o Validation: Status code 401 aur "Invalid credentials" ka error message aaye.

3. Scenario 3: Login with Blank Fields


o Request:
 Method: POST
 Endpoint: /api/login
 Body:

json
Copy code
{
"username": "",
"password": ""
}

o Expected Response:
 Status Code: 400 Bad Request
 Response Body:

json
Copy code
{
"error": "Username and password required"
}

o Validation: Status code 400 aur error message aaye "Username and password
required".

4. Scenario 4: Login with SQL Injection Attempt


o Request:
 Method: POST
 Endpoint: /api/login
 Body:

json
Copy code
{
"username": "' OR 1=1 --",
"password": "anyPassword"
}

o Expected Response:
 Status Code: 400 Bad Request or 401 Unauthorized
 Response Body:

json
Copy code
{
"error": "Invalid input"
}

o Validation: Status code 400 or 401 aur error message aaye jo SQL injection attempt ko
handle kare.

5. Scenario 5: Logout Verification


o Request:
 Method: POST
 Endpoint: /api/logout
 Headers: Authorization: Bearer <token>
o Expected Response:
 Status Code: 200 OK
 Response Body:

json
Copy code
{
"message": "Logout successful"
}

o Validation: Status code 200 aur message aaye "Logout successful".

Steps to Run in Postman

1. Create Requests: Har scenario ke liye ek request create karein aur expected inputs aur
responses ko configure karein.
2. Add Tests: Har request ke Tests tab me JavaScript code likhein jo status code aur response
body ko validate kare.
3. Run Collection: Sab requests ko ek collection me save karein aur Runner me open kar ke Run
karein.
4. View Results: Runner me detailed pass/fail results aur response times dekhein.

Is tarah ye Postman collection different login scenarios ko test karega aur expected outputs ko
validate karega.

4o

You said:

json ki file export kr k kya krty hn

ChatGPT said:

ChatGPT

Postman me JSON file export krne ka primary purpose ye hai ke aap apne API requests aur
collections ko share, backup, aur automate kar saken. JSON file export karke aap ye actions le
sakte hain:

1. Share with Team: JSON file ko apne team ke members ke sath share kar sakte hain, jo
ise import karke same collection aur tests apne Postman pe use kar sakte hain.
2. Version Control: JSON file ko version control system (e.g., Git) me store kar sakte hain.
Is tarah, aap kisi bhi update ka track rakh sakte hain aur changes ko easily manage kar
sakte hain.
3. Automate Testing with Newman: JSON file ko Newman ke sath use karke command-line
se automated testing run ki ja sakti hai. Ye CI/CD pipelines me bhi helpful hai, jisme aap
collection ko Jenkins, GitLab, ya kisi aur CI tool se integrate kar sakte hain.
4. Backup and Restore: Exported JSON file ko backup ke tor pe rakh sakte hain aur agar
kisi bhi reason se Postman me collection delete ho jaye to ise easily import karke restore
kiya ja sakta hai.

Ye exported JSON file APIs ki documentation aur testing ko shareable aur maintainable banati
hai.

4o

You said:

HTTP methods hm postman mn use krty hn?

ChatGPT said:

ChatGPT

Postman me commonly used HTTP methods ye hain:


1. GET – Data retrieve karne ke liye use hota hai. Example: Kisi user ka profile data fetch karna.
2. POST – New resource create karne ke liye. Example: Naya user create karna ya data submit
karna.
3. PUT – Existing resource ko update karne ke liye. Example: Kisi user ka profile update karna.
4. DELETE – Resource delete karne ke liye. Example: Kisi specific record ya user ko delete karna.
5. PATCH – Partially update karne ke liye. Example: Sirf kuch fields ko update karna, jaise email ya
phone number.
6. OPTIONS – Server se allow honay wale methods ki information fetch karne ke liye.
7. HEAD – GET request ki tarah, lekin ye sirf headers return karta hai, body nahi.

Postman me in methods ko select kar ke aap API endpoints pe different actions perform aur test
kar sakte hain.

4o

You said:

You might also like