How do I get a Cookie from a SoapUI response using a Groovy test step?

djangofan

How do I get a Cookie from a SoapUI response using a Groovy test step?

I tried this Groovy code, but it's returning zero cookies (or null). This code is part of a test step that runs immediately after a standard REST request returns a result with the following header:

Set-Cookie: JSESSIONID=45C5E845A0C117E22D26DB04A64E5FD8; Path=/tcompany; HttpOnly

And the Groovy script I am using that fails to retrieve the Cookie is this:

import com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport
def myCookieStore = HttpClientSupport.getHttpClient().getCookieStore()
def myCookies = myCookieStore.getCookies()
def sessionCookie
//log.info("Test:" + myCookies.get(0).getValue() )
if ( myCookies.size() > 0 ) {
  myCookies.each {
    log.info( "Cookie: " + it.name )
    if( it.name == "JSESSIONID" ) {
    sessionCookie = it
    log.info("Found JSESSIONID cookie: " + it.value )
    }
  }
} else {
  log.info("No cookies found in cookie store.")
}
//assert myCookies[0].value().contains("JSESSIONID")
return sessionCookie

I found a HACK around the problem but this seems like its not the normal way to do it:

def val = testRunner.testCase.testSteps['REST Test Request 1'].testRequest.response.getResponseHeaders()
log.info("---- all headers -------")
val.each() { hdrs ->
    log.info hdrs
}
log.info("---- cookie jar contents -------")
def cjar = val.get("Set-Cookie")[0]
log.info ( "Cookie Jar: " + cjar )
def cookies = cjar.tokenize("\\;")
log.info("---- cookies -------")
cookies.each() { cookie ->
    log.info "Cookie: " + cookie
}
log.info("---- separated -------")
cookies.each() { cookie ->
    def pair = cookie.tokenize("\\=")
    log.info( "[- Key: " + pair[0] + ", Val: " + pair[1] + "-]" )
}
log.info("---- end -------")
SiKing

Your code looks fine to me. The only problem is that (I think!) the header should be "Cookie", as opposed to "Set-Cookie". This might help: http://siking.wordpress.com/2013/07/25/soapui-cookie-management/

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How do i call a controller action from within my view using Razor?

来自分类Dev

How do i unit test the auth filter in Laravel 4.1?

来自分类Dev

How do I inspect response headers in laravel 4 for unit testing?

来自分类Dev

如何使用Groovy测试步骤从SoapUI响应中获取Cookie?

来自分类Dev

JAX-RS How to get a cookie from a request?

来自分类Dev

How do I get the each method to work with multiple inputs using MagicSuggest?

来自分类Dev

How can I request an Image from a URL when the Response is 302?

来自分类Dev

How do I override the response content in a JMeter WebDriver sampler test?

来自分类Dev

在SoapUI的Groovy中获取属性的值

来自分类Dev

How do I unit test a function that loops over objects?

来自分类Dev

When using (substack's) Tape module for testing, how do I run only one test in a file?

来自分类Dev

How do I get `sbt test` to recognize my custom target?

来自分类Dev

How do I mock a method call inside the method I want to test using NUnit?

来自分类Dev

How do I use Jest to test a React view wired to store?

来自分类Dev

How do I get a value from an associative array using Swift

来自分类Dev

how do i pass the HTTP response from one activity to another activity in android

来自分类Dev

SOAPUI:修改请求:Groovy:appendNode适用的参数

来自分类Dev

How to do CDI/SE from Spock Test?

来自分类Dev

How do I get the System.Type of a static member using reflection?

来自分类Dev

How do I parse a RestSharp response into a class?

来自分类Dev

在SOAPUI中将参数从Java传递到Groovy

来自分类Dev

如何从soapui groovy脚本执行shell脚本?

来自分类Dev

How to get only value of sql query without header using groovy

来自分类Dev

使用Groovy在SoapUI中创建项目属性

来自分类Dev

在SoapUI Pro中使用groovy压缩目录

来自分类Dev

I want to get numeric data from string. How to do that in python?

来自分类Dev

如何从soapui groovy脚本执行shell脚本?

来自分类Dev

SoapUI/Groovy - 如何复制节点?

来自分类Dev

How do I get property value without knowing it's specific key in javascript using JSON

Related 相关文章

  1. 1

    How do i call a controller action from within my view using Razor?

  2. 2

    How do i unit test the auth filter in Laravel 4.1?

  3. 3

    How do I inspect response headers in laravel 4 for unit testing?

  4. 4

    如何使用Groovy测试步骤从SoapUI响应中获取Cookie?

  5. 5

    JAX-RS How to get a cookie from a request?

  6. 6

    How do I get the each method to work with multiple inputs using MagicSuggest?

  7. 7

    How can I request an Image from a URL when the Response is 302?

  8. 8

    How do I override the response content in a JMeter WebDriver sampler test?

  9. 9

    在SoapUI的Groovy中获取属性的值

  10. 10

    How do I unit test a function that loops over objects?

  11. 11

    When using (substack's) Tape module for testing, how do I run only one test in a file?

  12. 12

    How do I get `sbt test` to recognize my custom target?

  13. 13

    How do I mock a method call inside the method I want to test using NUnit?

  14. 14

    How do I use Jest to test a React view wired to store?

  15. 15

    How do I get a value from an associative array using Swift

  16. 16

    how do i pass the HTTP response from one activity to another activity in android

  17. 17

    SOAPUI:修改请求:Groovy:appendNode适用的参数

  18. 18

    How to do CDI/SE from Spock Test?

  19. 19

    How do I get the System.Type of a static member using reflection?

  20. 20

    How do I parse a RestSharp response into a class?

  21. 21

    在SOAPUI中将参数从Java传递到Groovy

  22. 22

    如何从soapui groovy脚本执行shell脚本?

  23. 23

    How to get only value of sql query without header using groovy

  24. 24

    使用Groovy在SoapUI中创建项目属性

  25. 25

    在SoapUI Pro中使用groovy压缩目录

  26. 26

    I want to get numeric data from string. How to do that in python?

  27. 27

    如何从soapui groovy脚本执行shell脚本?

  28. 28

    SoapUI/Groovy - 如何复制节点?

  29. 29

    How do I get property value without knowing it's specific key in javascript using JSON

热门标签

归档