Перейти к содержимому

Фотография

Автотест для postman

postman

  • Авторизуйтесь для ответа в теме
Сообщений в теме: 26

#1 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 31 августа 2018 - 07:50

Всем доброго времени суток. Подскажите как написать тест. Нужно проверить все ли поля присутствуют.

 

Есть респонс:

{
    "data": {
        "id": ---,
        "email": "---",
        "mobile_number": "---",
        "card_number": "---",
        "code": "---",
        "card_virtual": ---,
        "first_name": "---",
        "middle_name": ---,
        "last_name": "---",
        "full_name": "---",
        "photo": "",
        "gender": ---,
        "language": ---,
        "accept_offers": ---,
        "accept_messages": ---,
        "birth_date": "---",
        "anniversary_date": ---,
        "status": "---",
        "cumulative": ---,
        "active_points": ---,
        "loyalty_cash": 0,
        "registered_at_james": "---",
        "messaging_via_email": ---,
        "messaging_via_sms": ---,
        "city": {
            "id": ---,
            "name": "---"
        }
    }
}
 
Автотест который я пробовал писать
 
const schema = {
  "required": [
      "id",
      "email",
      "mobile_number",
      "card_number",
      "code",
      "card_virtual",
      "first_name",
      "middle_name",
      "last_name",
      "full_name",
      "photo",
      "gender",
      "language",
      "accept_offers",
      "accept_messages",
      "birth_date",
      "anniversary_date",
      "status",
      "cumulative",
      "active_points",
      "loyalty_cash",
      "registered_at_james",
      "messaging_via_email",
      "messaging_via_sms",
      "city",
         "city.id",
         "city.name",
     ]
  };
  
  var data = JSON.parse(responseBody);  


pm.test('Body is correct', function() {
  pm.expect(tv4.validate(data, schema)).to.be.true;
});

 


  • 0

#2 Spock

Spock

    Профессионал

  • Members
  • PipPipPipPipPipPip
  • 1 772 сообщений
  • ФИО:Роман

Отправлено 31 августа 2018 - 08:10

схема вроде странно выглядит, без иерархии объектов. Первый уроверь это "data" а в схеме его вообще нет

 

и вообще, схему надо делать с помощью генератора схем и допиливать руками, а не вручную писать

 

пример сгенерированной схемы (надо дорабатывать согласно типам данным, я просто проставил 123 где не стринг)

  1 {
  2   "definitions": {}, 
  3   "$schema": "http://json-schema.org/draft-07/schema#", 
  4   "$id": "http://example.com/root.json", 
  5   "type": "object", 
  6   "title": "The Root Schema", 
  7   "required": [
  8     "data"
  9   ], 
 10   "properties": {
 11     "data": {
 12       "$id": "#/properties/data", 
 13       "type": "object", 
 14       "title": "The Data Schema", 
 15       "required": [
 16         "id", 
 17         "email", 
 18         "mobile_number", 
 19         "card_number", 
 20         "code", 
 21         "card_virtual", 
 22         "first_name", 
 23         "middle_name", 
 24         "last_name", 
 25         "full_name", 
 26         "photo", 
 27         "gender", 
 28         "language", 
 29         "accept_offers", 
 30         "accept_messages", 
 31         "birth_date", 
 32         "anniversary_date", 
 33         "status", 
 34         "cumulative", 
 35         "active_points", 
 36         "loyalty_cash", 
 37         "registered_at_james", 
 38         "messaging_via_email", 
 39         "messaging_via_sms", 
 40         "city"
 41       ], 
 42       "properties": {
 43         "id": {
 44           "$id": "#/properties/data/properties/id", 
 45           "type": "integer", 
 46           "title": "The Id Schema", 
 47           "default": 0, 
 48           "examples": [
 49             123
 50           ]
 51         }, 
 52         "email": {
 53           "$id": "#/properties/data/properties/email", 
 54           "type": "string", 
 55           "title": "The Email Schema", 
 56           "default": "", 
 57           "examples": [
 58             "---"
 59           ], 
 60           "pattern": "^(.*)$"
 61         }, 
 62         "mobile_number": {
 63           "$id": "#/properties/data/properties/mobile_number", 
 64           "type": "string", 
 65           "title": "The Mobile_number Schema", 
 66           "default": "", 
 67           "examples": [
 68             "---"
 69           ], 
 70           "pattern": "^(.*)$"
 71         }, 
 72         "card_number": {
 73           "$id": "#/properties/data/properties/card_number", 
 74           "type": "string", 
 75           "title": "The Card_number Schema", 
 76           "default": "", 
 77           "examples": [
 78             "---"
 79           ], 
 80           "pattern": "^(.*)$"
 81         }, 
 82         "code": {
 83           "$id": "#/properties/data/properties/code", 
 84           "type": "string", 
 85           "title": "The Code Schema", 
 86           "default": "", 
 87           "examples": [
 88             "---"
 89           ], 
 90           "pattern": "^(.*)$"
 91         }, 
 92         "card_virtual": {
 93           "$id": "#/properties/data/properties/card_virtual", 
 94           "type": "integer", 
 95           "title": "The Card_virtual Schema", 
 96           "default": 0, 
 97           "examples": [
 98             123
 99           ]
100         }, 
101         "first_name": {
102           "$id": "#/properties/data/properties/first_name", 
103           "type": "string", 
104           "title": "The First_name Schema", 
105           "default": "", 
106           "examples": [
107             "---"
108           ], 
109           "pattern": "^(.*)$"
110         }, 
111         "middle_name": {
112           "$id": "#/properties/data/properties/middle_name", 
113           "type": "integer", 
114           "title": "The Middle_name Schema", 
115           "default": 0, 
116           "examples": [
117             123
118           ]
119         }, 
120         "last_name": {
121           "$id": "#/properties/data/properties/last_name", 
122           "type": "string", 
123           "title": "The Last_name Schema", 
124           "default": "", 
125           "examples": [
126             "---"
127           ], 
128           "pattern": "^(.*)$"
129         }, 
130         "full_name": {
131           "$id": "#/properties/data/properties/full_name", 
132           "type": "string", 
133           "title": "The Full_name Schema", 
134           "default": "", 
135           "examples": [
136             "---"
137           ], 
138           "pattern": "^(.*)$"
139         }, 
140         "photo": {
141           "$id": "#/properties/data/properties/photo", 
142           "type": "string", 
143           "title": "The Photo Schema", 
144           "default": "", 
145           "examples": [
146             ""
147           ], 
148           "pattern": "^(.*)$"
149         }, 
150         "gender": {
151           "$id": "#/properties/data/properties/gender", 
152           "type": "integer", 
153           "title": "The Gender Schema", 
154           "default": 0, 
155           "examples": [
156             123
157           ]
158         }, 
159         "language": {
160           "$id": "#/properties/data/properties/language", 
161           "type": "integer", 
162           "title": "The Language Schema", 
163           "default": 0, 
164           "examples": [
165             123
166           ]
167         }, 
168         "accept_offers": {
169           "$id": "#/properties/data/properties/accept_offers", 
170           "type": "integer", 
171           "title": "The Accept_offers Schema", 
172           "default": 0, 
173           "examples": [
174             123
175           ]
176         }, 
177         "accept_messages": {
178           "$id": "#/properties/data/properties/accept_messages", 
179           "type": "integer", 
180           "title": "The Accept_messages Schema", 
181           "default": 0, 
182           "examples": [
183             123
184           ]
185         }, 
186         "birth_date": {
187           "$id": "#/properties/data/properties/birth_date", 
188           "type": "string", 
189           "title": "The Birth_date Schema", 
190           "default": "", 
191           "examples": [
192             "---"
193           ], 
194           "pattern": "^(.*)$"
195         }, 
196         "anniversary_date": {
197           "$id": "#/properties/data/properties/anniversary_date", 
198           "type": "integer", 
199           "title": "The Anniversary_date Schema", 
200           "default": 0, 
201           "examples": [
202             123
203           ]
204         }, 
205         "status": {
206           "$id": "#/properties/data/properties/status", 
207           "type": "string", 
208           "title": "The Status Schema", 
209           "default": "", 
210           "examples": [
211             "---"
212           ], 
213           "pattern": "^(.*)$"
214         }, 
215         "cumulative": {
216           "$id": "#/properties/data/properties/cumulative", 
217           "type": "integer", 
218           "title": "The Cumulative Schema", 
219           "default": 0, 
220           "examples": [
221             123
222           ]
223         }, 
224         "active_points": {
225           "$id": "#/properties/data/properties/active_points", 
226           "type": "integer", 
227           "title": "The Active_points Schema", 
228           "default": 0, 
229           "examples": [
230             123
231           ]
232         }, 
233         "loyalty_cash": {
234           "$id": "#/properties/data/properties/loyalty_cash", 
235           "type": "integer", 
236           "title": "The Loyalty_cash Schema", 
237           "default": 0, 
238           "examples": [
239             0
240           ]
241         }, 
242         "registered_at_james": {
243           "$id": "#/properties/data/properties/registered_at_james", 
244           "type": "string", 
245           "title": "The Registered_at_james Schema", 
246           "default": "", 
247           "examples": [
248             "---"
249           ], 
250           "pattern": "^(.*)$"
251         }, 
252         "messaging_via_email": {
253           "$id": "#/properties/data/properties/messaging_via_email", 
254           "type": "integer", 
255           "title": "The Messaging_via_email Schema", 
256           "default": 0, 
257           "examples": [
258             123
259           ]
260         }, 
261         "messaging_via_sms": {
262           "$id": "#/properties/data/properties/messaging_via_sms", 
263           "type": "integer", 
264           "title": "The Messaging_via_sms Schema", 
265           "default": 0, 
266           "examples": [
267             123
268           ]
269         }, 
270         "city": {
271           "$id": "#/properties/data/properties/city", 
272           "type": "object", 
273           "title": "The City Schema", 
274           "required": [
275             "id", 
276             "name"
277           ], 
278           "properties": {
279             "id": {
280               "$id": "#/properties/data/properties/city/properties/id", 
281               "type": "integer", 
282               "title": "The Id Schema", 
283               "default": 0, 
284               "examples": [
285                 123
286               ]
287             }, 
288             "name": {
289               "$id": "#/properties/data/properties/city/properties/name", 
290               "type": "string", 
291               "title": "The Name Schema", 
292               "default": "", 
293               "examples": [
294                 "---"
295               ], 
296               "pattern": "^(.*)$"
297             }
298           }
299         }
300       }
301     }
302   }
303 }

  • 0

