ãAPIã®éçºã¯è€éã§ããPostmanã䜿çšãããšç°¡åã«ãªããŸããã©Postdot TechnologiesãInc
PostmanããŒã«ã®èª¬æãèŠããšãããã¯æ¯ãã®ããããªãã®ã§ãããå šèœæ§ã®æèŠãããªãã®å°æ¥ã®åå«ã«ç®èŠããŸãã éå»ã«æé·ãããã¢ã³ã¹ã¿ãŒããã€ãã«ããªãã®åã«èœã¡ãããã§ãïŒ
ãã®èšäºã§ã¯ãPostmanã«ã€ããŠèª¬æããæåã®ã¹ã¯ãªãããæžããŸãã
éµäŸ¿é éå¡
ã¢ããªã±ãŒã·ã§ã³ã®äž»ãªç®çã¯ãAPIãžã®ãªã¯ãšã¹ããå«ãã³ã¬ã¯ã·ã§ã³ãäœæããããšã§ãã ã³ã¬ã¯ã·ã§ã³ãéããšãéçºè ãŸãã¯ãã¹ã¿ãŒã¯ãµãŒãã¹ã®äœæ¥ãç°¡åã«ç解ã§ããããã«ãªããŸãã ããã«ãPostmanã䜿çšãããšãAPIãã¶ã€ã³ãèšèšããããã«åºã¥ããŠMockãµãŒããŒãäœæã§ããŸãã éçºè ã¯ã¹ã¿ãã®äœæã«æéãè²»ããå¿ èŠããªããªããŸããã ãµãŒããŒãšã¯ã©ã€ã¢ã³ãã®å®è£ ã¯åæã«éå§ã§ããŸãã ãã¹ã¿ãŒã¯ãPostmanããçŽæ¥ãã¹ããäœæããèªåãã¹ããå®è¡ã§ããŸãã ãŸããã³ã¬ã¯ã·ã§ã³ã®èª¬æãèªåçã«ææžåããããŒã«ã¯ãããã«å¥ã®ã䟿å©ãªæ©èœãã®æéãç¯çŽããŸãã 管çè åãã®æ©èœããããŸããäœæè ã¯ãç£èŠãµãŒãã¹çšã®ã³ã¬ã¯ã·ã§ã³ãäœæããæ©èœãæäŸããŠããŸãã
ã¯ããã«
1-ã³ã¬ã¯ã·ã§ã³ã2-ãã©ã«ããŒã3-èŠæ±
Postmanãåäœããäž»ãªæŠå¿µã¯ãæäžäœã®ã³ã¬ã¯ã·ã§ã³ãšæäžäœã®ãªã¯ãšã¹ãã§ãã ãã¹ãŠã®äœæ¥ã¯ã³ã¬ã¯ã·ã§ã³ããå§ãŸããã¯ãšãªã䜿çšããŠAPIãèšè¿°ããããšã«ãªããŸãã é çªã«ãã¹ãŠã詳ããèŠãŠãããŸãããã
ã³ã¬ã¯ã·ã§ã³
ã³ã¬ã¯ã·ã§ã³ã¯ãæ°ããAPIã®åºçºç¹ã§ãã ã³ã¬ã¯ã·ã§ã³ããããžã§ã¯ããã¡ã€ã«ãšããŠè¡šç€ºã§ããŸãã ã³ã¬ã¯ã·ã§ã³ã¯ãé¢é£ãããã¹ãŠã®ã¯ãšãªãçµåããŸãã éåžžãAPIã¯1ã€ã®ã³ã¬ã¯ã·ã§ã³ã§èšè¿°ãããŸãããå¿ èŠã«å¿ããŠãå¥ã®å¶éã¯ãããŸããã ã³ã¬ã¯ã·ã§ã³ã«ã¯ç¬èªã®ã¹ã¯ãªãããšå€æ°ãå«ããããšãã§ããŸãããããã«ã€ããŠã¯åŸã§èª¬æããŸãã
ãã©ã«ããŒ
ãã©ã«ããŒ-èŠæ±ãã³ã¬ã¯ã·ã§ã³å ã®1ã€ã®ã°ã«ãŒãã«çµåããããã«äœ¿çšãããŸãã ããšãã°ãAPIã®æåã®ããŒãžã§ã³ã§ãããv1ãçšã®ãã©ã«ããŒãäœæããå®è¡ãããã¢ã¯ã·ã§ã³ã®æå³ã«å¿ããŠãªã¯ãšã¹ããã°ã«ãŒãåããŸãããOrderïŒCheckoutãããUser profileããªã©ããã¹ãŠã¯ããªãã®æ³ååãšããŒãºã«ãã£ãŠã®ã¿å¶éãããŸãã ã³ã¬ã¯ã·ã§ã³ã®ãããªãã©ã«ããŒã«ã¯ãå€æ°ã§ã¯ãªãç¬èªã®ã¹ã¯ãªãããå«ããããšãã§ããŸãã
ãªã¯ãšã¹ã
ãªã¯ãšã¹ãã¯ã³ã¬ã¯ã·ã§ã³ã®äž»èŠã³ã³ããŒãã³ãã§ããããã¹ãŠãéå§ãããçç±ã§ãã èŠæ±ã¯ã³ã³ã¹ãã©ã¯ã¿ãŒã§äœæãããŸãã ã¯ãšãªãã¶ã€ããŒã¯ãäœæ¥ããå¿ èŠãããã¡ã€ã³ã¹ããŒã¹ã§ãã Postmanã¯ããã¹ãŠã®æšæºHTTPã¡ãœããã䜿çšããŠèŠæ±ãå®è¡ã§ããŸãããã¹ãŠã®èŠæ±ãã©ã¡ãŒã¿ãŒã¯ç®¡çäžã«ãããŸãã å¿ èŠãªããããŒãCookieãããã³ãªã¯ãšã¹ãæ¬æãç°¡åã«å€æŽãŸãã¯è¿œå ã§ããŸãã ãªã¯ãšã¹ãã«ã¯ç¬èªã®ã¹ã¯ãªããããããŸãã ãªã¯ãšã¹ããã©ã¡ãŒã¿ã®äžã®ãPre-request Scriptãããã³ãTestsãã¿ãã«æ³šæããŠãã ããã ãªã¯ãšã¹ãã®ååŸã«ã¹ã¯ãªãããè¿œå ã§ããŸãã ãããã®2ã€ã®æ©èœã«ãããPostmanã¯éçºãšãã¹ãã«åœ¹ç«ã€åŒ·åãªããŒã«ã«ãªããŸãã
1-èŠæ±ã®ããã¿ãã2-URLãšã¡ãœããã3-èŠæ±ãã©ã¡ãŒã¿ãŒã4-å¿çãã©ã¡ãŒã¿ãŒ
ã¹ã¯ãªãã
ãPostman Sandboxãã¯ããPre-request Scriptãããã³ãTestsãã¹ã¯ãªãããèšè¿°ãããšãã«äœ¿çšã§ããJavaScriptã©ã³ã¿ã€ã ã§ãã ãäºåèŠæ±ã¹ã¯ãªãããã¯ãèŠæ±ã®åã«å¿ èŠãªæäœãå®è¡ããããã«äœ¿çšãããŸããããšãã°ãå¥ã®ã·ã¹ãã ã«èŠæ±ãè¡ãããã®å®è¡çµæãã¡ã€ã³èŠæ±ã§äœ¿çšã§ããŸãã ããã¹ããã¯ããã¹ãã®äœæãçµæã®ç¢ºèªãããã³å¿ èŠã«å¿ããŠå€æ°ã«ä¿åããããã«äœ¿çšãããŸãã
ãªã¯ãšã¹ãã®ã·ãŒã±ã³ã¹ïŒå
¬åŒããã¥ã¡ã³ãããïŒ
ãªã¯ãšã¹ãã¬ãã«ã®ã¹ã¯ãªããã«å ããŠããã©ã«ããŒã¬ãã«ãããã«ã¯ã³ã¬ã¯ã·ã§ã³ã¬ãã«ã§ãã¹ã¯ãªãããäœæã§ããŸãã äºåèŠæ±ã¹ã¯ãªããããã³ãã¹ããšãåŒã°ããŸãããéãã¯ããã©ã«ããŒå ã®åèŠæ±ã®åãŸãã¯åŸã«ããŸãã¯ãæ³åã®ãšããã³ã¬ã¯ã·ã§ã³å šäœã§å®è¡ãããããšã§ãã
ãã©ã«ããŒããã³ã³ã¬ã¯ã·ã§ã³ã®ã¹ã¯ãªããã䜿çšããã¯ãšãªå®è¡ã®ã·ãŒã±ã³ã¹ïŒå
¬åŒããã¥ã¡ã³ãããïŒ
å€æ°
Postmanã«ã¯ãå€æ°çšã®ã¹ããŒã¹ãšã¹ã³ãŒããããã€ããããŸãã
- ã°ããŒãã«å€æ°
- ã³ã¬ã¯ã·ã§ã³å€æ°
- ç°å¢å€æ°
- ããŒã«ã«å€æ°
- ããŒã¿å±€å€æ°
ã°ããŒãã«å€æ°ããã³ç°å¢å€æ°ã¯ãããã°ã©ã ã®å³äžé ã«ããæ¯è»ãã¯ãªãã¯ããŠäœæã§ããŸãã ã³ã¬ã¯ã·ã§ã³ãšã¯å¥ã«ååšããŸãã ã³ã¬ã¯ã·ã§ã³ã¬ãã«ã®å€æ°ã¯ãã³ã¬ã¯ã·ã§ã³ãã©ã¡ãŒã¿ãŒã®ç·šéæã«çŽæ¥äœæãããããŒã«ã«å€æ°ã¯å®è¡å¯èœã¹ã¯ãªããããäœæãããŸãã ããŒã¿ã¬ãã«ã®å€æ°ããããŸããããããã¯ã©ã³ããŒããã®ã¿å©çšå¯èœã§ããããã«ã€ããŠã¯åŸã§èª¬æããŸãã
å¯å€ã¹ããŒã¹ã®åªå
床ïŒå
¬åŒããã¥ã¡ã³ãããïŒ
Postmanã®å€æ°ã®ç¹æ§ã¯ã眮æã®ãã¬ãŒã¹ãã«ããŒãšããŠäžæ¬åŒ§ã䜿çšããŠãã¯ãšãªã³ã³ã¹ãã©ã¯ã¿ãŒãURLãPOSTãã©ã¡ãŒã¿ãŒãCookieãã©ãã«ã§ãæ¿å ¥ã§ããããšã§ãã
{{domain}}ããã³{{slack_incoming_webhook}}-DNS Checkerç°å¢å€æ°ã¯ãã¯ãšãªã®å®è¡äžã«å€ã«çœ®ãæããããŸã
å€æ°ã¯ã¹ã¯ãªããããã䜿çšã§ããŸãããpmçµã¿èŸŒã¿ã©ã€ãã©ãªã®æšæºã¡ãœãããåŒã³åºããšãå€æ°ãååŸã§ããŸãã
// pm.globals.get("variable_key"); // pm.environment.get("variable_key"); // pm.variables.get("variable_key");
ã³ã¬ã¯ã·ã§ã³ã©ã³ããŒ
éžæããã³ã¬ã¯ã·ã§ã³ãŸãã¯ãã©ã«ããŒããã®ãã¹ãŠã®èŠæ±ããã¹ãããŠå®äºããããã«èšèšãããŠããŸãã èµ·åæã«ãå埩åæ°ããã©ã«ããŒãŸãã¯ã³ã¬ã¯ã·ã§ã³ãèµ·åãããåæ°ãç°å¢ãããã³å€æ°ä»ãã®è¿œå ãã¡ã€ã«ãæå®ã§ããŸãã ã³ã¬ã¯ã·ã§ã³ããã³ãã©ã«ãå ã®å Žæã«å¿ããŠãã¯ãšãªãé çªã«å®è¡ãããããšã«æ³šæããŠãã ããã å®è¡é åºã¯ãçµã¿èŸŒã¿ã³ãã³ãã䜿çšããŠå€æŽã§ããŸãã
// "Create order", postman.setNextRequest('Create order');
ãã¹ãŠã®ãªã¯ãšã¹ããå®äºãããšãããã¹ããã¹ã¯ãªããããã®æåãããã§ãã¯ãšå€±æãããã§ãã¯ã®æ°ã瀺ãã¬ããŒããçæãããŸãã
ã³ã¬ã¯ã·ã§ã³ã©ã³ããŒ
ã³ã³ãœãŒã«
ã³ã³ãœãŒã«ã䜿çšããŠã¹ã¯ãªããããããã°ãããªã¯ãšã¹ãã«é¢ããè¿œå æ å ±ã衚瀺ããŸãã ã³ã³ãœãŒã«ã¯ãåäžã®ãªã¯ãšã¹ãã®èµ·åäžãšãRunnerãä»ãããªã¯ãšã¹ãããã±ãŒãžã®èµ·åäžã®äž¡æ¹ã§æ©èœããŸãã ãããéãã«ã¯ãã¡ã€ã³ã¢ããªã±ãŒã·ã§ã³ç»é¢ã®å·Šäžé ã«ããã³ã³ãœãŒã«ã¢ã€ã³ã³ãèŠã€ããŸãã
ç·Žç¿ãã
ã³ã³ã¹ãã©ã¯ã¿ãŒã§ã³ã¬ã¯ã·ã§ã³ãšã¯ãšãªãäœæããŠãåé¡ã¯çºçããªãã¯ããªã®ã§ãã¹ã¯ãªããã®äœæã«å®çšçãªéšåãå²ããŠããã¹ãã§ã¯ãšãªãã§ãŒã³ãäœæããæ¹æ³ãæ€èšããŸãã éå§ããåã«ãæ°ããã³ã¬ã¯ã·ã§ã³ãäœæãããHabraããšããååãä»ãããHabra.Envããšããæ°ããç°å¢ãäœæããŸã
ã¹ããã1
æ°ãããªã¯ãšã¹ããäœæããURLãšããŠhttps://postman-echo.com/get?userId=777ãæå®ããGETã¡ãœããããã®ãŸãŸã«ããŸãã 以äžãç°¡åã«ããããã«ãPostmanéçºè ã芪åã«æäŸãããšã³ãŒãµãŒããŒã䜿çšããŸãã ãªã¯ãšã¹ãããHabraãã³ã¬ã¯ã·ã§ã³ã«ä¿åãããGet user idããšããååãä»ãããšããµãŒããŒããã®ãŠãŒã¶ãŒIDã®åä¿¡ãã·ãã¥ã¬ãŒãããŸãã [ãã¹ã]ã¿ãã«ç§»åããŠã次ã®ã³ãŒããèšè¿°ããŸãã
// pm.test("Status is ok, response is json", function () { pm.response.to.be.ok; // pm.response.to.be.json; // }); try { // userId json pm.environment.set("userId", pm.response.json().args.userId); } catch(e) { // console.log(e); }
ãã®ã¹ã¯ãªããã䜿çšããŠãå¿çã®ã¹ããŒã¿ã¹ãšåœ¢åŒã確èªããå¿çããåä¿¡ãããŠãŒã¶ãŒIDãç°å¢å€æ°ã«ä¿åããŠãåŸã§ä»ã®èŠæ±ã§äœ¿çšã§ããããã«ããŸããã ãã¹ãããã¹ãããã«ã¯ãã¯ãšãªãå®è¡ããŸãã å¿çæ å ±ããã«ã®[ãã¹ã]ã¿ãã«ãç·è²ã®ã©ãã« "PASS"ã衚瀺ããããã®æšªã« "Status is okãresponse is json"ãšããç¢æã衚瀺ãããŸãã
ã¹ããã2
ããã§ã¯ãjsonãªã¯ãšã¹ãã«ãŠãŒã¶ãŒIDãæ¿å ¥ããŠã¿ãŸãããã æ°ãããªã¯ãšã¹ããäœæããURLãšããŠhttps://postman-echo.com/postãæå®ããPOSTã¡ãœãããéžæãããªã¯ãšã¹ãæ¬æã®ã¿ã€ããraw-application / jsonã«èšå®ããæ¬æèªäœã«è²Œãä»ããŸãã
{"userId": {{userId}}, "username": "Bob"}
ãªã¯ãšã¹ããã³ã¬ã¯ã·ã§ã³ã«ä¿åããããŠãŒã¶ãŒåã®æŽæ°ããšããååãä»ãããšããŠãŒã¶ãŒã®ãŠãŒã¶ãŒåãæŽæ°ããããã«ç·æ¥ã®ãšã³ããã€ã³ããèŠæ±ãããŸãã çŸåšã{{userId}}ã®ä»£ããã«ãªã¯ãšã¹ããåŒã³åºããšãã·ã¹ãã ã¯ç°å¢å€æ°ã®å€ãèªåçã«çœ®ãæããŸãã ãããæ£ããããšã確èªããæ°ããã¯ãšãªã®å°ããªãã¹ããäœæããŸãããã
// pm.test("Status is ok, response is json", function () { pm.response.to.be.ok; pm.response.to.be.json; }); // , userId userId pm.test("userId from env is equal to userId from response", function () { pm.expect(parseInt(pm.environment.get("userId"))).to.equal( pm.response.json().data.userId ); });
æ°ãããã¹ãã§ã¯ããµãŒããŒããåä¿¡ããuserIdãç°å¢å€æ°ã«æ ŒçŽãããŠãããã®ãšæ¯èŒããŸãããããã¯äžèŽããå¿ èŠããããŸãã ã¯ãšãªãå®è¡ãããã¹ãã«åæ Œããããšã確èªããŸãã ã§ã¯ãå ã«é²ã¿ãŸãããã
ã¹ããã3
2ã€ã®ãã¹ãã¹ã¯ãªããã®åœ¢åŒãšã¹ããŒã¿ã¹ãã§ãã¯ãåãã§ããããšã«æ°ä»ããããããŸããã
pm.test("Status is ok, response is json", function () { pm.response.to.be.ok; pm.response.to.be.json; });
è¡ãéãããŸã§ããããä¿®æ£ãããããã®ãã¹ããã³ã¬ã¯ã·ã§ã³ã¬ãã«ã«è»¢éããŸãããã ã³ã¬ã¯ã·ã§ã³ã®ç·šéãéãã圢åŒãšã¹ããŒã¿ã¹ãã§ãã¯ã[ãã¹ã]ã¿ãã«è»¢éãããšããªã¯ãšã¹ãããããããåé€ã§ããŸãã ããã§ãã³ã¬ã¯ã·ã§ã³å ã®åãªã¯ãšã¹ãã®ããã¹ããã¹ã¯ãªããã®åã«ãããã®ãã§ãã¯ãèªåçã«åŒã³åºãããŸãã ãããã£ãŠããã®ãã§ãã¯ãåãªã¯ãšã¹ãã«ã³ããŒããå¿ èŠããªããªããŸããã
ã¹ããã4
ç°å¢å€æ°ãèšé²ããŠååŸããæ¹æ³ãåŠã³ãŸãããä»åºŠã¯ãã£ãšé£ããããšã«ç§»ããŸãããã tv4çµã¿èŸŒã¿ã©ã€ãã©ãªïŒTinyValidatorïŒã䜿çšããŠãjsonãªããžã§ã¯ãã¹ããŒããæ£ããããšã確èªããŠã¿ãŸãããã æ°ãããªã¯ãšã¹ããäœæãã httpsïŒ//postman-echo.com/postãURLãšããŠäœ¿çšããã¡ãœãããPOSTã«èšå®ãããªã¯ãšã¹ãæ¬æã«raw-application / jsonãæå®ããŠè²Œãä»ããŸãïŒ
{ "profile" : { "userId": {{userId}}, "username": "Bob", "scores": [1, 2, 3, 4, 5], "age": 21, "rating": {"min": 20, "max": 100} } }
èŠæ±ãéå§ããåŸããšã³ãŒãµãŒããŒã¯jsonã¢ãã«ã "data"ãã£ãŒã«ãã®åçãšããŠè¿ãå¿ èŠããããããããã®ãããã¡ã€ã«ã«é¢ããæ å ±ãéä¿¡ã§ããå®ãµãŒããŒã®åäœãã·ãã¥ã¬ãŒãããŸãã ã¢ãã«ã®æºåãã§ããããåè·¯ã®æ£ç¢ºæ§ããã§ãã¯ãããã¹ããäœæããŸãã
// var profile = pm.response.json().data.profile; // var scheme = { // "type": "object", // "required": ["userId", "username"], // "properties": { "userId": {"type": "integer"}, "username": {"type": "string"}, "age": {"type": "integer"}, // "scores": { "type": "array", // "items": {"type": "integer"} }, // "rating": { "type": "object", "properties": { "min": {"type": "integer"}, "max": {"type": "integer"} } } } }; pm.test('Schema is valid', function() { // profile scheme var isValidScheme = tv4.validate(profile, scheme, true, true); // , true pm.expect(isValidScheme).to.be.true; });
å®äºããããã¡ã€ã«ãªããžã§ã¯ãã¹ããŒããæ€èšŒããŸããã ã¯ãšãªãå®è¡ãããã¹ãã«åæ Œããããšã確èªããŸãã
ã¹ããã5
3ã€ã®ã¯ãšãªãšããã€ãã®ãã¹ãããæãåºããŸããã å®å šã«ãã¹ããããšããæ¥ãŸããã ããããã®åã«ãæåã®ãªã¯ãšã¹ãã«å°ãå€æŽãå ããŸããããURLã®ã777ãå€ããã¬ãŒã¹ãã«ããŒã{{newUserId}}ãã«çœ®ãæããã€ã³ã¿ãŒãã§ãŒã¹ãä»ããŠHabra.Envç°å¢ã«å€ã777ãã®ãnewUserIdãå€æ°ãè¿œå ããŸãã ã ã³ã³ãã¥ãŒã¿ãŒã«users.jsonãã¡ã€ã«ãäœæãã次ã®jsoné åãããã«é 眮ããŸãã
[ {"newUserId": 100}, {"newUserId": 200}, {"newUserId": 300}, {"newUserId": 50000} ]
ã©ã³ããŒãå®è¡ããŸãã ãã³ã¬ã¯ã·ã§ã³ãã©ã«ããã«ã¯ããHabraããéžæããŸãã ãç°å¢ãã«ã¯ãHabra.Envããé 眮ããŸãã å埩åæ°ã¯0ã§ãã[ããŒã¿]ãã£ãŒã«ãã§ãusers.jsonãã¡ã€ã«ãéžæããŸãã ãã®ãã¡ã€ã«ããããã³ã¬ã¯ã·ã§ã³ã©ã³ããŒãã¯4åã®å埩ãå®è¡ããå¿ èŠãããããšãç解ããåå埩ã§å€æ°ãnewUserIdãã®å€ããã¡ã€ã«å ã®é åã®å€ã§çœ®ãæããŸãã é åå ã®èŠçŽ ã®æ°ããã倧ããå埩åæ°ãæå®ãããšãããŒã¿é åã®æåŸã®å€ã§ä»¥éã®ãã¹ãŠã®å埩ãçºçããŸãã ãã®å Žåã4åã®å埩åŸããnewUserIdãã®å€ã¯åžžã«50000ã«ãªããŸãããããŒã¿ããã¡ã€ã«ã¯ãããŸããŸãªnewUserIdã䜿çšããŠããŠãŒã¶ãŒã«é¢ä¿ãªããã¹ãŠãå®å®ããããã«ããŸãã
ãRun Habraããã¯ãªãã¯ããŠãã¹ããå®è¡ããŸãã ããã§ãšãããããŸããã³ã¬ã¯ã·ã§ã³ã®äœæã«æåããèªåãã¹ãã®å©ããåããŠå³èã®æ¹æ³ããã¹ãããŸããïŒ
Habraã³ã¬ã¯ã·ã§ã³ã®ãã¹ã
ããã§ãã¹ã¯ãªããã®äœææ¹æ³ãããã£ãã®ã§ããããžã§ã¯ãã®ãã¹ããããã€ãäœæã§ããŸãã
ãããšã¯å¥ã«ãå®éã®ãããžã§ã¯ãã§ã¯ããã¹ãŠã®ãªã¯ãšã¹ããã³ã¬ã¯ã·ã§ã³ã®ã«ãŒãã«ä¿æããã®ã§ã¯ãªãããããããã©ã«ãã«é 眮ããããšããããšã«æ³šæããŠãã ããã ããšãã°ããRequestsããã©ã«ãã«ãAPIãèšè¿°ãããã¹ãŠã®å¯èœãªãªã¯ãšã¹ããè¿œå ãããã¹ããå¥ã®ãã©ã«ããTestsãã«ä¿åããŸãã ãããŠããããžã§ã¯ãããã¹ãããå¿ èŠãããå ŽåããRunnerãã§ãTestsããã©ã«ããŒã®ã¿ãèµ·åããŸãã
ç¥ã£ãŠãããã
çµè«ãšããŠãã¹ã¯ãªããã®äœæäžã«å¿ èŠã«ãªãå¯èœæ§ã®ããåºæ¬çãªã³ãã³ãã瀺ããŸãã ããè¯ãååã®ããã«ã圌ããšäžç·ã«éãã§ã¿ãŠãã ããã
å€æ°ã®èšå®ãšååŸ
// pm.globals.set(âkeyâ, âvalueâ); pm.globals.get(âkeyâ); // pm.environment.set(âkeyâ, âvalueâ); pm.environment.get(âkeyâ); // pm.variables.set(âkeyâ, âvalueâ); pm.variables.get(âkeyâ); // ,
ãã¹ããŸãã¯ã¢ãµãŒã
// assert pm.test(â â, function () { pm.response.to.be.success; pm.expect(âvalueâ).to.be.true; pm.expect(âotherâ).to.equal(âotherâ); }); // tests tests[â â] = (âaâ != âbâ); tests[â 2â] = true;
ã¯ãšãªãäœæãã
// get pm.sendRequest(âhttps://postman-echo.com/getâ, function (err, res) { console.log(err); console.log(res); }); // post let data = { url: âhttps://postman-echo.com/postâ, method: âPOSTâ, body: { mode: ârawâ, raw: JSON.stringify({ key: âvalueâ })} }; pm.sendRequest(data, function (err, res) { console.log(err); console.log(res); });
ã¡ã€ã³ãªã¯ãšã¹ãã«å¯Ÿããå¿çãååŸãã
pm.response.json(); // json pm.response.text(); // responseBody; //
çãã¯ããã¹ããã¿ãã§ã®ã¿å©çšå¯èœã§ã
çµã¿èŸŒã¿ã©ã€ãã©ãªã䜿çšãã
ããã¥ã¡ã³ãã¯ãjsonæ€èšŒçšã®tv4ãxml2js xmlããjsonãžã®ã³ã³ããŒã¿ãŒãæå·åçšã®crypto-jsãatobãbtoaãªã©ãå«ããå€æ°ã®çµã¿èŸŒã¿ã©ã€ãã©ãªã®ååšãèŠå¶ããŸãã
// xml2js var xml2js = require(âxml2jsâ); // xml json xml2js.parseString("<root>Hello xml2js!</root>", function(err, res) { console.log(res); });
ããšãã°ãtv4ãªã©ã®äžéšã®ã©ã€ãã©ãªã¯ãrequireãä»ããçŽæ¥æ¥ç¶ãå¿ èŠãšãããååã§ããã«äœ¿çšã§ããŸãã
çŸåšã®ã¹ã¯ãªããã«é¢ããæ å ±ãååŸãã
pm.info.eventName; // test prerequest pm.info.iteration; // Runner pm.info.iterationCount; // pm.info.requestName; // pm.info.requestId; //
ã¹ã¯ãªãããªã¯ãšã¹ãã·ãŒã±ã³ã¹ç®¡ç
ãã®æ¹æ³ã¯ããã¹ãŠã®ã¹ã¯ãªããã®å®è¡ã¢ãŒãã§ã®ã¿æ©èœããããšã«æ³šæããŠãã ããã
// postman.setNextRequest(â â); // postman.setNextRequest(ID); // // postman.setNextRequest(null);
次ã®èŠæ±ã«é²ãã åŸãPostmanã¯ç·åœ¢é 次ã¯ãšãªã®å®è¡ã«æ»ããŸãã
ã°ããŒãã«ãã«ããŒã®äœæ
å Žåã«ãã£ãŠã¯ããã¹ãŠã®ã¯ãšãªã§äœ¿çšã§ããé¢æ°ãäœæããããšãã§ããŸãã ãããè¡ãã«ã¯ããäºåèŠæ±ã¹ã¯ãªãããã»ã¯ã·ã§ã³ã®æåã®èŠæ±ã§ã次ã®ã³ãŒããèšè¿°ããŸãã
// pm.environment.set("pmHelper", function pmHelper() { let helpers = {}; helpers.usefulMethod = function() { console.log(âIt is helper, bro!â); }; return helpers; } + '; pmHelper();');
ãããŠã次ã®ã¹ã¯ãªããã§ã¯ã次ã®ããã«äœ¿çšããŸãã
// var pmHelper = eval(pm.environment.get("pmHelper")); // pmHelper.usefulMethod();
ããã¯äŸ¿å©ãªã³ãã³ãã®ã»ãã®å°ããªãªã¹ãã§ãã ã¹ã¯ãªããã®å¯èœæ§ã¯ã1ã€ã®èšäºã§ã«ããŒã§ããç¯å²ãã¯ããã«è¶ ããŠããŸãã Postmanã«ã¯ãæ°ããã³ã¬ã¯ã·ã§ã³ãäœæãããšãã«èŠã€ããããçŽ æµãªããã³ãã¬ãŒããããããŸãã ãããã®å®è£ ãã®ããèŠããŠå匷ããŠãã ããã ãŸããå ¬åŒããã¥ã¡ã³ãã«ã¯ãã»ãšãã©ã®è³ªåã«å¯Ÿããåçãå«ãŸããŠããŸãã
ãããã«
ãããžã§ã¯ãã§Postmanã䜿çšããããã«ãªã£ãäž»ãªå©ç¹ïŒ
- å¯èŠæ§-ãã¹ãŠã®ãªã¯ãšã¹ãã¯åžžã«æå ã«ãããéçºäžã®æåãã¹ãã容æã«ãªããŸã
- ã¯ã€ãã¯ã¹ã¿ãŒã-ããã°ã©ããŒã§ããããšãã¹ã¿ãŒã§ããããšãããŒã å ã®æ°ãããã¬ãŒã€ãŒããã°ããç°¡åã«åå ããã
- ãã¹ã-ã¯ãšãªã®ãã¹ããäœæããããºã«ãããŸããŸãªãªãã·ã§ã³ãã¢ããªã±ãŒã·ã§ã³ã©ã€ãã®æ¹æ³ãªã©ãããããããã°ããäœæããæ©èœ
- CIãµããŒã-newmanã䜿çšããŠCIã«ãã¹ããçµ±åããæ©èœïŒããã¯å¥ã®èšäºã«ãªããŸãïŒ
ãã€ãã¹ã«ã¯ïŒ
- ã³ã¬ã¯ã·ã§ã³ã®ç·šéã¯Postmanã«é¢é£ä»ããããŠããŸããã€ãŸãããããžã§ã¯ããªããžããªã«ã€ã³ããŒããç·šéãããã³ãšã¯ã¹ããŒãããå¿ èŠãããå€æŽã«ã€ããŠ
- ã³ã¬ã¯ã·ã§ã³ã¯1ã€ã®å€§ããªjsonãã¡ã€ã«ã«ãããããå€æŽã®ã¬ãã¥ãŒã¯ã»ãšãã©äžå¯èœã§ã
åãããžã§ã¯ãã«ã¯ããã¹ããšéçºã«é¢ããç¬èªã®ã¢ãããŒããšèŠè§£ããããŸãã ç§ãã¡ã¯çæãããé·æãèŠãã®ã§ããã®åŒ·åãªããŒã«ããã¹ããšãããžã§ã¯ãã®APIãªã¯ãšã¹ãã®èšè¿°ã®äž¡æ¹ã«äœ¿çšããããšã«ããŸããã ãããŠãç§ãã¡èªèº«ã®çµéšãããPostmanãæäŸãããã¹ãããŒã«ã䜿çšããªããŠããèŠæ±ã®èª¬æãã³ã¬ã¯ã·ã§ã³ã®åœ¢ã§æã£ãŠãããšéåžžã«åœ¹ç«ã€ãšèšããŸãã Postman Collectionsã¯ãAPIã®ã©ã€ãã®å¯Ÿè©±åããã¥ã¡ã³ãã§ãããå€ãã®æéãç¯çŽããéçºããããã°ãããã³ãã¹ããæã é«éåããŸãã
PSïŒ
Postmanã®äž»ãªæ©èœã¯ç¡æã§ãæ¯æ¥ã®ããŒãºãæºãããŠããŸãããç¡æçã«ã¯ããã€ãã®å¶éãããããŒã«ããããŸãã
- Postman API-ã¢ã«ãŠã³ãããŒã¿ã«ã¢ã¯ã»ã¹ããAPIãä»ããŠããã°ã©ã ãã³ã¬ã¯ã·ã§ã³ããªã¯ãšã¹ãããã®ä»ã®æ å ±ãçŽæ¥è¿œå ãåé€ãæŽæ°ã§ããŸãã 圌ã«æã«1000åé£çµ¡ããããšãã§ããŸãã
- ã¢ãã¯ãµãŒããŒ-APIã®ã¹ã¿ããPostmanéçºè ãµãŒããŒã«å±éã§ããŸãã 1ãæããã1000件ã®ãªã¯ãšã¹ããå¯èœã§ãã
- APIç£èŠ-Postmanéçºè ãµãŒããŒããã¹ã±ãžã¥ãŒã«ã«åŸã£ãŠç£èŠããã³å®è¡ããã³ã¬ã¯ã·ã§ã³ãäœæã§ããŸãã ç£èŠã·ã¹ãã ã¯ã1ãæããã1000件以äžã®ãªã¯ãšã¹ããè¡ããŸã
- Apiããã¥ã¡ã³ã-Postmanã¢ããªã±ãŒã·ã§ã³ã®ãµãŒããŒäžã§èªåçæãããããã¥ã¡ã³ããå ¬éã§ããŸãã 1ãæããã1,000åã®èŠèŽãå¶éãã