Skip to content

Instantly share code, notes, and snippets.

Created October 14, 2013 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6972223 to your computer and use it in GitHub Desktop.
Save anonymous/6972223 to your computer and use it in GitHub Desktop.
package com.intuiko.training.gatling.test
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.core.Predef.bootstrap._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import akka.util.duration._
import org.slf4j.LoggerFactory
object ClientCartScenario {
val urlMobile = "http://m.france.dev.intuiko.lild01.pictime.fr"
val urlEcomm = "http://previewfr.dev.intuiko.lild01.pictime.fr"
// val urlMobile = System.getProperty("baseUrlMobile")
// val urlEcomm = System.getProperty("baseUrlEcomm")
val randomSkuProduct = csv("products.csv").random
val product = csv("products.csv")
val log = LoggerFactory.getLogger(getClass())
val scn = {
scenario("Manipulation client cart")
.feed(csv("users.csv").random)
/////////////// FIRST CONNECTION ///////////////
.exec(
http("1st connexion")
.post(urlEcomm + "/StarterEcommerce/secure/login.html")
// .param("login", login)
// .param("password", mdp)
.param("login", "${login}")
.param("password", "${mdp}")
.check(status.is(200)))
.pause(2000 milliseconds)
.repeat(3, "i") {
exec(session => {
val i = session.getTypedAttribute[Int]("i")
val record = product(i)
session.setAttributes(record)
})
.exec(
http("add 3 products in client cart")
.get(urlEcomm + "/StarterEcommerce/cart.html")
.queryParam("action", "add")
.queryParam("skuId", "${skuid}")
.queryParam("quantity", "1")
.queryParam("parentId", "${parentid}")
.queryParam("modal", "true")
.queryParam("_", "137994812548")
.check(status.is(200)))
.pause(2000 milliseconds)
}
.feed(randomSkuProduct)
.exec(
http("update random quantity product in client cart")
.get(urlEcomm + "/StarterEcommerce/cart.html")
.queryParam("action", "updateQuantity")
.queryParam("skuId", "${skuid}")
.queryParam("quantity", "2")
.check(status.is(200))
.check(headerRegex("Set-Cookie", "cart=.*nb=4.*")))
.pause(100 milliseconds)
.exec(
http("get cart client")
.get(urlEcomm + "/StarterEcommerce/cart.html")
.check(status.is(200))
.check(header("Set-Cookie").saveAs("cart")))
.exec(session => {
import com.excilys.ebi.gatling.http.cookie._
import java.net.URI
val cart = session.getAttribute("cart")
log.debug("1st connection = " + cart.toString); session
})
/////////////// FIRST DECONNECTION ///////////////
.exec(
http("1st deconnection")
.get(urlEcomm + "/StarterEcommerce/ajax/login.html")
.queryParam("logoutLayer", "1380812733150")
.check(status.is(200)))
.exec(
http("get cart client after deconnection")
.get(urlEcomm + "/StarterEcommerce/cart.html")
.check(status.is(200))
.check(header("Set-Cookie").saveAs("cart")))
.exec(session => {
import com.excilys.ebi.gatling.http.cookie._
import java.net.URI
val cart = session.getAttribute("cart")
log.debug("After 1st deconnection = " + cart.toString); session
})
/////////////// MOBILE CONNECTION ///////////////
.exec(
http("mobile connexion")
.post(urlMobile + "/StarterMobile/secure/login.html")
// .param("login", login)
// .param("password", mdp)
.param("login", "${login}")
.param("password", "${mdp}")
.check(status.is(200)))
.pause(500 milliseconds)
.exec(
http("check client mobile cart")
.get(urlMobile + "/StarterMobile/cart.html")
.check(status.is(200))
.check(headerRegex("Set-Cookie", "cart=.*nb=5.*")))
.exec(
http("get client mobile cart")
.get(urlMobile + "/StarterMobile/cart.html")
.check(status.is(200))
.check(header("Set-Cookie").saveAs("cart")))
.exec(session => {
import com.excilys.ebi.gatling.http.cookie._
import java.net.URI
val cart = session.getAttribute("cart")
log.debug("Mobile connection = " + cart.toString); session
})
/////////////// MOBILE DECONNECTION ///////////////
.exec(
http("mobile deconnection")
.get(urlMobile + "/StarterMobile/ajax/login.html")
.queryParam("logoutLayer", "1380812733150")
.check(status.is(200)))
.exec(
http("get cart client after deconnection")
.get(urlMobile + "/StarterMobile/cart.html")
.check(status.is(200))
.check(header("Set-Cookie").saveAs("cart")))
.exec(session => {
import com.excilys.ebi.gatling.http.cookie._
import java.net.URI
val cart = session.getAttribute("cart")
log.debug("After mobile deconnection = " + cart.toString); session
})
/////////////// SECOND CONNECTION ///////////////
.exec(
http("2nd connexion")
.post(urlEcomm + "/StarterEcommerce/secure/login.html")
// .param("login", login)
// .param("password", mdp)
.param("login", "${login}")
.param("password", "${mdp}")
.check(status.is(200)))
.pause(2000 milliseconds)
.feed(randomSkuProduct)
.exec(
http("add a random products in client cart")
.get(urlEcomm + "/StarterEcommerce/cart.html")
.queryParam("action", "add")
.queryParam("skuId", "332")
.queryParam("quantity", "1")
.queryParam("parentId", "105")
.queryParam("modal", "true")
.queryParam("_", "1379948801309")
.check(status.is(200)))
.pause(2000 milliseconds)
.exec(
http("check client ecomm cart")
.get(urlEcomm + "/StarterEcommerce/cart.html")
.check(status.is(200))
//.check(headerRegex("Set-Cookie", "cart=.*l=1.nb=5.*"))
.check(header("Set-Cookie").saveAs("cart")))
.exec(session => {
import com.excilys.ebi.gatling.http.cookie._
import java.net.URI
val cart = session.getAttribute("cart")
log.debug("2nd connection & add random product = " + cart.toString); session
})
/////////////// SECOND DECONNECTION ///////////////
.exec(
http("2nd deconnection")
.get(urlEcomm + "/StarterEcommerce/ajax/login.html")
.queryParam("logoutLayer", "1380812733150")
.check(status.is(200)))
.exec(
http("get cart client after deconnection")
.get(urlEcomm + "/StarterEcommerce/cart.html")
.check(status.is(200))
.check(header("Set-Cookie").saveAs("cart")))
.exec(session => {
import com.excilys.ebi.gatling.http.cookie._
import java.net.URI
val cart = session.getAttribute("cart")
log.debug("After 2nd deconnection = " + cart.toString); session
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment