【问题标题】:jmeter authorization manager / loop countjmeter授权管理器/循环计数
【发布时间】:2016-02-03 14:09:42
【问题描述】:

我正在使用 JMeter 运行一些 Web 服务测试,这是我的问题:

  1. 这是我的测试结构:
> Threadgroup
>         -User Defined Variables
>         -SOAP/XML-RPC Request1
>            ->Xpath Extractor
>            ->Beanshell PostProcessor
>         -SOAP/XML-RPC Request2
>             ->HTTP Authorization manager
>             ->Beanshell PreProcessor
>         -Debug Sampler
>       View Results Tree
  1. Xpath Extractor 处理 Request1 结果以提取密码,而 Beanshell PostProcessor 将其存储在用户定义的变量“授权”中。

  2. Beanshell PreProcessor 从变量中提取密码,在授权管理器中使用用户设置。

AuthManager authmanager = sampler.getAuthManager();
Authorization authorization = new Authorization();
authorization.setURL("http://localhost:1130");
authorization.setUser("user"); 
authorization.setPass(vars.get("Authorization"));
authorization.setRealm("gSOAP Web Service");
authmanager.addAuth(authorization);

在我需要循环组线程之前,一切都运行良好。第一个循环工作正常,但其余的执行失败。似乎在第二轮授权管理器没有更新新的凭据,导致以下请求失败。

我尝试在创建新授权之前清除授权管理器,但它不起作用。

救命!!

【问题讨论】:

    标签: jmeter


    【解决方案1】:

    addAuth 方法(可以在code 中看到)只会在授权对象不存在时添加它。因此,在第二次添加对象之前,您必须将其删除,如下所示:

    AuthManager authmanager = sampler.getAuthManager();
    // ... (same as before)
    authorization.setRealm("gSOAP Web Service");
    for (int i = 0; i < authmanager.getAuthCount(); i++) {
            Authorization oldAuthorization = authmanager.get(i);
            if (oldAuthorization == null) {
                continue;
            }
            if (oldAuthorization.getURL().equals(authorization.getURL())) { 
                authmanager.remove(i);
            }
    }
    authmanager.addAuth(authorization);
    

    【讨论】:

    • 完美运行。感谢您的帮助。
    • @Claudia.A 很高兴它有帮助;那么你可以接受它:)
    猜你喜欢
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多