#3 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 31 августа 2018 - 08:24

 

схема вроде странно выглядит, без иерархии объектов. Первый уроверь это "data" а в схеме его вообще нет

 

и вообще, схему надо делать с помощью генератора схем и допиливать руками, а не вручную писать

 

пример сгенерированной схемы (надо дорабатывать согласно типам данным, я просто проставил 123 где не стринг)

  1 {
  2   "definitions": {}, 
  3   "$schema": "http://json-schema.org/draft-07/schema#", 
  4   "$id": "http://example.com/root.json", 
  5   "type": "object", 
  6   "title": "The Root Schema", 
  7   "required": [
  8     "data"
  9   ], 
 10   "properties": {
 11     "data": {
 12       "$id": "#/properties/data", 
 13       "type": "object", 
 14       "title": "The Data Schema", 
 15       "required": [
 16         "id", 
 17         "email", 
 18         "mobile_number", 
 19         "card_number", 
 20         "code", 
 21         "card_virtual", 
 22         "first_name", 
 23         "middle_name", 
 24         "last_name", 
 25         "full_name", 
 26         "photo", 
 27         "gender", 
 28         "language", 
 29         "accept_offers", 
 30         "accept_messages", 
 31         "birth_date", 
 32         "anniversary_date", 
 33         "status", 
 34         "cumulative", 
 35         "active_points", 
 36         "loyalty_cash", 
 37         "registered_at_james", 
 38         "messaging_via_email", 
 39         "messaging_via_sms", 
 40         "city"
 41       ], 
 42       "properties": {
 43         "id": {
 44           "$id": "#/properties/data/properties/id", 
 45           "type": "integer", 
 46           "title": "The Id Schema", 
 47           "default": 0, 
 48           "examples": [
 49             123
 50           ]
 51         }, 
 52         "email": {
 53           "$id": "#/properties/data/properties/email", 
 54           "type": "string", 
 55           "title": "The Email Schema", 
 56           "default": "", 
 57           "examples": [
 58             "---"
 59           ], 
 60           "pattern": "^(.*)$"
 61         }, 
 62         "mobile_number": {
 63           "$id": "#/properties/data/properties/mobile_number", 
 64           "type": "string", 
 65           "title": "The Mobile_number Schema", 
 66           "default": "", 
 67           "examples": [
 68             "---"
 69           ], 
 70           "pattern": "^(.*)$"
 71         }, 
 72         "card_number": {
 73           "$id": "#/properties/data/properties/card_number", 
 74           "type": "string", 
 75           "title": "The Card_number Schema", 
 76           "default": "", 
 77           "examples": [
 78             "---"
 79           ], 
 80           "pattern": "^(.*)$"
 81         }, 
 82         "code": {
 83           "$id": "#/properties/data/properties/code", 
 84           "type": "string", 
 85           "title": "The Code Schema", 
 86           "default": "", 
 87           "examples": [
 88             "---"
 89           ], 
 90           "pattern": "^(.*)$"
 91         }, 
 92         "card_virtual": {
 93           "$id": "#/properties/data/properties/card_virtual", 
 94           "type": "integer", 
 95           "title": "The Card_virtual Schema", 
 96           "default": 0, 
 97           "examples": [
 98             123
 99           ]
100         }, 
101         "first_name": {
102           "$id": "#/properties/data/properties/first_name", 
103           "type": "string", 
104           "title": "The First_name Schema", 
105           "default": "", 
106           "examples": [
107             "---"
108           ], 
109           "pattern": "^(.*)$"
110         }, 
111         "middle_name": {
112           "$id": "#/properties/data/properties/middle_name", 
113           "type": "integer", 
114           "title": "The Middle_name Schema", 
115           "default": 0, 
116           "examples": [
117             123
118           ]
119         }, 
120         "last_name": {
121           "$id": "#/properties/data/properties/last_name", 
122           "type": "string", 
123           "title": "The Last_name Schema", 
124           "default": "", 
125           "examples": [
126             "---"
127           ], 
128           "pattern": "^(.*)$"
129         }, 
130         "full_name": {
131           "$id": "#/properties/data/properties/full_name", 
132           "type": "string", 
133           "title": "The Full_name Schema", 
134           "default": "", 
135           "examples": [
136             "---"
137           ], 
138           "pattern": "^(.*)$"
139         }, 
140         "photo": {
141           "$id": "#/properties/data/properties/photo", 
142           "type": "string", 
143           "title": "The Photo Schema", 
144           "default": "", 
145           "examples": [
146             ""
147           ], 
148           "pattern": "^(.*)$"
149         }, 
150         "gender": {
151           "$id": "#/properties/data/properties/gender", 
152           "type": "integer", 
153           "title": "The Gender Schema", 
154           "default": 0, 
155           "examples": [
156             123
157           ]
158         }, 
159         "language": {
160           "$id": "#/properties/data/properties/language", 
161           "type": "integer", 
162           "title": "The Language Schema", 
163           "default": 0, 
164           "examples": [
165             123
166           ]
167         }, 
168         "accept_offers": {
169           "$id": "#/properties/data/properties/accept_offers", 
170           "type": "integer", 
171           "title": "The Accept_offers Schema", 
172           "default": 0, 
173           "examples": [
174             123
175           ]
176         }, 
177         "accept_messages": {
178           "$id": "#/properties/data/properties/accept_messages", 
179           "type": "integer", 
180           "title": "The Accept_messages Schema", 
181           "default": 0, 
182           "examples": [
183             123
184           ]
185         }, 
186         "birth_date": {
187           "$id": "#/properties/data/properties/birth_date", 
188           "type": "string", 
189           "title": "The Birth_date Schema", 
190           "default": "", 
191           "examples": [
192             "---"
193           ], 
194           "pattern": "^(.*)$"
195         }, 
196         "anniversary_date": {
197           "$id": "#/properties/data/properties/anniversary_date", 
198           "type": "integer", 
199           "title": "The Anniversary_date Schema", 
200           "default": 0, 
201           "examples": [
202             123
203           ]
204         }, 
205         "status": {
206           "$id": "#/properties/data/properties/status", 
207           "type": "string", 
208           "title": "The Status Schema", 
209           "default": "", 
210           "examples": [
211             "---"
212           ], 
213           "pattern": "^(.*)$"
214         }, 
215         "cumulative": {
216           "$id": "#/properties/data/properties/cumulative", 
217           "type": "integer", 
218           "title": "The Cumulative Schema", 
219           "default": 0, 
220           "examples": [
221             123
222           ]
223         }, 
224         "active_points": {
225           "$id": "#/properties/data/properties/active_points", 
226           "type": "integer", 
227           "title": "The Active_points Schema", 
228           "default": 0, 
229           "examples": [
230             123
231           ]
232         }, 
233         "loyalty_cash": {
234           "$id": "#/properties/data/properties/loyalty_cash", 
235           "type": "integer", 
236           "title": "The Loyalty_cash Schema", 
237           "default": 0, 
238           "examples": [
239             0
240           ]
241         }, 
242         "registered_at_james": {
243           "$id": "#/properties/data/properties/registered_at_james", 
244           "type": "string", 
245           "title": "The Registered_at_james Schema", 
246           "default": "", 
247           "examples": [
248             "---"
249           ], 
250           "pattern": "^(.*)$"
251         }, 
252         "messaging_via_email": {
253           "$id": "#/properties/data/properties/messaging_via_email", 
254           "type": "integer", 
255           "title": "The Messaging_via_email Schema", 
256           "default": 0, 
257           "examples": [
258             123
259           ]
260         }, 
261         "messaging_via_sms": {
262           "$id": "#/properties/data/properties/messaging_via_sms", 
263           "type": "integer", 
264           "title": "The Messaging_via_sms Schema", 
265           "default": 0, 
266           "examples": [
267             123
268           ]
269         }, 
270         "city": {
271           "$id": "#/properties/data/properties/city", 
272           "type": "object", 
273           "title": "The City Schema", 
274           "required": [
275             "id", 
276             "name"
277           ], 
278           "properties": {
279             "id": {
280               "$id": "#/properties/data/properties/city/properties/id", 
281               "type": "integer", 
282               "title": "The Id Schema", 
283               "default": 0, 
284               "examples": [
285                 123
286               ]
287             }, 
288             "name": {
289               "$id": "#/properties/data/properties/city/properties/name", 
290               "type": "string", 
291               "title": "The Name Schema", 
292               "default": "", 
293               "examples": [
294                 "---"
295               ], 
296               "pattern": "^(.*)$"
297             }
298           }
299         }
300       }
301     }
302   }
303 }

