Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- rethinkdb
- nGrinder
- postgresql
- Jupyter Notebook
- kitura
- create table
- SWIFT
- 28015
- nohup
- insert
- Materials
- Jupyter
- centos
- ssh
- GoCD
- appium
- STF_PortForwarding
- openpyxl
- 실행권한
- nmap
- postgres
- appium server
- ubuntu
- perfect
- port forwarding
- mysql
- sshpass
- STF
- PYTHON
- ftp
Archives
- Today
- Total
don't stop believing
nGrinder에서 json 다루기 본문
nGrinder에서 json을 다룰때는 JSONObject을 사용합니다. Python의 기본 json 을 다루는 것과는 조금 다릅니다.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687-*- coding:utf-8 -*-# A simple example using the HTTP plugin that shows the retrieval of a# single page via HTTP.## This script is automatically generated by ngrinder.## @author adminfrom net.grinder.script.Grinder import grinderfrom net.grinder.script import Testfrom net.grinder.plugin.http import HTTPRequestfrom net.grinder.plugin.http import HTTPPluginControlfrom HTTPClient import NVPairfrom org.json import JSONObjectcontrol = HTTPPluginControl.getConnectionDefaults()# if you don't want that HTTPRequest follows the redirection, please modify the following option 0.# control.followRedirects = 1# if you want to increase the timeout, please modify the following option.control.timeout = 6000test1 = Test(1, "Test1")request1 = HTTPRequest()# Make any method call on request1 increase TPStest1.record(request1)class TestRunner:# initlialize a threaddef __init__(self):grinder.statistics.delayReports=Truepass# test methoddef __call__(self):result = request1.GET("http://google.com")message = """{"glossary": {"title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": {"ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","List": ["apple", "orange", "banana"],"Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": [{"para": "A meta-markup language, used to create markup languages such as DocBook."}, {"para": "Tests resulting in error only contribute to the Errors column."}, {"para": "registered plug-in net.grinder.plugin.http.HTTPPlugin"}],"GlossSee": "markup"}}}}}"""json_1 = JSONObject(message)json_2 = json_1.getJSONObject("glossary")json_3 = json_2.getJSONObject("GlossDiv")json_4 = json_3.getJSONObject("GlossList")json_5 = json_4.getJSONObject("GlossEntry")json_6 = json_5.getString("GlossTerm")json_7 = json_5.getString("List")json_8 = json_5.getJSONArray("GlossDef").getJSONObject(1).getString("para")print "----------> %s" % json_8for i in range(0, json_5.getJSONArray("GlossDef").length()) :print "para(%s)----------> %s" % (i, json_5.getJSONArray("GlossDef").getJSONObject(i).getString("para"))if result.getStatusCode() == 200 :grinder.statistics.forLastTest.success = 1elif result.getStatusCode() in (301, 302) :grinder.logger.warn("Warning. The response may not be correct. The response code was %d." % result.getStatusCode())grinder.statistics.forLastTest.success = 1else :grinder.statistics.forLastTest.success = 0
만약 nGrinder안에서 Python의 samplejson을 사용하고 싶다면 samplejson 모듈을 nGrinder에 추가하고 아래와 같이 사용하면 됩니다.
simplejson 모듈을 다운로드 하고 폴더와 파일들을 nGrinder의 lib 폴더로 복사하면 됩니다.
대량의 파일을 nGrinder에 올릴때는 nGrinder에서 제공하는 svn을 사용하면 편합니다.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586# -*- coding:utf-8 -*-# A simple example using the HTTP plugin that shows the retrieval of a# single page via HTTP.## This script is automatically generated by ngrinder.## @author adminfrom net.grinder.script.Grinder import grinderfrom net.grinder.script import Testfrom net.grinder.plugin.http import HTTPRequestfrom net.grinder.plugin.http import HTTPPluginControlfrom HTTPClient import NVPairimport simplejson as jsoncontrol = HTTPPluginControl.getConnectionDefaults()# if you don't want that HTTPRequest follows the redirection, please modify the following option 0.# control.followRedirects = 1# if you want to increase the timeout, please modify the following option.control.timeout = 6000test1 = Test(1, "Test1")request1 = HTTPRequest()# Make any method call on request1 increase TPStest1.record(request1)class TestRunner:# initlialize a threaddef __init__(self):grinder.statistics.delayReports=Truepass# test methoddef __call__(self):result = request1.GET("http://google.com")message = """{"glossary": {"title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": {"ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","List": ["apple", "orange", "banana"],"Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": [{"para": "A meta-markup language, used to create markup languages such as DocBook."}, {"para": "Tests resulting in error only contribute to the Errors column."}, {"para": "registered plug-in net.grinder.plugin.http.HTTPPlugin"}],"GlossSee": "markup"}}}}}"""find_text = json.loads(message)print find_text["glossary"]["title"]print find_text["glossary"]["GlossDiv"]["title"]print find_text["glossary"]["GlossDiv"]["GlossList"]["GlossEntry"]["ID"]print find_text["glossary"]["GlossDiv"]["GlossList"]["GlossEntry"]["SortAs"]print find_text["glossary"]["GlossDiv"]["GlossList"]["GlossEntry"]["GlossTerm"]print find_text["glossary"]["GlossDiv"]["GlossList"]["GlossEntry"]["List"][0]print find_text["glossary"]["GlossDiv"]["GlossList"]["GlossEntry"]["List"][1]print find_text["glossary"]["GlossDiv"]["GlossList"]["GlossEntry"]["List"][2]print find_text["glossary"]["GlossDiv"]["GlossList"]["GlossEntry"]["GlossDef"][0]["para"]print find_text["glossary"]["GlossDiv"]["GlossList"]["GlossEntry"]["GlossDef"][1]["para"]if result.getStatusCode() == 200 :grinder.statistics.forLastTest.success = 1elif result.getStatusCode() in (301, 302) :grinder.logger.warn("Warning. The response may not be correct. The response code was %d." % result.getStatusCode())grinder.statistics.forLastTest.success = 1else :grinder.statistics.forLastTest.success = 0
하지만 simplejson 모듈을 nGrinder에 업로드 하는것 보다 JSONObject를 익히는 게 더 편할 것 같습니다.
'Testing Automation > nGrinder' 카테고리의 다른 글
CentOS에 nGrinder 설치 하기 (v3.4) (0) | 2017.10.11 |
---|---|
nGrinder Controller 설정 (1) | 2017.09.19 |
Ubuntu에 nGrinder 설치 하기 (v3.4) (0) | 2017.09.05 |