테스트시 HTTPRequest 세션관련 문의

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

테스트시 HTTPRequest 세션관련 문의

choidaejung
안녕하세요.

nGrinder를 이용하여 테스트를 진행중인데 잘 안되는 부분이 있어서 문의 드립니다.

요점은 특정 URL을 호출을 할건데 기본적으로 로그인상태(세션에 데이터 생성 저장)만 접근이 가능한데
로그인 후 실제 테스트 URL 부분에서 미로그인상태(세션 정보가 없음)로 인하여 테스트가 안되고 있습니다.

################################################################
# 스크립트
################################################################
@RunWith(GrinderRunner)
class TestRunner {
        public static GTest test
        public static HTTPRequest request

        @BeforeProcess
        public static void beforeProcess() {
                HTTPPluginControl.getConnectionDefaults().timeout = 6000
                test = new GTest(1, "local.test.co.kr")
                request = new HTTPRequest()
                test.record(request);
                grinder.logger.info("before process.");
        }

        @BeforeThread
        public void beforeThread() {
                grinder.statistics.delayReports=true;

                NVPair[] queryData = new NVPair[3];
                queryData[0] = new NVPair("userId", "PMC_ADMIN2");
                queryData[1] = new NVPair("password", "1");
                queryData[2] = new NVPair("loginType", "MANUAL");

                HTTPResponse result = request.POST("http://localhost:8080/pmc/login/login/proc.easy", queryData);

                grinder.logger.info("result.getText() : " + result.getText());
                grinder.logger.info("before thread.");
        }

        @Test
        public void test(){
                HTTPResponse result = request.GET("http://localhost:8080/pmc/myPage/myPage/view.easy")

                if (result.statusCode == 301 || result.statusCode == 302) {
                        grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
                } else {
                        assertThat(result.statusCode, is(200));
                }
        }
}
################################################################

@BeforeThread  에서는 로그인이 정상적으로 처리 되었는데
@Test 에서는 세션정보가 아예 없는걸로 나오네요.

어떤 처리를 더 해줘야 하는건지좀 알려주세요.~~
Reply | Threaded
Open this post in threaded view
|

Re: 테스트시 HTTPRequest 세션관련 문의

junoyoon
Administrator

서버측에서 세션을 어떻게 유지하는지가 중요한데요
쿠키로 한다면 ngrinder가 자동으로 처리합니다

세션키를 별도로 파라미터로 받아 유지시킨다면 이후 test 구문에서 그걸 보내주셔야 합니다 

2015. 9. 17. 오전 11:03에 "choidaejung [via ngrinder]" <[hidden email]>님이 작성:
안녕하세요.

nGrinder를 이용하여 테스트를 진행중인데 잘 안되는 부분이 있어서 문의 드립니다.

요점은 특정 URL을 호출을 할건데 기본적으로 로그인상태(세션에 데이터 생성 저장)만 접근이 가능한데
로그인 후 실제 테스트 URL 부분에서 미로그인상태(세션 정보가 없음)로 인하여 테스트가 안되고 있습니다.

################################################################
# 스크립트
################################################################
@RunWith(GrinderRunner)
class TestRunner {
        public static GTest test
        public static HTTPRequest request

        @BeforeProcess
        public static void beforeProcess() {
                HTTPPluginControl.getConnectionDefaults().timeout = 6000
                test = new GTest(1, "local.test.co.kr")
                request = new HTTPRequest()
                test.record(request);
                grinder.logger.info("before process.");
        }

        @BeforeThread
        public void beforeThread() {
                grinder.statistics.delayReports=true;

                NVPair[] queryData = new NVPair[3];
                queryData[0] = new NVPair("userId", "PMC_ADMIN2");
                queryData[1] = new NVPair("password", "1");
                queryData[2] = new NVPair("loginType", "MANUAL");

                HTTPResponse result = request.POST("http://localhost:8080/pmc/login/login/proc.easy", queryData);

                grinder.logger.info("result.getText() : " + result.getText());
                grinder.logger.info("before thread.");
        }

