如何确认Gatling是否实际加载了网页

时间:2015-01-27 15:44:04

标签: gatling

请原谅我是如此天真,但我很难检查/确认我的Gatling Script是否实际加载了我想要加载的页面。 我的环境: Windows 8.1(64位) Symantec Endpoint Protection 斯卡拉:2.11.4 加特林:2.0.3 Java:java版本" 1.7.0_72"       Java(TM)SE运行时环境(版本1.7.0_72-b14)       64位服务器VM(内置24.72-b04,混合模式)

在我的主机文件中输入后,我访问了客户端的QA网站。

我的脚本如下:

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class ClientBe extends Simulation{
  val httpProtocol = http
        .baseURL("CLIENT URL")
        .inferHtmlResources(BlackList(""".*\.js""", """.*\.css""", """.*\.gif""", """.*\.jpeg""", """.*\.jpg""", """.*\.ico""", """.*\.woff""", """.*\.(t|o)tf""", """.*\.png"""), WhiteList())
        .acceptHeader("""image/png,image/*;q=0.8,*/*;q=0.5""")
        .acceptEncodingHeader("""gzip, deflate""")
        .acceptLanguageHeader("""en-US,en;q=0.5""")
        .connection("""keep-alive""")
        .contentTypeHeader("""application/ocsp-request""")
        .userAgentHeader("""Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0""")

   val headers_0 = Map("""Accept""" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""")

    val headers_1 = Map("""Accept""" -> """*/*""")

    val headers_11 = Map(
        """Accept""" -> """*/*""",
        """If-Modified-Since""" -> """Thu, 27 Jan 2015 15:32:12 GMT""",
        """If-None-Match""" -> """W/"14228-1421335932000-gzip"""")

    val headers_14 = Map(
        """Accept""" -> """*/*""",
        """Cache-Control""" -> """no-cache""",
        """Pragma""" -> """no-cache""",
        """X-Requested-With""" -> """XMLHttpRequest""")

    val headers_17 = Map(
        """Accept""" -> """*/*""",
        """Cache-Control""" -> """no-cache""",
        """Content-Type""" -> """application/x-www-form-urlencoded; charset=UTF-8""",
        """Pragma""" -> """no-cache""",
        """X-Requested-With""" -> """XMLHttpRequest""")

    val uri04 = """ CLIENT URL """

    val scn = scenario("Loading home page")
        // Loading QA2 Site (French)
        .exec(http("Loading QA2 Site Home Page")
            .get("""/?language=fr&cmpid=""")
            .headers(headers_0)
            .check(status.is(session => 200))
            .check(regex("""Identifiez-vous""").exists))
        .pause(1)       
        .exec(http("LoggingIn")
            .post("""/loginnotmandatory""")
            .headers(headers_0)
            .formParam("""j_username""","""my email id""")
            .formParam("""j_password""",""" password """)
            .check(status.is(session => 200))
            .check(regex("""Bienvenue""").exists))
            //.check(css("""a""").is("""Bienvenue""")))
         .pause(3)   
         .exec(http("Navigate to Promotions")
            .get("""/fr-be/promotions""")
            .headers(headers_0)
            .check(status.is(session => 200))
            .check(regex("""Top Promotions""").exists))
        .pause(2)

        .exec(http("Logging Out")
            .get("""/?logout""")
            .headers(headers_0)
            .check(status.is(session => 200))
            .check(currentLocation.is("""CLIENT URL/?logout"""))
            .check(regex("""Identifiez-vous""").exists))

    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

我得到的错误是这样的: 正则表达式(Bienvenue).find(0)。存在,什么也没找到 regex(Top Promotions).find(0).exists,什么都没找到

非常感谢任何指导。

1 个答案:

答案 0 :(得分:0)

将一个extraInfoExtractor添加到httpProtocol以打印响应

 .extraInfoExtractor {
      extraInfo =>
        extraInfo.status match {
          case io.gatling.core.result.message.KO =>
            {
              println("Request : " + extraInfo)
              println("Response Body : " + extraInfo.response.body.string)
            }
            Nil
          case io.gatling.core.result.message.OK =>

            Nil
          case _ => Nil
        }
    }
相关问题