Titan Quest Fans Forum
Titan Quest - Anniversary Edition => Java private => Ragnarok => Java => Topic started by: efko on 05 May 2020, 17:12:44
-
// Jejson je obicni tekstualni fajl (Json)
// restfullAPI
// deli se na front end i back end developere
// dokumentacija struktura apija i base podataka
// get i post poruke se najvise koriste
// get je previse otvoren, sve putuju kroz url i otvoren je, sto znaci da ne zelimo da se vide broj kartice za placanje
// slicno pa se koristi vise post
// delete
// morpheus znaci vodja
// sa svakom porukom server vraca odgovor
// postman je dobra dokumentacija, kad se radi sa servisima imamo dokumentaciju API liste poziva za sve sta se desava
// https://www.getpostman.com/
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
// https://learning.getpostman.com/docs/postman/launching-postman/introduction/
Napisati tri zahteva u postmanu, objasniti ih uz jednu recenicu i postaviti na drajvu.
Literatura i API
https://jsonplaceholder.typicode.com/
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
https://reqres.in/
Automatizacija API testova pomoću Postmena
Test API https://vue-demo.daniel-avellaneda.com/
Klijent za API koji se testira https://vue-demo.daniel-avellaneda.com/
Dokumentacija Rest API-a je yaml fajl, koji otvarate u Swagger editoru tako što izaberete File > Import File > izaberete pomenuti yaml fajl
Koristan video trening: Testiranje API-a pomoću Postmena možete kupiti na udemy-u ili skinuti sa ovo linka.
Da bismo uspešno istestirali API, moramo se prvo upoznati sa logikom i videti u kojim situacijama se koriste dati API pozivi. U tome će nam dosta pomoći analiza same klijentske aplikacije. Potrebno je upoznati se sa aplikacijom, i saznati što više informacija za svaki od navedenih api poziva. Sve potrebne informacije možete naći u Network prozoru kao na slici 1.
Slika 1. Praćenje API poziva iz Network prozora
Na kraju dolazimo do prvog zadatka, a to je:
U eksel tabeli, klonirajte sheet Sablon i nazovite ga svojim imenom a zatim popunite tabelu.
Za razmevanje procesa prijavljivanja i svrhe u koju se koristi token, potrebno je upoznati se sa JWT tokenom. Koristan video trening na tu temu možete pogledati na youtube-u.
2. Pisanje API-poziva u Postmenu
Smernice kojima bi se trebali voditi:
● imena poziva su ista kao imena ruta
● Upotreba globalnih promenljivi ili promenljivi okruženja za:
○ naziv host-a, npr: {{base_url}}/registracija (udemy, Writing tests and scripts using variables)
○ tokene (udemy, Authentication / Authorization > JSON Web Tokens (JWT))
○ promenljive podatke, npr: login podaci, id-evi,
● Podatke iz dokumentacije koji se šalju kao formData, šaljite u body kao x-www-form-urlencoded
Napomena 1: Validne vrednosti za user role su “admin” i “user”
Napomena 2: Token je deo zaglavlja i mora se unositi u formatu sa ključnom rečju Bearer {{token}}
3. Pisanje API testova
U Postmenu testovi se pišu u JavaScript-u, tako da bi bilo dobro upoznati se malo sa tim programskim jezikom (udemy: JavaScript fundamentals, Writing tests and scripts, Writing tests and scripts using variables, Advanced assertions, Running a request multiple times with different data sets, ...)
Primeri nekih osnovnih testova link (Otvorite u Postmanu klikom na dugme Run in Postman). Neki od njih su zastareli ali je moguce naći novu veriju na linku.
Postoji mnogo načina za kreiranje testova, ali moja stroga preporuka je koristiti Chai Assertion Library (udemy: Advanced assertions )
U početku će vam biti teže da se povežete sa testiranjem u Postmanu, preporuka je da za debugiranje koristite konzolu (udemy: Writing tests and scripts using variables > Debugging tests )
Potrebno je implementirati testove koji su navedeni u daljem tekstu. Postoje 4 logičke grupe testova:
● auth testovi
● city testovi
● profile testovi
● user testovi
Auth testovi
Primer zapazanja za rutu /register:
Opis:
Poziva se pri registraciji novog korisnika. Od podataka se salje: Ime i prezime, email i password (sva polja su obavezna)
Zakljucak/Opazanje:
Uspesna registracija vraca status 201, i u responsu imamo token i podatke za usera.
Kada se korisnik registruje podrazumevano mu je role = "user".
Nakon registarcije se dobija email za verifikaciju.
Pokusaj registracije korisnika sa istim email-om vraca status 422 i gresku EMAIL_ALREADY_EXISTS.
Sigurno moze jos nesto da se doda, ali ovo je na primer za mene dovoljno.
-
>>>pet<<<
POST /pet
Pet object that needs to be added to the store - add a new pet to the store
body * object (body) - Pet object that needs to be added to the store
{
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
405 Invalid input
-------------------------------
PUT /pet
Pet object that needs to be added to the store - update existing pet
body * object (body) - Pet object that needs to be added to the store
{
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
400 Invalid ID supplied
404 Pet not found
405 Validation exception
-----------------
GET /pet/findByStatus
Multiple status values can be provided with comma separated strings - find pets By Status
status * array[string] (query) - Status values that need to be considered for filter
Available values : available, pending, sold
200 successful operation
400 Invalid status value
-----------------
[s]GET /pet/findByTags[/s] - Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing
tags * array[string] (query) - Tags to filter by
200 successful operation
400 Invalid status value
---------------------
GET /pet/{petId}
Returns a single pet - find pet by ID
petId * integer($int64) (path) - ID of pet to return
200 successful operation
<?xml version="1.0" encoding="UTF-8"?>
<Pet>
<id>0</id>
<Category>
<id>0</id>
<name>string</name>
</Category>
<name>doggie</name>
<photoUrl>
<photoUrl>string</photoUrl>
</photoUrl>
<tag>
<Tag>
<id>0</id>
<name>string</name>
</Tag>
</tag>
<status>available</status>
</Pet>
400 Invalid ID supplied
404 Pet not found
------------------------
POST /pet/{petId}
updates a pet with form data
petId * integer($int64) (path) - ID of pet that needs to be updated
name string (formData) - Updated name of the pet
status string (formData) - Updated status of the pet
405 Invalid input
------------------------
DELETE /pet/{petId}
deletes a pet
api_key string (header)
petId * integer($int64) - Pet id to delete
400 Invalid ID supplied
404 Pet not found
---------------------
POST /pet/{petId}/ uploadImage
petId * integer($int64) (path) - ID of pet to update
additional Metadata string -(formData) - Additional data to pass to server
file file (formData) - file to upload
200 successful operation
{
"code": 0,
"type": "string",
"message": "string"
}
-------------------
-
>>>store<<<
GET /store/inventory - returns store inventory by status
Returns a map of status codes to quantities
200 successful operation
{
"additionalProp1": 0,
"additionalProp2": 0,
"additionalProp3": 0
}
---------------------
POST /store/order - place an order for a pet
body * object (body) - order placed for purchasing the pet
{
"id": 0,
"petId": 0,
"quantity": 0,
"shipDate": "2020-05-05T21:34:47.821Z",
"status": "placed",
"complete": false
}
200 successful operation
<?xml version="1.0" encoding="UTF-8"?>
<Order>
<id>0</id>
<petId>0</petId>
<quantity>0</quantity>
<shipDate>2020-05-05T22:03:37.296Z</shipDate>
<status>placed</status>
<complete>false</complete>
</Order>
400 Invalid Order
------------------
GET /store/{orderId} find purchase order by ID
For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions
orderId * integer($int64) (path) - ID of pet that needs to be fetched
200 successful operation
<?xml version="1.0" encoding="UTF-8"?>
<Order>
<id>0</id>
<petId>0</petId>
<quantity>0</quantity>
<shipDate>2020-05-05T22:03:37.312Z</shipDate>
<status>placed</status>
<complete>false</complete>
</Order>
400 Invalid ID supplied
404 Order not found
------------------------
DELETE /store/order/{orderId} - Delete purchase order by ID
For valid response try integer IDs with positive integer value.
Negative or non-integer values will generate API errors
orderId * integer($int64) (path) - ID of the order that needs to be deleted
400 Invalid ID supplied
404 Order not found
--------------------
-
>>>USER<<<
POST /user - Create user
This can only be done by the logged in user.
body * object (body) - Created user object
default - successful operation
-------------------
POST /user/createWithArray - Creates list of users with given input array
body * array[object] (body) - List of user object
[
{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}
]
default - successful operation
-----------------------
POST /user/createWithList - Creates list of users with given input array
body * array[object] (body) - List of user object
[
{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}
]
default - successful operation
-----------------------
GET /user/login - Logs user into the system
username * string (query) - The user name for login
password * string (query) - The password for login in clear text
200 successful operation
<?xml version="1.0" encoding="UTF-8"?>
<!-- XML example cannot be generated; root element name is undefined -->
X-Rate-Limit - calls per hour allowed by the user - integer
X-Expires-After - date in UTC when token expires - string
400 Invalid username/password supplied
---------------------------
GET /user/logout- Logs out current logged in user session
default - successful operation
---------------------------
GET /user/{username} - Get user by user name
username * string (path) - The name that needs to be fetched. Use user1 for testing.
200 successful operation
<?xml version="1.0" encoding="UTF-8"?>
<User>
<id>0</id>
<username>string</username>
<firstName>string</firstName>
<lastName>string</lastName>
<email>string</email>
<password>string</password>
<phone>string</phone>
<userStatus>0</userStatus>
</User>
400 Invalid username supplied
404 User not found
------------------------
PUT /user/{username} - Updated user
This can only be done by the logged in user.
username * string (path) - name that need to be updated
body * object (body) - Updated user object
{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}
400 Invalid user supplied
404 User not found
--------------------------
DELETE /user/{username} - Delete user
This can only be done by the logged in user.
username * string (path) - The name that needs to be deleted
400 Invalid username supplied
404 User not found
----------------------
-
>>>MODELS<<<
ORDER
{
id integer($int64)
petId integer($int64)
quantity integer($int32)
shipDate string($date-time)
status string
Order Status
Enum:
Array [ 3 ]
complete boolean
default: false
}
-----------------
CATEGORY
{
id integer($int64)
name string
}
-----------------
USER
{
id integer($int64)
username string
firstName string
lastName string
email string
password string
phone string
userStatus integer($int32)
User Status
}
-------------------------
TAG
{
id integer($int64)
name string
}
--------------------------
PET
{
id integer($int64)
category Category{...} [Jump to definition]
name* string
example: doggie
photoUrls* [...]
tags [...]
status string
pet status in the store
Enum:
Array [ 3 ]
-----------------------
ApiResponse
{
code integer($int32)
type string
message string
}
----------------------
-
https://www.meetup.com/QA-Serbia/events/270436941
https://www.youtube.com/watch?v=LKveAwao9HA
https://www.youtube.com/watch?v=0S0zXTNzR7E&feature=youtu.be
https://www.guru99.com/postman-tutorial.html
https://stackoverflow.com/questions/58580641/vue-website-complains-that-javascript-isnt-enabled-after-vuetify-is-added - problem
https://learning.postman.com/docs/postman/sending-api-requests/debugging-and-logs/
https://learning.postman.com/docs/postman/sending-api-requests/requests/
https://learning.postman.com/docs/postman/sending-api-requests/authorization/#api-key > Bearer Token