This post was updated on .
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest from HTTPClient import NVPair connectionDefaults = HTTPPluginControl.getConnectionDefaults() httpUtilities = HTTPPluginControl.getHTTPUtilities() # import file for parametrization # To use a proxy server, uncomment the next line and set the host and test = Test(3, "Dummy POST") requestPost = test.wrap(HTTPRequest(url=" http://58.181.37.172:8080")) class TestRunner: def __init__(self): print "Init" def __call__(self): url = '/login' params = [NVPair('login', 'admin'), NVPair('passwd', 'nabi!@#'), NVPair('Content-Type', 'application/x-www-form-urlencoded')] result = requestPost.POST(url, params) self.token_sessionId = \ httpUtilities.valueFromBodyURI('sessionId') self.token_role = \ httpUtilities.valueFromBodyURI('role') if result.statusCode == 200 : requestPost.POST("http://58.181.37.172:8080/equip_type_view.jsp",[NVPair("equip", "SGW"),NVPair("equip_num", "003") ]) writeToFile(result.text) def writeToFile(text): filename = "%s-page-%d.html" % (grinder.processName, grinder.runNumber) file = open(filename, "w") print >> file, text file.close() /////////////////////////////////////////////////////////////////////////////////////////// 안녕하세요. 초보사용자의 허접한 스크립트에 대해 질문드립니다. 제가 하려는 시나리오는 1.싸이트를 로그인후 2.로그인이 정상적으로 돼면 파라미터값을 URI주소로 넘겨서 화면 전환하기 입니다 하지만 위의대로 스크립트를 했는데 해당싸이트의 로그인조차 안돼고 있습니다... 어디가 틀렸는지 알려주시면 감사하겠습니더...로그인하는 예제문을 보여주시면 더 좋구요... 또 하나 로그인이 안돼어 2.번항목 테스트가 안돼는데 맞는지 부탁드리며 틀렷다면 지적해주시면 감사하겠습니다. |
안녕하세요.
스레드를 호출하기전 reset cookie 해준후. (init) cookie 값을 제 할당하는 방식으로 구현이 되어야 합니다. (call) 참고하실 만한 링크 보내 드립니다. https://github.com/naver/ngrinder/blob/master/script-sample/test-with-login/login.py 감사합니다. |
This post was updated on .
답변 감사합니다... (__)
# _*_ coding: utf8 _*_ from HTTPClient import NVPair, Cookie, CookieModule, CookiePolicyHandler from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest from net.grinder.script import Test from net.grinder.script.Grinder import grinder from java.util import Date # Set up a cookie handler to log all cookies that are sent and received. class MyCookiePolicyHandler(CookiePolicyHandler): def acceptCookie(self, cookie, request, response): return 1 def sendCookie(self, cookie, request): return 1 CookieModule.setCookiePolicyHandler(MyCookiePolicyHandler()) test1 = Test(1, "checkout home") request1 = test1.wrap(HTTPRequest(url="http://58.181.37.173:8080")) class TestRunner: def __init__(self): # Login URL request = HTTPRequest(url="http://58.181.37.173:8080/login") ##### reset to the all cookies ##### threadContext = HTTPPluginControl.getThreadHTTPClientContext() self.cookies = CookieModule.listAllCookies(threadContext) for c in self.cookies: CookieModule.removeCookie(c, threadContext) # do login resp = request.POST("http://58.181.37.173:8080/login", ( NVPair('userid', 'admin'), NVPair('userpw', '!@#$@'))); print '---------',resp.statusCode ##### save to the login info in cookies ##### self.cookies = CookieModule.listAllCookies(threadContext) def __call__(self): grinder.statistics.delayReports = 1 ##### Set to the cookies for login ##### threadContext = HTTPPluginControl.getThreadHTTPClientContext() for c in self.cookies: CookieModule.addCookie(c,threadContext) ##### Request with login ##### #### 메인페이지 이동 result = request1.GET("/integration/mainMonitor") #### 메인페이지 정상이동을 html 화면으로 저장후 확인 text = result.getText() if isinstance(text, unicode) : text = text.encode('utf-8') writeToFile(text) if result.text.count("only my content data") < 0: grinder.statistics.forLastTest.success = 0 else : grinder.statistics.forLastTest.success = 1 def writeToFile(text): filename = "%s-page-%d.html" % (grinder.processName, grinder.runNumber) file = open(filename, "w") print >> file, text file.close() ///////////////////////////////////////////////////////////////////////////////// 2016-07-27 16:48:18,195 INFO mobigen_nella-124 thread-0: http://58.181.37.173:8080/login -> 200 OK, 10036 bytes 2016-07-27 16:48:18,195 INFO mobigen_nella-124 thread-0: starting, will do 5 runs 2016-07-27 16:48:18,195 INFO mobigen_nella-124 : start time is 1469605698203 ms since Epoch 2016-07-27 16:48:18,257 INFO mobigen_nella-124 thread-0 [ run-0, test-1 ]: http://58.181.37.173:8080/integration/mainMonitor -> 302 Found, 0 bytes [Redirect, ensure the next URL is http://58.181.37.173:8080/login] 2016-07-27 16:48:18,289 INFO mobigen_nella-124 thread-0 [ run-1, test-1 ]: http://58.181.37.173:8080/integration/mainMonitor -> 302 Found, 0 bytes [Redirect, ensure the next URL is http://58.181.37.173:8080/login] 2016-07-27 16:48:18,320 INFO mobigen_nella-124 thread-0 [ run-2, test-1 ]: http://58.181.37.173:8080/integration/mainMonitor -> 302 Found, 0 bytes [Redirect, ensure the next URL is http://58.181.37.173:8080/login] 2016-07-27 16:48:18,351 INFO mobigen_nella-124 thread-0 [ run-3, test-1 ]: http://58.181.37.173:8080/integration/mainMonitor -> 302 Found, 0 bytes [Redirect, ensure the next URL is http://58.181.37.173:8080/login] 2016-07-27 16:48:18,367 INFO mobigen_nella-124 thread-0 [ run-4, test-1 ]: http://58.181.37.173:8080/integration/mainMonitor -> 302 Found, 0 bytes [Redirect, ensure the next URL is http://58.181.37.173:8080/login] 2016-07-27 16:48:18,367 INFO mobigen_nella-124 thread-0: finished 5 runs 2016-07-27 16:48:18,383 INFO mobigen_nella-124 : elapsed time is 182 ms //////////////////// resp = request.POST("http://58.181.37.173:8080/login", ( NVPair('userid', 'admin'), NVPair('userpw', '!@#$@'))); 로그인하는부분에서 파라미터와 파라미터정의값이 다르게 했는데도 response 리턴값은 200이 떨어집니다... 왜 그런지 모르겠습니다 알려주시면 감사합니다 (__) |
안녕하세요.
테스트한 코드에서 wrap은 이전버전에서 사용되던 방식 입니다. record 방식으로 개선 하시면 좋을거 같아요. 추가적으로 redirect 설정을 주시면 좋을거 같아요. HTTPPluginControl.followRedirects = True 네이버 로그인 테스트 하신다 하셔서 테스트한 코드 드립니다. 참고하시길 바랍니다. ``` # _*_ coding: utf8 _*_ from HTTPClient import NVPair, Cookie, CookieModule, CookiePolicyHandler from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest from net.grinder.script import Test from net.grinder.script.Grinder import grinder from java.util import Date # Set up a cookie handler to log all cookies that are sent and received. class MyCookiePolicyHandler(CookiePolicyHandler): def acceptCookie(self, cookie, request, response): return 1 def sendCookie(self, cookie, request): return 1 CookieModule.setCookiePolicyHandler(MyCookiePolicyHandler()) test1 = Test(1, "checkout home") request1 = HTTPRequest(url="http://www.naver.com") test1.record(request1) # HTTPPluginControl.followRedirects = True class TestRunner: def __init__(self): # Login URL request1 = HTTPRequest(url="https://www.naver.com") ##### reset to the all cookies ##### threadContext = HTTPPluginControl.getThreadHTTPClientContext() self.cookies = CookieModule.listAllCookies(threadContext) for c in self.cookies: CookieModule.removeCookie(c, threadContext) # do login result = request1.POST("https://nid.naver.com/nidlogin.login", ( NVPair("id", "userid"),NVPair("pw", "userpw"))); grinder.logger.warn("%d." % result.getStatusCode()) ##### save to the login info in cookies ##### self.cookies = CookieModule.listAllCookies(threadContext) def __call__(self): grinder.statistics.delayReports = 1 ##### Set to the cookies for login ##### threadContext = HTTPPluginControl.getThreadHTTPClientContext() for c in self.cookies: CookieModule.addCookie(c,threadContext) ##### Request with login ##### result = request1.GET("http://www.naver.com") if result.text.count("only my content data") < 0: grinder.statistics.forLastTest.success = 0 else : grinder.statistics.forLastTest.success = 1 ``` |
This post was updated on .
답변 주셔서 정말 감사합니다 ㅠ _ㅜ
위의 테스트예제를 그대로 돌려도 로그인쿠키를 못받아 오는거 같습니다 ㅠ post방식에 파라미터값을 정상적으로 주든 비정상적으로 주든 result = request1.POST("https://nid.naver.com/nidlogin.login", ( NVPair("id", "userid"),NVPair("pw", "userpw"))); 여기의 result .statusCode값은 200으로 줄뿐... ( post방식으로 해당 uri에 파라미터정보를 잘못 전달했는데 왜 200 으로 주는지 의문입니다 ) 정작 로그인은 안돼어서 정상적인쿠키값을 못받아와서 result = request1.GET("http://section.cafe.naver.com/") 사용자의 카페에 접근을 못합니다 grinder에서의 로그인이 안돼니 답답하네요... 다른 로그인을 하는 소스나 답변 부탁드립니다 # _*_ coding: utf8 _*_ from HTTPClient import NVPair, Cookie, CookieModule, CookiePolicyHandler from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest from net.grinder.script import Test from net.grinder.script.Grinder import grinder from java.util import Date # Set up a cookie handler to log all cookies that are sent and received. class MyCookiePolicyHandler(CookiePolicyHandler): def acceptCookie(self, cookie, request, response): return 1 def sendCookie(self, cookie, request): return 1 CookieModule.setCookiePolicyHandler(MyCookiePolicyHandler()) test1 = Test(1, "checkout home") request1 = HTTPRequest(url="http://www.naver.com") test1.record(request1) HTTPPluginControl.followRedirects = True ## 주석 해제 followRedirects True class TestRunner: def __init__(self): # Login URL request1 = HTTPRequest(url="https://www.naver.com") ##### reset to the all cookies ##### threadContext = HTTPPluginControl.getThreadHTTPClientContext() self.cookies = CookieModule.listAllCookies(threadContext) for c in self.cookies: CookieModule.removeCookie(c, threadContext) # do login result = request1.POST("https://nid.naver.com/nidlogin.login", ( NVPair("id", "userid"),NVPair("pw", "userpw"))); grinder.logger.warn("%d." % result.getStatusCode()) ##### save to the login info in cookies ##### self.cookies = CookieModule.listAllCookies(threadContext) def __call__(self): grinder.statistics.delayReports = 1 ##### Set to the cookies for login ##### threadContext = HTTPPluginControl.getThreadHTTPClientContext() for c in self.cookies: CookieModule.addCookie(c,threadContext) ##### Request with login ##### result = request1.GET("http://section.cafe.naver.com/") if result.text.count("only my content data") < 0: grinder.statistics.forLastTest.success = 0 else : grinder.statistics.forLastTest.success = 1 |
In reply to this post by songeunwoo
안녕하세요.
올려주신 소스로 테스트 해보니 전 정상적으로 로그인 되는걸 확인했습니다. 로그인시 잘못된 계정 정보를 넘겨줘도 리턴되는 값이 에어가 이니기에 200코드가 리턴 되는건 정상입니다. 질문하신 분의 아이디나 비밀번호가 틀리진 않았는지 다시 한번 확인해 보시길 바랄게요. |
안녕하세요 빠른 답변 감사합니다 ( __) 로그인이 잘 돼었는지 어떻게 확인했는지 모르겠지만 전 안돼어서 제 id와 pw가 담긴 소스코드를 여기 메일에 보내드릴게요.. 확인좀 부탁합니다 소스는 로그인후 개인메일함으로 가는 것인데, 실행을 하면 로그인을 하라는 Redirect문구와 함께 302found가 발생합니다 다시 한번 확인부탁드리며, 신경 써주셔서 감사합니다 //////////////////////////////////////// 2016-07-29 11:54:54,067 INFO mobigen_nella-32 : The Grinder version 3.11 2016-07-29 11:54:54,067 INFO mobigen_nella-32 : Java(TM) SE Runtime Environment 1.6.0_45-b06: Java HotSpot(TM) 64-Bit Server VM (20.45-b01, mixed mode) on Windows 8 amd64 6.2 2016-07-29 11:54:54,067 INFO mobigen_nella-32 : time zone is KST (+0900) 2016-07-29 11:54:54,145 INFO mobigen_nella-32 : worker process 32 of agent number 0 2016-07-29 11:54:54,192 INFO mobigen_nella-32 : instrumentation agents: byte code transforming instrumenter for Jython 2.5; byte code transforming instrumenter for Java 2016-07-29 11:54:56,114 INFO mobigen_nella-32 : registered plug-in net.grinder.plugin.http.HTTPPlugin 2016-07-29 11:54:56,192 INFO mobigen_nella-32 : running "login13.py" using Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:54:35) [Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] 2016-07-29 11:54:56,416 INFO mobigen_nella-32 thread-0: https://nid.naver.com/nidlogin.login -> 200 OK, 16600 bytes 2016-07-29 11:54:56,432 WARN mobigen_nella-32 thread-0: 200. 2016-07-29 11:54:56,432 INFO mobigen_nella-32 thread-0: starting, will do 5 runs 2016-07-29 11:54:56,432 INFO mobigen_nella-32 : start time is 1469760896430 ms since Epoch 2016-07-29 11:54:56,541 INFO mobigen_nella-32 thread-0 [ run-0, test-1 ]: https://mail.naver.com/?n=1469760062071&v=f -> 302 Found, 0 bytes [Redirect, ensure the next URL is https://mail.naver.com/login?url=https%3A%2F%2Fmail.naver.com%2F%3Fn%3D1469760062071%26v%3Df] 2016-07-29 11:54:56,635 INFO mobigen_nella-32 thread-0 [ run-1, test-1 ]: https://mail.naver.com/?n=1469760062071&v=f -> 302 Found, 0 bytes [Redirect, ensure the next URL is https://mail.naver.com/login?url=https%3A%2F%2Fmail.naver.com%2F%3Fn%3D1469760062071%26v%3Df] 2016-07-29 11:54:56,807 INFO mobigen_nella-32 thread-0 [ run-2, test-1 ]: https://mail.naver.com/?n=1469760062071&v=f -> 302 Found, 0 bytes [Redirect, ensure the next URL is https://mail.naver.com/login?url=https%3A%2F%2Fmail.naver.com%2F%3Fn%3D1469760062071%26v%3Df] 2016-07-29 11:54:56,900 INFO mobigen_nella-32 thread-0 [ run-3, test-1 ]: https://mail.naver.com/?n=1469760062071&v=f -> 302 Found, 0 bytes [Redirect, ensure the next URL is https://mail.naver.com/login?url=https%3A%2F%2Fmail.naver.com%2F%3Fn%3D1469760062071%26v%3Df] 2016-07-29 11:54:56,979 INFO mobigen_nella-32 thread-0 [ run-4, test-1 ]: https://mail.naver.com/?n=1469760062071&v=f -> 302 Found, 0 bytes [Redirect, ensure the next URL is https://mail.naver.com/login?url=https%3A%2F%2Fmail.naver.com%2F%3Fn%3D1469760062071%26v%3Df] 2016-07-29 11:54:56,979 INFO mobigen_nella-32 thread-0: finished 5 runs 2016-07-29 11:54:56,994 INFO mobigen_nella-32 : elapsed time is 555 ms 2016-07-29 11:54:56,994 INFO mobigen_nella-32 : Final statistics for this process: 2016-07-29 11:54:56,994 INFO mobigen_nella-32 : Tests Errors Mean Test Test Time TPS Mean Response Response Mean time to Mean time to Mean time to Time (ms) Standard response bytes per errors resolve host establish first byte Deviation length second connection (ms) Test 1 5 0 106.40 27.58 9.01 0.00 0.00 0 0.00 15.80 105.60 "checkout home" Totals 5 0 106.40 27.58 9.01 0.00 0.00 0 0.00 15.80 105.60 Tests resulting in error only contribute to the Errors column. Statistics for individual tests can be found in the data file, including (possibly incomplete) statistics for erroneous tests. Composite tests are marked with () and not included in the totals. |
안녕하세요.
여전히 해결이 안되셨다니. 답답 하사겠어요.. 보내주신 소스로 테스트를 진행 해 보면 아래와 같이 로그가 나오는게 확인이 됩니다. 간단한 로그인 테스트를 진행 하는 방법은 스크립트 작성 페이지에서 스크립트 검증 버튼을 클릭하여 진행 하시면 편하실 거에요. grinder.logger.warn(" response content : %s." % result.getText()) 위 코드로 확인을 해보면 질문자님이 호출 하신 페이지의 소스 보기 상태와 html코드가 같은지 육안으로 확인이 가능 합니다. 특정 아이디나 이름 로그인 상태를 나타내는 코드가 있는지 확인해 보면 되겠죠? 원하시는 테스트 성공하시길 바랍니다. 2016-07-29 12:29:31,908 INFO https://mail.naver.com/?n=1469760062071&v=f -> 200 OK, 315513 bytes 2016-07-29 12:29:32,045 INFO https://mail.naver.com/?n=1469760062071&v=f -> 200 OK, 315513 bytes 2016-07-29 12:29:32,183 INFO https://mail.naver.com/?n=1469760062071&v=f -> 200 OK, 315513 bytes 2016-07-29 12:29:32,309 INFO https://mail.naver.com/?n=1469760062071&v=f -> 200 OK, 315513 bytes 2016-07-29 12:29:32,463 INFO https://mail.naver.com/?n=1469760062071&v=f -> 200 OK, 315513 bytes 2016-07-29 12:29:32,603 INFO https://mail.naver.com/?n=1469760062071&v=f -> 200 OK, 315513 bytes 2016-07-29 12:29:32,732 INFO https://mail.naver.com/?n=1469760062071&v=f -> 200 OK, 315513 bytes 2016-07-29 12:29:32,914 INFO received a stop message 2016-07-29 12:29:33,067 INFO https://mail.naver.com/?n=1469760062071&v=f -> 200 OK, 315513 bytes 2016-07-29 12:29:33,077 INFO shut down 2016-07-29 12:29:33,077 INFO finished 112 runs 2016-07-29 12:29:33,081 INFO elapsed time is 17758 ms 2016-07-29 12:29:33,081 INFO Final statistics for this process: 2016-07-29 12:29:33,091 INFO Tests Errors Mean Test Test Time TPS Mean Response Response Mean time to Mean time to Mean time to Time (ms) Standard response bytes per errors resolve host establish first byte Deviation length second connection (ms) Test 1 112 0 137.59 32.32 6.31 315513.00 1989945.71 0 0.19 3.30 111.84 "checkout home" Totals 112 0 137.59 32.32 6.31 315513.00 1989945.71 0 0.19 3.30 111.84 Tests resulting in error only contribute to the Errors column. Statistics for individual tests can be found in the data file, including (possibly incomplete) statistics for erroneous tests. Composite tests are marked with () and not included in the totals. |
Free forum by Nabble | Edit this page |