        @Test
        public void test(){
                HTTPResponse result = request.GET("http://localhost:8080/pmc/myPage/myPage/view.easy")

                if (result.statusCode == 301 || result.statusCode == 302) {
                        grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
                } else {
                        assertThat(result.statusCode, is(200));
                }
        }
}
################################################################

@BeforeThread  에서는 로그인이 정상적으로 처리 되었는데
@Test 에서는 세션정보가 아예 없는걸로 나오네요.

어떤 처리를 더 해줘야 하는건지좀 알려주세요.~~


If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/HTTPRequest-tp1874.html
To start a new topic under ngrinder-user-kr, email [hidden email]
To unsubscribe from ngrinder-user-kr, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: 테스트시 HTTPRequest 세션관련 문의

choidaejung
로그인을 하면 서버에서는
HttpServletRequest.getSession 을 사용하여 그 곳에 데이터를 넣어놓고 사용을 하고있습니다.
Reply | Threaded
Open this post in threaded view
|

Re: 테스트시 HTTPRequest 세션관련 문의

junoyoon
Administrator

일단 beforethread 블록내에서 get 해보시고 여기서는 정상적으로 처리 되는지 확인해 보시겠어요?

2015. 9. 17. 오후 12:15에 "choidaejung [via ngrinder]" <[hidden email]>님이 작성:
로그인을 하면 서버에서는
HttpServletRequest.getSession 을 사용하여 그 곳에 데이터를 넣어놓고 사용을 하고있습니다.


If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/HTTPRequest-tp1874p1877.html
To start a new topic under ngrinder-user-kr, email [hidden email]
To unsubscribe from ngrinder-user-kr, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: 테스트시 HTTPRequest 세션관련 문의

choidaejung
오잉 같은 구문 안에서는 잘 되네요.
@BeforeThread  에서는 로그인 상태유지되네요

        @BeforeThread
        public void beforeThread() {
                NVPair[] queryData = new NVPair[3];
                queryData[0] = new NVPair("userId", "PMC_ADMIN2");
                queryData[1] = new NVPair("password", "1");
                queryData[2] = new NVPair("loginType", "MANUAL");

                HTTPResponse result = request.POST("http://localhost:8080/pmc/login/login/proc.easy", queryData);
                request.GET("http://localhost:8080/pmc/admin/serverConf/serverConf/view.easy");

                grinder.statistics.delayReports=true;
                grinder.logger.info("before thread.");
        }

        @Test
        public void test(){
                HTTPResponse result = request.GET("http://localhost:8080/pmc/admin/serverConf/serverConf/view.easy")

                if (result.statusCode == 301 || result.statusCode == 302) {
                        grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
                } else {
                        assertThat(result.statusCode, is(200));
                }
        }
Reply | Threaded
Open this post in threaded view
|

Re: 테스트시 HTTPRequest 세션관련 문의

junoyoon
Administrator

Requesr객체 생성과 record 를 beforethread 로 옮기세요 request 의 static,도 제거하시구요

2015. 9. 17. 오후 1:14에 "choidaejung [via ngrinder]" <[hidden email]>님이 작성:
오잉 같은 구문 안에서는 잘 되네요.
@BeforeThread  에서는 로그인 상태유지되네요

        @BeforeThread
        public void beforeThread() {
                NVPair[] queryData = new NVPair[3];
                queryData[0] = new NVPair("userId", "PMC_ADMIN2");
                queryData[1] = new NVPair("password", "1");
                queryData[2] = new NVPair("loginType", "MANUAL");

                HTTPResponse result = request.POST("http://localhost:8080/pmc/login/login/proc.easy", queryData);
                request.GET("http://localhost:8080/pmc/admin/serverConf/serverConf/view.easy");

                grinder.statistics.delayReports=true;
                grinder.logger.info("before thread.");
        }

        @Test
        public void test(){
                HTTPResponse result = request.GET("http://localhost:8080/pmc/admin/serverConf/serverConf/view.easy")

                if (result.statusCode == 301 || result.statusCode == 302) {
                        grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
                } else {
                        assertThat(result.statusCode, is(200));
                }
        }


