Syntax Errors

Hi ,

Could you please tell me if the syntax is correct ?

val httpProtocol = http
.baseURL(“https://xyz.com”)
.headers(“Content-Type”, “application/json”)
.headers(“sentHeaders”)
.headers(“Accept”,“application/json”)
.headers(“Accept-Charset”,“utf-8n”)
.acceptEncodingHeader(""“gzip, deflate”"")
.acceptLanguageHeader(""“en-us,en;q=0.5"”")
.connection(""“keep-alive”"")

The error which i am getting is attached as a screen shot

Kindly help

gatling_error.png

.headers() accepts a map. You want .header( name, value )

Not sure what you intend with .headers(“sentHeaders”), but if you intend to send the header without a value, you need to add an empty value, like so: .header(“sentHeaders”,"")

HI John,
I have deleted that header and it look like the one mentioned below

val httpProtocol = http
.baseURL(“https://xyz.com”)
.headers(“Content-Type”, “application/json”)
.headers(“Accept”,“application/json”)
.headers(“Accept-Charset”,“utf-8n”)
.acceptEncodingHeader(""“gzip, deflate”"")
.acceptLanguageHeader(""“en-us,en;q=0.5"”")
.connection(""“keep-alive”"")

But still the same errors pops up.
Kindly help

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import scala.util.matching.Regex
import scala.concurrent.duration._

class getSampleTest extends Simulation{

val httpProtocol = http
.baseURL(“https://xyz.com”)
.headers(“Content-Type”, “application/json”)
.headers(“Accept”,“application/json”)
.headers(“Accept-Charset”,“utf-8n”)
.acceptEncodingHeader(""“gzip, deflate”"")
.acceptLanguageHeader(""“en-us,en;q=0.5"”")
.connection(""“keep-alive”"")

val scn = scenario(“XYZ”)
.group(“XYZ Group”) {
exec(http(“XYZ-Page”).get("/profile/services/countries").check(status.is(200)))
}
setUp(scn.inject(
rampUsersPerSec(1) to(10) during(5),
constantUsersPerSec(10) during(5)
).protocols(httpProtocol))

}

Quoting John : “.headers() accepts a map. You want .header( name, value )”

Change :

.headers(“Content-Type”, “application/json”)
.headers(“Accept”,“application/json”)

.headers(“Accept-Charset”,"utf-8n”)

To :

.header(“Content-Type”, “application/json”)
.header(“Accept”,“application/json”)

.header(“Accept-Charset”,"utf-8n”)

Hi ,

just changed a little in the headers part , along with the syntax in headers

val AllHeaders = Map(“Content-Type” → “application/json”, “Accept” → " application/json ")

val httpProtocol = http
.baseURL(“https://xyz.com”)
.headers(AllHeaders )
.header(""“Accept-Charset”,“utf-8n”"")
.acceptLanguageHeader(""“en-us,en;q=0.5"”")
.acceptEncodingHeader(""“gzip, deflate”"")
.connection(""“keep-alive”"")

But still getting error (Error snapshot attached)
Kindly help

gatling_error_2.png

hi ,
i have also used the below over here

val httpProtocol = http
.baseURL(“https://xyz.com”)
.header(“Content-Type”,“application/json”)
.header(“Accept”," application/json ")
.header(“Accept-Charset”,“utf-8n”)
.acceptLanguageHeader(“en-us”,“en;q=0.5”)
.acceptEncodingHeader(“gzip”, “deflate”)
.connection(“keep-alive”)
Getting the error mentioned in snapshot_1

Thanks in Advance

Any Recommendations >?

Can you post your full simulation please ?

  1. package simulations.computerdatabase.advanced

  2. import io.gatling.core.Predef._

  3. import io.gatling.http.Predef._

  4. import io.gatling.jdbc.Predef._

  5. import scala.util.matching.Regex

  6. import scala.concurrent.duration._

  7. class getSampleTest extends Simulation{

  8. val sentHeaders = Map(“Content-Type” → “application/json”, “Accept” → " application/json ")

  9. val httpProtocol = http

  10. .baseURL(“https://xyz.com”)

  11. .headers(sentHeaders)

  12. .acceptLanguageHeader(“en-us,en;q=0.5”)

  13. .acceptEncodingHeader(“gzip,deflate”)

  14. .connection(“keep-alive”)

  15. val scn = scenario(“XYZ”)

  16. .group(“XYZ Group”) {

  17. exec(http(“XYZ-PAge”).get("/profile/services/countries").check(status.is(200)))

  18. }

  19. setUp(scn.inject(

  20. rampUsersPerSec(1) to(10) during(5),

  21. constantUsersPerSec(10) during(5)

  22. ).protocols(httpProtocol))

  23. }
    And the Error which i am getting →

gatling-charts-highcharts-2.0.0-SNAPSHOT" 20:50:58.858 [ERROR] i.g.a.ZincCompiler$ - C:\gatling-charts-highcharts-2.0.0-20 140922.162052-88-bundle\gatling-charts-highcharts-2.0.0-SNAPSHOT\user-files\simu lations\computerdatabase\advanced\CPC.scala:30: value headers is not a member of io.gatling.http.config.HttpProtocolBuilder possible cause: maybe a semicolon is missing before `value headers’? 20:50:58.863 [ERROR] i.g.a.ZincCompiler$ - .headers(sentHeaders) 20:50:58.864 [ERROR] i.g.a.ZincCompiler$ - ^ 20:51:01.354 [ERROR] i.g.a.ZincCompiler$ - one error found Compilation failed

Well, at line 30 in your simulation there’s no single mention of headers.
Is this absolutely all the code of your CPC.scala file ? Looks like it’s not.

Could be wrong but I think it is complaining about .headers(sentHeaders)

I think .acceptHeader() is what you should be using but I could be wrong :S