Спасибо Вам!
Какой генератор схем? 


  • 0

#4 Spock

Spock

    Профессионал

  • Members
  • PipPipPipPipPipPip
  • 1 772 сообщений
  • ФИО:Роман

Отправлено 31 августа 2018 - 09:46

https://www.jsonschema.net/

 

я сгенерировал первым попавшимся, но вы выбирайте который лучше вам подойдёт


  • 0

#5 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 31 августа 2018 - 09:52

https://www.jsonschema.net/

 

я сгенерировал первым попавшимся, но вы выбирайте который лучше вам подойдёт

Спасибо :smile:


  • 0

#6 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 03 сентября 2018 - 07:05

Подскажите как задать переменную рандомные символы (буквы/числа). Мне надо задать чтоб каждый раз создавало електронную почту и мобильный номер при новом запросе на регистрацию. Спасибо! :smile:

var random = jsonContent.featured[Math.floor(Math.random() * jsonContent.featured.length)];
console.log(random) 

Нашел такой вот вариант, но не знаю как присвоить переменную для mobile number. И проблема, надо вставить код +380 перед номером который сгенирирует, а число должно быть из 7ми цыфр
 


  • 0

#7 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 03 сентября 2018 - 07:52

pm.environment.set("mobile_number", "+38066" + _.random(1000000, 9999999));
pm.environment.set("email", Math.random().toString(35) + "@mail.com");
 