If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/HTTPRequest-tp1874p1879.html
To start a new topic under ngrinder-user-kr, email [hidden email]
To unsubscribe from ngrinder-user-kr, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: 테스트시 HTTPRequest 세션관련 문의

choidaejung
코드를 아래와 같이 변경을 했더니 에러가 발생하네요.

###########################################################
# 스크립트
###########################################################
@RunWith(GrinderRunner)
class TestRunner {
        public static GTest test
        public HTTPRequest request

        @BeforeProcess
        public static void beforeProcess() {
                HTTPPluginControl.getConnectionDefaults().timeout = 6000
                test = new GTest(1, "local.test.co.kr")
                grinder.logger.info("before process.");
        }

        @BeforeThread
        public void beforeThread() {
                request = new HTTPRequest()
                test.record(request);

                NVPair[] queryData = new NVPair[3];
                queryData[0] = new NVPair("userId", "0984076");
                queryData[1] = new NVPair("password", "1");
                queryData[2] = new NVPair("loginType", "MANUAL");

                HTTPResponse result = request.POST("http://localhost:8080/pmc/login/login/proc.easy", queryData);

                grinder.statistics.delayReports=true;
                grinder.logger.info("before thread.");
        }

        /**
         * 사용자 페이지 테스트
         */
        @RunRate(50)
        @Test
        public void testUser(){
                HTTPResponse result = request.GET("http://localhost:8080/pmc/myPage/myPage/view.easy");

                if (result.statusCode == 301 || result.statusCode == 302) {
                        grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
                } else {
                        assertThat(result.statusCode, is(200));
                }
        }

        /**
         * 관리자 페이지 테스트
         */
        @RunRate(50)
        @Test
        public void testAdmin(){
                HTTPResponse result = request.GET("http://localhost:8080/pmc/admin/apaGrade/apaGrade/view.easy");

                if (result.statusCode == 301 || result.statusCode == 302) {
                        grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
                } else {
                        assertThat(result.statusCode, is(200));
                }
        }
}
###########################################################

###########################################################
# 에러메세지
###########################################################
2015-09-17 14:48:35,288 ERROR Aborting thread: {}Exception occurs in @BeforeThread block.
net.grinder.scriptengine.groovy.GroovyScriptEngine$GroovyScriptExecutionException: Exception occurs in @BeforeThread block.
        at net.grinder.scriptengine.groovy.GrinderContextExecutor.runBeforeThread(GrinderContextExecutor.java:116) ~[ngrinder-groovy-3.3.jar:na]
        at net.grinder.scriptengine.groovy.GroovyScriptEngine$GroovyWorkerRunnable.<init>(GroovyScriptEngine.java:142) ~[ngrinder-groovy-3.3.jar:na]
        at net.grinder.scriptengine.groovy.GroovyScriptEngine$GroovyWorkerRunnable.<init>(GroovyScriptEngine.java:102) ~[ngrinder-groovy-3.3.jar:na]
        at net.grinder.scriptengine.groovy.GroovyScriptEngine.createWorkerRunnable(GroovyScriptEngine.java:81) ~[ngrinder-groovy-3.3.jar:na]
        at net.grinder.engine.process.GrinderProcess$ThreadStarterImplementation$2.create(GrinderProcess.java:822) ~[ngrinder-runtime-3.3.jar:na]
        at net.grinder.engine.process.GrinderThread.run(GrinderThread.java:89) ~[grinder-core-3.9.1.jar:na]
        at java.lang.Thread.run(Thread.java:662) [na:1.6.0_43]
