-
-
Save anonymous/cb09e9a94deafd5d44a8 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 devis.chains | |
import com.excilys.ebi.gatling.core.Predef._ | |
import com.excilys.ebi.gatling.http.Predef._ | |
import utils.ExtractUtils._ | |
import utils.SessionUtils.getAttributeOrElse | |
import com.excilys.ebi.gatling.core.Predef.Session | |
import utils.DateUtils._ | |
import com.excilys.ebi.gatling.http.check.HttpCheck | |
object Modification { | |
val fields = ({ | |
var map = scala.collection.mutable.Map[String,String]( | |
"csrf" -> "form[_csrf_token]"//hidden | |
) | |
var i: Int = 1 | |
for (conducteur <- List("principal", "secondaire")) { | |
map ++= scala.collection.mutable.Map[String,String]( | |
("nbMoisAssurance|"+i, "form[conducteur_"+conducteur+"][nb_mois_assurance]"), //hidden | |
("dejaAssure|"+i, "form[conducteur_"+conducteur+"][deja_assure]") //radio | |
) | |
for(j <- 0 to 3 ) { | |
map += "date|" + i + "_" + j -> getDateAntecedentParameterName(j, conducteur) | |
} | |
map ++= scala.collection.mutable.Map[String,String]( | |
("nbMoisAssuranceDisplay|"+i, "form[conducteur_"+conducteur+"][nb_mois_assurance_display]"), //input | |
("crm|"+i, "form[conducteur_"+conducteur+"][dernier_crm]"), //select | |
("dateCRM|"+i, "form[conducteur_"+conducteur+"][date_acquisition][date]"),//input | |
("nbAnneeCRM|"+i, "form[conducteur_"+conducteur+"][nb_annee_crm]"),//input | |
("nonPaiement|"+i, "form[conducteur_"+conducteur+"][A1]"),//radio | |
("resiliationSinistre|"+i, "form[conducteur_"+conducteur+"][R1]"),//radio | |
("resiliationFaux|"+i, "form[conducteur_"+conducteur+"][A2]"),//radio | |
("infractions|"+i, "form[conducteur_"+conducteur+"][objet_infraction]"),//radio | |
("sinistres|"+i, "form[conducteur_"+conducteur+"][avec_sinistre]")//radio | |
) | |
i += 1 | |
} | |
map | |
}) | |
val chn = bootstrap | |
.exec({ | |
var builder = http("GET form").get("""${next}""") | |
var checks = List[HttpCheck[_]]() | |
checks ::= status.is(200) | |
checks ::= extractInputValue(fields("csrf")) | |
//si possible ne pas du tout extraire les valeurs si le 2nd conducteur n'est pas déclaré | |
for(i <- 1 to 2) { | |
checks ::= extractInputValue(fields("nbMoisAssurance|"+i)) | |
checks ::= extractRadioValue(fields("dejaAssure|"+i)) | |
for(j <- 0 to 3) { | |
val fieldName = fields("date|" + i + "_" + j) | |
//on sauvegarde dans la session avec un nom unique | |
checks ::= extractCheckboxMultipleValue(fieldName) | |
} | |
checks ::= extractInputValue(fields("nbMoisAssuranceDisplay|"+i)) | |
checks ::= extractSelectValue(fields("crm|"+i)) | |
checks ::= extractInputValue(fields("dateCRM|"+i)) | |
checks ::= extractInputValue(fields("nbAnneeCRM|"+i)) | |
checks ::= extractRadioValue(fields("nonPaiement|"+i)) | |
checks ::= extractRadioValue(fields("resiliationSinistre|"+i)) | |
checks ::= extractRadioValue(fields("resiliationFaux|"+i)) | |
checks ::= extractRadioValue(fields("infractions|"+i)) | |
checks ::= extractRadioValue(fields("sinistres|"+i)) | |
} | |
builder.check(checks: _*) | |
}) | |
.exec((s: Session) => { | |
var session = s | |
//on compte les antécedents d'assurance comme fait en javascript | |
var moisAssuranceConducteur1 = 0; | |
var moisAssuranceConducteur2 = 0; | |
for ((alias, fieldName) <- fields) { | |
var value: Any = Nil | |
if (alias.contains("date|1")) { | |
var value: Seq[String] = getAttributeOrElse(s, fieldName, List()).asInstanceOf[Seq[String]] | |
moisAssuranceConducteur1 += value.length | |
} | |
else if (alias.contains("date|2")) { | |
var value: Seq[String] = getAttributeOrElse(s, fieldName, List()).asInstanceOf[Seq[String]] | |
moisAssuranceConducteur2 += value.length | |
} | |
else { | |
var value: String = getAttributeOrElse(s, fieldName, "").asInstanceOf[String] | |
session = session.setAttribute(fieldName, value) | |
} | |
} | |
session = session.setAttribute(fields("nbMoisAssurance|1"), moisAssuranceConducteur1) | |
session = session.setAttribute(fields("nbMoisAssurance|2"), moisAssuranceConducteur2) | |
session | |
}) | |
.exec(session => { | |
// print the Session for debugging, don't do that on real Simulations | |
println(session) | |
session | |
}) | |
.exec({ | |
var builder = http("POST form 1").post("""${next}""") | |
for ((alias, fieldName) <- fields) { | |
if (alias.contains("|2").equals(false)) | |
{ | |
var sessionName = fieldName | |
if (alias.contains("date|")) { | |
println("building scenario with multiValuedParam for session value " + sessionName) | |
builder = (1 to 11).foldLeft(builder) { (cur, i) => cur.param(fieldName, "${"+sessionName+"("+i+")}")} | |
} | |
else { | |
builder = builder.param(fieldName, """${"""+sessionName+"""}""") | |
} | |
} | |
} | |
builder | |
.param("action", """next""") | |
.check( | |
status.is(302), | |
header("Location").saveAs("next"), | |
headerRegex("Location", """url/toMatch\?ns=([^"]+)""").find(0).saveAs("ns") | |
) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment