Implicit conversion error

I am seeing this error
Found: (“${pkgId}” : String)
Required: io.gatling.core.session.Expression[Any]
Note that implicit conversions cannot be applied because they are ambiguous;
both getter stringIsNeitherValidableNorString1 in object NeitherValidableNorString and getter stringIsNeitherValidableNorString2 in object NeitherValidableNorString match type io.gatling.core.NeitherValidableNorString.DoesNotContain[String]

from this code. Pls help

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.language.postfixOps
import io.gatling.core.session.Expression

class CombinedSimulation extends Simulation {

  object Configuration
  {
    val description: Expression[String] = "bulk05-*"
    val printOrder: Expression[String] = "orderJobNum"
    val printQueue: Expression[String]= "237"

  }

  // Common HTTP Configuration
  val httpConf = http.baseUrl("https://x.cloud").shareConnections

  // Common headers
  val commonHeaders = Map(
    "accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "origin" -> "https://x.cloud",
    "pragma" -> "no-cache",
    "sec-ch-ua" -> """Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122""",
    "sec-ch-ua-mobile" -> "?0",
    "sec-ch-ua-platform" -> "Windows",
    "upgrade-insecure-requests" -> "1"
  )

  // Simulation 1 - ImportVisitManager
  val csvFileWriter = new java.io.PrintWriter(new java.io.File("user_requests.csv"))
  csvFileWriter.println("PkgId")


  val xmlTemplate =
    """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vis="http://visitimport.ws.ietp.infotrustgroup.com/">
       <soapenv:Header/>
       <soapenv:Body>
         <vis:visitImport>
           <arg0>
             --
           </arg0>
         </vis:visitImport>
       </soapenv:Body>
     </soapenv:Envelope>"""

  val dataFeeder = Iterator.continually(Map(
    "visitorDesc" -> s"bulk05-${scala.util.Random.nextInt(10000)}",
    "pkgId" -> (scala.util.Random.nextInt(900) + 10000)
  ))

  val importVisitManagerScenario = scenario("Import Visit Manager")
    .feed(dataFeeder)
    .exec(session => {
      val pkgId = session("pkgId").as[Int]
      val visitorDesc = session("visitorDesc").as[String]
      val updatedSoapBody = xmlTemplate
        .replace("${visitorDesc}", visitorDesc)
        .replace("${pkgId}", pkgId.toString)

      session.set("updatedSoapBody", updatedSoapBody).set("pkgId", pkgId)
    })
    .repeat(5, "requestIndex") {
      exec(http("Post Import Visit Manager")
        .post("/ietp-s1000d-master/ws/visitimport")
        .headers(commonHeaders)
        .body(StringBody("${updatedSoapBody}"))
        .check(status.is(200))
        .check(bodyString.saveAs("responseBody"))
      )
        .exec { session =>
          println(session("responseBody").as[String])
          csvFileWriter.println(s"${session("pkgId").as[Int]}")
          session
        }
    }

  val bulkOpenScenario = scenario("bulkopen")
    .exec(
      http("request_0")
        .post("/ietp-s1000d/getSearchVisitResults.do")
        .headers(commonHeaders)
        .formParam("description", Configuration.description)
        .check(jsonPath("$.pkgId").saveAs("pkgId"))
    )
    .pause(26)
    .exec(
      http("request_25")
        .post("/ietp-s1000d/openAndOrPrintVisits.do")
        .headers(commonHeaders)
        .formParam("visits", "${pkgId}") // Use Gatling Expression
        .formParam("printOrder", Configuration.printOrder)
        .formParam("printQueue", Configuration.printQueue)
    )
    .pause(10)
    .exec(
      http("request_69")
        .post("/ietp-s1000d/getOpenAndOrPrintVisitsResults.do")
        .headers(commonHeaders)
        .formParam("visits", "${pkgId}") // Use Gatling Expression
    )

  // Close CSV writer after both scenarios
  after {
    csvFileWriter.close()
  }

  // Setup both scenarios
  setUp(
    importVisitManagerScenario.inject(atOnceUsers(2)),
    bulkOpenScenario.inject(atOnceUsers(2))
  ).protocols(httpConf)
    .maxDuration(5 minutes) // Set the total duration of the simulation
}

Remove your extra conflicting import: import io.gatling.core.session.Expression.

Note: If you’re not a Scala developer (which you don’t seem to be), you should consider using the Java SDK instead of the Scala one.

Im trying to replace this
PkgId
10412
10426
10161
10829
10123
10791
10325
10471
10165
10720

in place of formparam. But im getting this conversion error
private val scn = scenario(“bulkopen”)
.feed(csvFeeder)

  .exec(session => {
    val processedPkgID = session("pkgId").as[String]
    println(s"Processed pkgID: $processedPkgID")
    session.set("pkgId", processedPkgID)
  })
.exec(
  http("request_0")
    .post("/ietp-s1000d/openAndOrPrintVisits.do")
    .headers(headers_0)

    .formParam("visits", session("processedPkgID"))

    .formParam("printOrder", Configuration.printOrder)
    .formParam("printQueue", Configuration.printQueue)

Pls help

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.