Caused by: java.lang.ExceptionInInitializerError: null
        at net.grinder.plugin.http.HTTPPlugin.<clinit>(HTTPPlugin.java:63) ~[grinder-http-3.9.1.jar:na]
        at net.grinder.plugin.http.HTTPRequest.<clinit>(HTTPRequest.java:103) ~[grinder-http-3.9.1.jar:na]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_43]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[na:1.6.0_43]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[na:1.6.0_43]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[na:1.6.0_43]
        at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77) ~[groovy-all-2.2.1.jar:2.2.1]
        at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102) ~[groovy-all-2.2.1.jar:2.2.1]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57) ~[groovy-all-2.2.1.jar:2.2.1]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182) ~[groovy-all-2.2.1.jar:2.2.1]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:186) ~[groovy-all-2.2.1.jar:2.2.1]
        at org.ngrinder.TestRunner.beforeThread(TestRunner.groovy:47) ~[na:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_43]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_43]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_43]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_43]
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) ~[junit-dep-4.8.2.jar:na]
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) ~[junit-dep-4.8.2.jar:na]
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) ~[junit-dep-4.8.2.jar:na]
        at net.grinder.scriptengine.groovy.junit.RunBeforeThreads.evaluate(RunBeforeThreads.java:60) ~[ngrinder-groovy-3.3.jar:na]
        at net.grinder.scriptengine.groovy.GrinderContextExecutor.runBeforeThread(GrinderContextExecutor.java:114) ~[ngrinder-groovy-3.3.jar:na]
        ... 6 common frames omitted
Caused by: net.grinder.engine.common.EngineException: An instance of the plug-in class 'net.grinder.plugin.http.HTTPPlugin' could not be initialised.
        at net.grinder.engine.process.PluginRegistryImplementation.register(PluginRegistryImplementation.java:91) ~[grinder-core-3.9.1.jar:na]
        at net.grinder.plugin.http.HTTPPlugin.<clinit>(HTTPPlugin.java:60) ~[grinder-http-3.9.1.jar:na]
        ... 26 common frames omitted
Caused by: net.grinder.plugininterface.PluginException: Could not register custom statistics
        at net.grinder.plugin.http.HTTPPlugin.initialize(HTTPPlugin.java:181) ~[grinder-http-3.9.1.jar:na]
        at net.grinder.engine.process.PluginRegistryImplementation.register(PluginRegistryImplementation.java:88) ~[grinder-core-3.9.1.jar:na]
        ... 27 common frames omitted
Caused by: net.grinder.script.InvalidContextException: registerDataLogExpression() is not supported from worker threads
        at net.grinder.engine.process.ScriptStatisticsImplementation.registerDataLogExpression(ScriptStatisticsImplementation.java:104) ~[grinder-core-3.9.1.jar:na]
        at net.grinder.plugin.http.HTTPPlugin.initialize(HTTPPlugin.java:127) ~[grinder-http-3.9.1.jar:na]
        ... 28 common frames omitted
###########################################################
Reply | Threaded
Open this post in threaded view
|

Re: 테스트시 HTTPRequest 세션관련 문의

Gisoo.Gwon
In reply to this post by choidaejung
You need inject cookie for login.

1. First define class member
Class TestRunner {
    ...
    public Object cookies = []


2. Login and save cookie
@BeforeThread
    ...
    request.POST("http://localhost:8080/pmc/login/login/proc.easy", queryData);
    cookies = CookieModule.listAllCookies(threadContext)


3. Inject cookie before request
@Before
    ...
    Object threadContext = HTTPPluginControl.getThreadHTTPClientContext()
    cookies.each {
        CookieModule.addCookie(it ,threadContext)
        grinder.logger.info("{}", it)
    }


4. Go test
Reply | Threaded
Open this post in threaded view
|

Re: 테스트시 HTTPRequest 세션관련 문의

choidaejung
감사합니다.
잘 동작 되네요. ^^