Franz Wimmer
Franz Wimmer

Reputation: 1487

Gatling: How to solve "cannot find impicit parameter"?

I have this Gatling Simulation:

package package_name
import io.gatling.core.Predef._
import io.gatling.http.Predef._

class PerformanceTest extends Simulation {
  private val httpConfiguration = http
    .baseURL(Configuration.baseUrl)
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader(Configuration.userAgentName)
    .inferHtmlResources()
    .maxConnectionsPerHostLikeChrome
    .disableClientSharing
    .extraInfoExtractor(dumpSessionOnFailure)
}

Where Configuration is a simple object Configuration { ... }.

Gatling won't compile the tests, stating this error message:

[...]\performance-test\src\gatling\scala\package_name\performance\test\PerformanceTest.scala: 
could not find implicit value for parameter configuration: io.gatling.core.config.GatlingConfiguration
  private val httpConfiguration = http
                                  ^
one error found

How can I solve this error?

Upvotes: 2

Views: 2766

Answers (3)

blackuprise
blackuprise

Reputation: 450

In my case I had variable defined as below in the simulation class

val configuration = ConfigFactory.load()..

which was causing the issue... with the same message

Upvotes: 0

Dmytro Mitin
Dmytro Mitin

Reputation: 51723

The following code compiles without errors:

src/test/scala/package_name/PerformanceTest.scala

package package_name

import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.http.Predef._

object Configuration {
  val userAgentName: Expression[String] = "http://computer-database.gatling.io"
  val baseUrl: String = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"
}

class PerformanceTest extends Simulation {
  private val httpConfiguration = http
    .baseURL(Configuration.baseUrl)
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader(Configuration.userAgentName)
    .inferHtmlResources()
    .maxConnectionsPerHostLikeChrome
    .disableClientSharing
    .extraInfoExtractor(dumpSessionOnFailure)
}

build.sbt

name := "gatlingdemo"

version := "0.1"

scalaVersion := "2.12.6"

libraryDependencies += "io.gatling" % "gatling-core" % "2.3.1"
libraryDependencies += "io.gatling" % "gatling-http" % "2.3.1"

Here is a quick start: https://gatling.io/docs/2.3/quickstart/#gatling-scenario-explained

Where Configuration is a simple object Configuration {}.

Configuration can't be just object Configuration {}, it should contain userAgentName and baseUrl.

Upvotes: 0

Franz Wimmer
Franz Wimmer

Reputation: 1487

The solution is as simple as frustrating: I changed the package name (not the location of the file) to performance_test (it was com.company.performance.test before). Now the code compiles flawlessly.

Upvotes: 1

Related Questions