Created
October 11, 2013 07:12
-
-
Save anonymous/6930747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/StarterMobile/" | |
val urlEcomm = "http://previewfr.dev.intuiko.lild01.pictime.fr/StarterEcommerce/" | |
val randomSkuProduct = csv("products.csv").random | |
val user = csv("users.csv").random | |
val product = csv("products.csv") | |
val log = LoggerFactory.getLogger(getClass()) | |
val scn = { | |
scenario("Manipulation client cart") | |
.exec(session => { | |
val user = csv("users.csv").random | |
val login = user.next()("login") | |
val mdp = user.next()("mdp") | |
log.debug(login) | |
log.debug(mdp) | |
session.setAttribute("login", login) | |
session.setAttribute("mdp", mdp) | |
}) | |
.exec( | |
http("1st connexion") | |
.post(urlEcomm + "secure/login.html") | |
.param("login", "${login}") | |
.param("password", "${mdp}") | |
.check(status.is(200))) | |
.pause(2000 milliseconds) | |
.repeat(3, "i") { | |
exec(session => { | |
val i = session.getTypedAttribute("i") | |
val record = product(i) | |
session.setAttributes(record) | |
}) | |
.exec( | |
http("add 3 random products in client cart") | |
.get(urlEcomm + "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 + "cart.html") | |
.queryParam("action", "updateQuantity") | |
.queryParam("skuId", "${skuid}") | |
.queryParam("quantity", "2") | |
.check(status.is(200)) | |
.check(headerRegex("Set-Cookie", ".nb=4.*"))) | |
.pause(100 milliseconds) | |
.exec( | |
http("get cart client") | |
.get(urlEcomm + "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 | |
}) | |
.exec( | |
http("1st deconnection") | |
.get(urlEcomm + "ajax/login.html") | |
.queryParam("logoutLayer", "1380812733150") | |
.check(status.is(200))) | |
.exec( | |
http("get cart client after deconnection") | |
.get(urlEcomm + "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 | |
}) | |
.exec( | |
http("1st connexion") | |
.post(urlEcomm + "secure/login.html") | |
.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 + "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 cart") | |
.get(urlEcomm + "cart.html") | |
.check(status.is(200)) | |
.check(headerRegex("Set-Cookie", ".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 | |
}) | |
.exec( | |
http("2nd deconnection") | |
.get(urlEcomm + "ajax/login.html") | |
.queryParam("logoutLayer", "1380812733150") | |
.check(status.is(200))) | |
.exec( | |
http("get cart client after deconnection") | |
.get(urlEcomm + "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 | |
}) | |
.exec( | |
http("mobile connexion") | |
.post(urlMobile + "secure/login.html") | |
.param("login", "${login}") | |
.param("password", "${mdp}") | |
.check(status.is(200))) | |
.pause(100 milliseconds) | |
.exec( | |
http("check cart") | |
.get(urlEcomm + "cart.html") | |
.check(status.is(200)) | |
.check(headerRegex("Set-Cookie", ".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("Mobile connection = " + cart.toString); session | |
}) | |
.exec( | |
http("mobile deconnection") | |
.get(urlMobile + "ajax/login.html") | |
.queryParam("logoutLayer", "1380812733150") | |
.check(status.is(200))) | |
.exec( | |
http("get cart client after deconnection") | |
.get(urlMobile + "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 | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment