500 - something wrong with server
pm.test - accepts two parametres
API - interface to a server that has some data or tasks some actions.
How to create variables
{{baseUrl}}/books/1 - Postman zamenit etot parameter with value -> {{baseUrl}}/books/:bookId
access token - like a temporary password, when you authorize yourself.
_______________________________________________
Test in Postman always starts from pm.test() - a function that takes two parameters.
1) first parameter - the name of the test:
pm.test("Status should be OK");
2) second parameter - call back function:
pm.test("Status should be OK", () => {});
Тhen we write utvergdenie:
pm.test("Status should be OK", () => {
pm.expect(1).to.eql(1); - expect - то, что мы ожидает получить;
});
_______________________________________________________________________
pm.test("Status should be OK", () => {
pm.expect(response.status).to.eql("OK");
});
вывод: способ убедиться, что этот эндпоинт работает правильно.
____________
pm.test("Status code is 200", () => {
pm.response.to.have.status(200); - means - we looking for Respons, to have Status ok
});
_____
Pre-request - it is something that will be ran before our request will be sent.(here we can create Local variables)
make sure that we see what we want to test INSIDE console.log
__________________________
сначала мы видим массив [ ]
поэтому нам нужно получить данные сначала из массива. Затем у нас есть объект, в котором мы можем вызвать идентификатор свойства (Property ID).
массив который у нас есть имеет ключи. по сути способ который позволяет нам получить доступ к этой информации .
например - [0] - даст нам первый элемент из массива.
then choose "set a global variable":
pm.globals.set("variable_key", "variable_value");
then change data to :
pm.globals.set("bookId", "nonFictionBooks[0].id");(because we want to know only property fo this object.
Testing
pm.test("Status code is 204", () => {
pm.response.to.have.status(204);
});
const response = pm.response.json(); - определить переменную с именем response, syntax parsing (pm.response.json());
внутри этой переменной ответа в JavaScript теперь будет ответ, который будет проанализирован из json в JavaScript.
const response - to define JavaScript variable;
console.log(response) - указываем в этот параметр функции Параметр. и этот параметр "response"
(Open console, clean -> SEND request)
STATUS 200 OK Testing
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
})
__it is an automaticly command^________________________________
const response = pm.response.json();
console.log(response['status']);
pm.test("Status should be OK", () => {
pm.expect(response.status). to.eql("OK")
});
_______it is manual command (the same)^__________________________________
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
https://www.json.org/json-en.html
https://blog.postman.com/looping-through-a-data-file-in-the-postman-collection-runner/
number in JSON without "" (числа)