Получилось таким кодом. Может кому надо будет :smile:


  • 1

#8 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 03 сентября 2018 - 13:13

Как проверить в объекте JSON наличие определенного поля?

 

есть поле Status: ok

 

 

пишу такой код:

var json = '{"status"}',
    data = JSON.parse(responseBody);
if ('status' in data) {
    alert('Status: ok');
} else {
    alert('поля нет');
}

Ошибку выдает : ReferenceError: alert is not defined

 


  • 0

#9 BadMF

BadMF

    Специалист

  • Members
  • PipPipPipPipPip
  • 809 сообщений
  • ФИО:Dmitry Petrov

Отправлено 03 сентября 2018 - 14:16

var alert;

  • 0

#10 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 03 сентября 2018 - 14:28

var alert;

объясните пожалуйста, а то я только учусь писать тесты.


  • 0

#11 BadMF

BadMF

    Специалист

  • Members
  • PipPipPipPipPip
  • 809 сообщений
  • ФИО:Dmitry Petrov

Отправлено 03 сентября 2018 - 15:28

К тестам это имеет очень опосредствованное отношение.

 

Ошибку выдает : ReferenceError: alert is not defined

 

<var name> is not defined

 

Говорит о том, что переменная не объявлена. Её надо либо объявить, либо дать на неё корректную ссылку, о чём нам сообщает наименование исключения ReferenceError.

