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 override the response content in a JMeter WebDriver sampler test?

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

How do I parse a RestSharp response into a class?

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

How to do CDI/SE from Spock Test?

来自分类Dev

SoapUI/Groovy - 如何复制节点?

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

在SoapUI的Groovy中获取属性的值

来自分类Dev

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

来自分类Dev

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

来自分类Dev

在SoapUI Pro中使用groovy压缩目录

来自分类Dev

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

Related 相关文章

  1. 1

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

  2. 2

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

  3. 3

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

  4. 4

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

  5. 5

    How do I parse a RestSharp response into a class?

  6. 6

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

  7. 7

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

  8. 8

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

  9. 9

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

  10. 10

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

  11. 11

    How to do CDI/SE from Spock Test?

  12. 12

    SoapUI/Groovy - 如何复制节点?

  13. 13

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

  14. 14

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

  15. 15

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

  16. 16

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

  17. 17

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

  18. 18

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

  19. 19

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

  20. 20

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

  21. 21

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

  22. 22

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

  23. 23

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

  24. 24

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

  25. 25

    在SoapUI的Groovy中获取属性的值

  26. 26

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

  27. 27

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

  28. 28

    在SoapUI Pro中使用groovy压缩目录

  29. 29

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

热门标签

归档