当用户名和密码不正确时,为什么可以,但不是KO?

时间:2016-01-22 03:22:54

标签: scala gatling

我是gatling的新用户,我想测试一个Web应用程序的登录方案。我遇到下面的问题,我用错误的密码写scala脚本来测试登录场景,但是我发现最终的结果不是我预期的失败,发生了什么问题?

我的scala计划:

package cnblogsCase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class MueasSimulation extends Simulation{
  val httpConf = http.baseURL("http://localhost:8080")
  var scn = scenario("Search mueas home page")
          .exec(http("Redirect Login").get("/").check(currentLocation.saveAs("post_url")))
          .pause(10 seconds)
          .exec(http("Try login").post("${post_url}")
              .formParam("username", "shihuc")
              .formParam("password", "123456").check(status.is(200)))
          .pause(10 seconds)
  setUp(scn.inject(atOnceUsers(2)).protocols(httpConf))
}

而且,我的Web应用程序中登录的表单部分是这样的:

<form method="post" action="/login">  
        <input type="text" required="required" name="username" placeholder="ID or Email-address">
        <input type="password" required="required" name="password" placeholder="Password">
        <div class="remfog">
            <div class="rem">
                <label>
                    <input type="checkbox" name="remember-me" value="true" style="margin-top:10px">
                    Remember Me
                </label>
            </div>
            <div class="fog">
                <a title="Reset password" href="/password/forgot">Forgot Password?</a>
            </div>
        </div>
        <input class="csubmit" type="submit" value="Log in">    
    </form>

我的预期结果失败了,因为scala脚本中的用户名和密码不正确,但实际上,它是正常的,而不是KO。请查看log文件。我的加特林版本是2.1.7。

1 个答案:

答案 0 :(得分:1)

作为explained in the doc,如果您没有指定,则Gatling会自动添加对HTTP状态的检查。

检查日志后,您的应用程序将回复302 / Found并将位置重定向回登录页面。 这种行为是错误的。在这种情况下,HTTP响应应使用403/Forbidden status code

最佳解决方案是修复应用程序。 解决方法是在页面中添加对可能的错误消息的显式检查。