alert насколько я понимаю, далеко не в каждом инструменте можно использовать просто так. 

вообще, то, что я написал, это костыль, я не знаю объектную модель вашего фрэймворка (я даже не знаю какой у вас фрэймворк, так как не читал весь топик), у вас скорее всего alert находится в каком-нибудь window или ещё где, и в этом случае надо писать 

<Parrent>.alert('textHere');

Если вкраце, rtfm.


  • 0

#12 Spock

Spock

    Профессионал

  • Members
  • PipPipPipPipPipPip
  • 1 772 сообщений
  • ФИО:Роман

Отправлено 03 сентября 2018 - 21:53

 

 

Как проверить в объекте JSON наличие определенного поля?

схемой


  • 0

#13 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 04 сентября 2018 - 07:01

К тестам это имеет очень опосредствованное отношение.

 

Ошибку выдает : ReferenceError: alert is not defined

 

<var name> is not defined

 

Говорит о том, что переменная не объявлена. Её надо либо объявить, либо дать на неё корректную ссылку, о чём нам сообщает наименование исключения ReferenceError.

alert насколько я понимаю, далеко не в каждом инструменте можно использовать просто так. 

вообще, то, что я написал, это костыль, я не знаю объектную модель вашего фрэймворка (я даже не знаю какой у вас фрэймворк, так как не читал весь топик), у вас скорее всего alert находится в каком-нибудь window или ещё где, и в этом случае надо писать 

<Parrent>.alert('textHere');

Если вкраце, rtfm.

Спасибо!


  • 0

#14 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 04 сентября 2018 - 07:05

 

 

 

Как проверить в объекте JSON наличие определенного поля?

схемой

 

Уже до меня дошло. Проверяю схемой.)


  • 0

#15 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 04 сентября 2018 - 08:17

Есть поля в респонсе

"full_name": "Customer Laster",
"photo": "",
"gender": null,

пишу код для проверки

pm.expect(data.data.full_name).to.be.a('string');
pm.expect(data.data.photo).to.be.a('null');
pm.expect(data.data.gender).to.be.a('string');

и пишет ошибку

AssertionError: expected '' to be a null

  • 0

#16 BadMF

BadMF

    Специалист

  • Members
  • PipPipPipPipPip
  • 809 сообщений
  • ФИО:Dmitry Petrov

Отправлено 04 сентября 2018 - 08:37

это не ошибка, а результат проваленного теста, так как вы ожидается пустое значение у параметра, а оно не null, а "", что не одно и то же.


  • 1

#17 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 04 сентября 2018 - 15:57

как можно вписать переменную в тест для постмена? для переменной создает автоматически email, хочу чтоб проверял тест - соответсвует ли респонс переменной

pm.test("Your test name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.email).to.eql("???");
});

  • 0

#18 Spock

Spock

    Профессионал

  • Members
  • PipPipPipPipPipPip
  • 1 772 сообщений
  • ФИО:Роман

Отправлено 04 сентября 2018 - 16:41

https://www.getpostm...obals/variables


  • 0

#19 djkjlz

djkjlz

    Новый участник

  • Members
  • Pip
  • 24 сообщений
  • ФИО:Владимир

Отправлено 05 сентября 2018 - 09:52

как написать схему для проверки полей в респонсе?

{
"data": [
{
"id": 558,
"name": "Riyadh",
"type": 2
   }
  ]
}

писал такой код

const schema = {
 "data": [
    "id",
    "name",
    "type"],
};

var data = JSON.parse(responseBody);

pm.test('Body is correct', function() {
pm.expect(tv4.validate(data, schema)).to.be.true;
});

когда меняю название поля всеравно пишет что тест прошел, при том что поля нет в респонсе

 

  • 0

#20 Spock

Spock

    Профессионал

  • Members
  • PipPipPipPipPipPip
  • 1 772 сообщений
  • ФИО:Роман

Отправлено 05 сентября 2018 - 10:00

а почему не используете генератор схем и пишете свои, неправильные?


  • 0



Темы с аналогичным тегами postman

Количество пользователей, читающих эту тему: 0

0 пользователей, 0 гостей, 0 анонимных