51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2206|回复: 0
打印 上一主题 下一主题

[讨论] SoapUI管理Cookie

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2018-6-22 16:15:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
SoapUI每次请求之后都会把Cookie清理掉,保持一个干净的运行环境,这导致测试有登陆的场景变得麻烦了.

处理SoapUI的Cookie,有好种方式

1,用脚本发送http+cookie

2,HTTP中手动加hearder

3,开发一个soapUI插件

4,替换soapUI源码,支持保持cookie



一,跟踪

找原因真的好麻烦,打不了断点嘛.

   1, jvisualvm 安装btrace插件,

  2,监控http执行栈,

  1. <p>[java] view plain copy</p><p>@OnMethod(clazz = "org.apache.http.impl.client.CloseableHttpClient", method = "execute" )  </p><p>public static void Trace_exit(){  </p><p>    println( "jstack() is :" );  </p><p>    println( "[" );  </p><p>    jstack();  </p><p>    println( "]" );  </p><p>}  </p><p>
  2. </p><p>
  3. </p><p>
  4. </p><p>
  5. </p><p>
  6. </p><p>
  7. </p><p>[java] view plain copy</p><p>org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java)  </p><p>org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)  </p><p>com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport$Helper.execute(HttpClientSupport.java:233)  </p><p>com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport.execute(HttpClientSupport.java:323)  </p><p>com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.submitRequest(HttpClientRequestTransport.java:295)  </p><p>com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:225)  </p><p>com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:119)  </p><p>java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)  </p>
复制代码



说起来简单,这可搞了几个小时

看来关键的还是以下这个类:

com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport

反编译以后找到一段神奇的代码:
  1. <p>
  2. </p><p>public static BasicHttpContext createEmptyContext() {</p><p>    BasicHttpContext httpContext = new BasicHttpContext();</p><p>    // BasicCookieStore cookieStore = new BasicCookieStore();</p><p>    // httpContext.setAttribute("http.cookie-store", cookieStore);</p><p>    return httpContext;</p><p>}</p>
复制代码


果然这个方法被它调用了:

com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport.sendRequest()

SoapUI原来是设计是对REST和SOAP优化的,不需要cookie,而且理论上每个http请求是独立的,所以清理cookie



现在用反编译出的class替换它就以了.

以下groovy脚本,可以用来验证cookie还存在,也可以用来清理cookie

  1. <p>
  2. </p><p>[java] view plain copy</p><p>import com.eviware.soapui.impl.wsdl.support.http.*;  </p><p>import org.apache.http.client.methods.HttpGet;  </p><p>import org.apache.http.client.CookieStore;  </p><p>   // ht.execute();  </p><p>    HttpGet get=new HttpGet("http://www.baidu.com");  </p><p>    HttpGet get2=new HttpGet("http://www.baidu.com");  </p><p>  //  CookieStore ck;  </p><p>  </p><p>        HttpClientSupport ht=new HttpClientSupport();  </p><p>  </p><p>        HttpClientSupport.getHttpClient().execute(get);  </p><p>        CookieStore ck= HttpClientSupport.getHttpClient().getCookieStore();  </p><p>  </p><p>     //   HttpClientSupport.getHttpClient().execute(get2);  </p><p>        CookieStore ck2= HttpClientSupport.getHttpClient().getCookieStore();  </p>
复制代码


清理脚本(没验证):
[java] view plain copy
HttpClientSupport.getHttpClient().setCookieStore(<span style="color: rgb(128, 128, 128); font-family:
Menlo; font-size: 12pt; background-color: rgb(43, 43, 43);">new BasicCookieStore());</span>  

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-24 16:15 , Processed in 0.063124 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表