How to invoke a SOAP Web service using Gatling 2.2.0 - soap

I am new to Gatling and Scala. How to invoke / test a java SOAP web service using Gatling 2.2.0 ? I had searched google and gatling documentation, but could not find any link for that
code:
val httpProtocol = http
.baseURL("http://PUNITP83267L:8081/WebServiceProject/services/MyService")
val headers_0 = Map(
"accept-encoding" -> "gzip, deflate",
"Content-Type" -> "text/xml;charset=UTF-8",
"SOAPAction" -> "",
"Content-Length" -> "275",
"Host" -> "PUNITP83267L:8081",
"Connection" -> "alive",
"accept-language" -> "en-US,en;q=0.8",
"user-agent" -> "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"
)
val scn = scenario("SOAPRecordedSimulation")
.exec(http("simple Soap Request")
.post("<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<soapenv:Body><greetMeResponse xmlns=\"http://ws.star.fs.infosys.com\">
<greetMeReturn>Hello uMESH</greetMeReturn></greetMeResponse>
</soapenv:Body></soapenv:Envelope>\"\r\n")
.headers(headers_0))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

Am not sure if there is a recorder available. But, you could make changes to your script as below:
class testSOAP extends Simulation {
val httpProtocol = http
.baseURL("http://PUNITP83267L:8081/WebServiceProject/services/")
val header = Map(
"accept-encoding" -> "gzip, deflate",
"Content-Type" -> "text/xml;charset=UTF-8",
"SOAPAction" -> "", "Content-Length" -> "275",
"Host" -> "PUNITP83267L:8081",
"Connection" -> "alive",
"accept-language" -> "en-US,en;q=0.8",
"user-agent" -> "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36")
val scn = scenario("SOAPRecordedSimulation")
.exec(http("simple Soap Request")
.post("MyService")
.headers(header)
.body(StringBody("""<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><greetMeResponse xmlns=\"http://ws.star.fs.infosys.com\"><greetMeReturn>Hello uMESH</greetMeReturn></greetMeResponse></soapenv:Body></soapenv:Envelope>\"\r\n""")))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

I think that the SAOP code have to be in a file, and the base url doesn't contain the url context. It's just the base url (localhost:7001). Put the url context in the post function.
Here is the code :
package my.package
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class MyClass extends Simulation {
val httpProtocol = http
.baseURL("http://127.0.0.1:7001")
.inferHtmlResources()
.acceptEncodingHeader("gzip,deflate")
.contentTypeHeader("text/xml;charset=UTF-8")
.userAgentHeader("Apache-HttpClient/4.1.1 (java 1.5)")
val headers_0 = Map("SOAPAction" -> """""""")
val uri1 = "http://127.0.0.1:7001/my-project/my-service"
val scn = scenario("ScenarioName")
.exec(http("request_0")
.post("/my-project/my-service")
.headers(headers_0)
.body(RawFileBody("MyService_0000_request.txt")))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
"MyService_0000_request.txt" is a file in bodies folder and contains the soap request body.

Related

Akka HTTP: How to add a custom user agent to a HttpRequest?

I would need to add a custom user agent like e.g. "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0" to a HttpRequest used as outgoing user agent, is that possible?
val url = UrlBuilder(id)
val request = HttpRequest(method = HttpMethods.GET, uri = url)
val f: Future[(StatusCode, String)] = Http(context.system)
.singleRequest(request)
.flatMap(_.toStrict(2.seconds))
.flatMap { resp =>
Unmarshal(resp.entity).to[String].map((resp.status, _))
}
context.pipeToSelf(f) {
case Success(response) =>
ResponseSuccess(response._1, response._2)
case Failure(e) =>
ResponseFailure(e.getMessage)
}

Failed to build request: No attribute named 'token' is defined in Gatling script

I convert HAR file to Gatling simulations script, but I have problem with extracting token from request header. After conversion I have the following code:
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class LoginTest extends Simulation {
val httpProtocol = http
.baseUrl("https://webapi.mytestsite.com)
.inferHtmlResources()
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36")
val headers_0 = Map(
"Accept" -> "application/json, text/plain, */*",
"Origin" -> "https://mytestsite.com",
"Sec-Fetch-Mode" -> "cors")
val headers_1 = Map(
"Access-Control-Request-Headers" -> "authorization",
"Access-Control-Request-Method" -> "GET",
"Origin" -> "https://mytestsite.com",
"Sec-Fetch-Mode" -> "cors")
val headers_2 = Map(
"Accept" -> "application/json, text/plain, */*",
"Origin" -> "https://mytestsite.com",
"Sec-Fetch-Mode" -> "cors",
"authorization" -> "Bearer ipV0mVqxcVO7xQUJ6lBPNxn77tWCivmO7Gohe47z7d7skAJV-mRCuVOwT1YmJVOvZ8N-T-ZFCgvT4nclOsfI303G7Y4EBIS9pFl4iU23C8l1k6Di387ZnAuDIkncHAne9HukSN9bBf1in9L8ath8fE57gx1CZw-kDXU4K67Q9F9brj413mMZiQrIp6VMJaFFPmMcEgq-h0uo9lP03qTdz6Aq_GdxZOV9iXls2nGG5j6nt_cFaxoTFICn0nwKRjR7eJloyUXmF3wfoqkvC_5t5gZ_YKDMf_mLxg4V2seBVyM1O11EwOpGpTOZG5FYDnJoarDybX6QkE-F4eb5aZM27NiPjstMwMn4zQ2EvhuinLNWHBzTtRN0MNW8TLT0X4f6hNS0F9lmjWBzl_OF-wCzoYQiFM7tQsU2UkHC1FHROJbPQDOH6oxDG06u8Nnco07cmLKn60zE4FYDa52DTt1lNGK7GIP97LgrGCHEdJByN4U")
val headers_3 = Map("Sec-Fetch-Mode" -> "no-cors")
val headers_6 = Map(
"Origin" -> "https://mytestsite.com",
"Sec-Fetch-Mode" -> "cors",
"content-type" -> "application/x-www-form-urlencoded; charset=UTF-8")
val uri1 = "https://api.wage.iteodev.com/signalr"
val uri2 = "https://mytestsite.com/static/media/download-app-headline.a2c2b312.svg"
val scn = scenario("LoginTest")
.exec(http("request_0")
.post("/api/oauth/token")
.headers(headers_0)
.formParam("username", "yelari#malboxe.com")
.formParam("password", "Zaq1#wsx")
.formParam("grant_type", "password")
.resources(http("request_1")
.options("/api/account")
.headers(headers_1),
http("request_2")
.get("/api/account")
.headers(headers_2),
http("request_3")
.get(uri2 + "")
.headers(headers_3),
http("request_4")
.options("/api/conversations/")
.headers(headers_1),
http("request_5")
.options("/api/notifications")
.headers(headers_1),
http("request_6")
.get(uri1 + "/negotiate?clientProtocol=1.5&Authorization=Bearer%20ipV0mVqxcVO7xQUJ6lBPNxn77tWCivmO7Gohe47z7d7skAJV-mRCuVOwT1YmJVOvZ8N-T-ZFCgvT4nclOsfI303G7Y4EBIS9pFl4iU23C8l1k6Di387ZnAuDIkncHAne9HukSN9bBf1in9L8ath8fE57gx1CZw-kDXU4K67Q9F9brj413mMZiQrIp6VMJaFFPmMcEgq-h0uo9lP03qTdz6Aq_GdxZOV9iXls2nGG5j6nt_cFaxoTFICn0nwKRjR7eJloyUXmF3wfoqkvC_5t5gZ_YKDMf_mLxg4V2seBVyM1O11EwOpGpTOZG5FYDnJoarDybX6QkE-F4eb5aZM27NiPjstMwMn4zQ2EvhuinLNWHBzTtRN0MNW8TLT0X4f6hNS0F9lmjWBzl_OF-wCzoYQiFM7tQsU2UkHC1FHROJbPQDOH6oxDG06u8Nnco07cmLKn60zE4FYDa52DTt1lNGK7GIP97LgrGCHEdJByN4U&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_6),
http("request_7")
.get("/UploadedFiles/03765fee-ede8-4689-9a4c-13dd2ada18a4.png")
.headers(headers_3),
http("request_8")
.get("/api/notifications")
.headers(headers_2),
http("request_9")
.get("/api/conversations/")
.headers(headers_2),
http("request_10")
.get("/UploadedFiles/26ac4d69-8a63-4575-bec4-849d5a5e194a.png")
.headers(headers_3),
http("request_11")
.get(uri1 + "/start?transport=serverSentEvents&clientProtocol=1.5&Authorization=Bearer%20ipV0mVqxcVO7xQUJ6lBPNxn77tWCivmO7Gohe47z7d7skAJV-mRCuVOwT1YmJVOvZ8N-T-ZFCgvT4nclOsfI303G7Y4EBIS9pFl4iU23C8l1k6Di387ZnAuDIkncHAne9HukSN9bBf1in9L8ath8fE57gx1CZw-kDXU4K67Q9F9brj413mMZiQrIp6VMJaFFPmMcEgq-h0uo9lP03qTdz6Aq_GdxZOV9iXls2nGG5j6nt_cFaxoTFICn0nwKRjR7eJloyUXmF3wfoqkvC_5t5gZ_YKDMf_mLxg4V2seBVyM1O11EwOpGpTOZG5FYDnJoarDybX6QkE-F4eb5aZM27NiPjstMwMn4zQ2EvhuinLNWHBzTtRN0MNW8TLT0X4f6hNS0F9lmjWBzl_OF-wCzoYQiFM7tQsU2UkHC1FHROJbPQDOH6oxDG06u8Nnco07cmLKn60zE4FYDa52DTt1lNGK7GIP97LgrGCHEdJByN4U&connectionToken=P%2FGWEN0HNtZWUowxiulVcCbSNQGTg%2BtCrti09SWiZKkPiFyOPNuEW4HBfWX%2FTPbRLhbhW5sst3BwnE3ihcbCvNE9m42MoguFmLCUGUib12Xrqsb8mZ7LsjlhYh5ul07Q1ups4KfOqxgcT0bx%2F03o1A%3D%3D&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
.headers(headers_6)))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
But when I change
http("request_2")
.get("/api/account")
.headers(headers_2),
to
http("request_2")
.get("/api/account")
.headers(headers_2)
.check(header("Bearer").saveAs("token"))
and when I change
http("request_6")
.get(uri1 + "/negotiate?clientProtocol=1.5&Authorization=Bearer%20ipV0mVqxcVO7xQUJ6lBPNxn77tWCivmO7Gohe47z7d7skAJV-mRCuVOwT1YmJVOvZ8N-T-ZFCgvT4nclOsfI303G7Y4EBIS9pFl4iU23C8l1k6Di387ZnAuDIkncHAne9HukSN9bBf1in9L8ath8fE57gx1CZw-kDXU4K67Q9F9brj413mMZiQrIp6VMJaFFPmMcEgq-h0uo9lP03qTdz6Aq_GdxZOV9iXls2nGG5j6nt_cFaxoTFICn0nwKRjR7eJloyUXmF3wfoqkvC_5t5gZ_YKDMf_mLxg4V2seBVyM1O11EwOpGpTOZG5FYDnJoarDybX6QkE-F4eb5aZM27NiPjstMwMn4zQ2EvhuinLNWHBzTtRN0MNW8TLT0X4f6hNS0F9lmjWBzl_OF-wCzoYQiFM7tQsU2UkHC1FHROJbPQDOH6oxDG06u8Nnco07cmLKn60zE4FYDa52DTt1lNGK7GIP97LgrGCHEdJByN4U&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
to
http("request_6")
.get(uri1 + "/negotiate?clientProtocol=1.5&Authorization=Bearer%20${token}&connectionData=%5B%7B%22name%22%3A%22livechat%22%7D%5D")
I've got following error:
https://i.postimg.cc/0yTMKrvm/2019-10-12-23-46-37-C-WINDOWS-system32-cmd-exe.png
What am I doing wrong?
Looking at the screenshot, the error you are getting is: No attribute named 'token' is defined .
This suggests that you aren't saving the token from the header Bearer.
Look closely at the HTTP request when you call /api/account - especially the headers, and check that the header exists as you expect. You could use Chrome Dev Tools or any HTTP proxy for this.
You might want to debug your Script in Gatling as well, so that you can see all the variables you are capturing - see this post for some ideas on that - https://www.james-willett.com/debug-gatling/

Unable to print line or reach break point in Gatling 3.0 simulation

So I know we cannot perform DSL operations in before/after of a Gatling simulation, but in 3.0 it does not appear to work at all. If I run the simulation I don't see a print line and I do not reach a break point on the prints. I am using Intellij. I must be missing something obvious, any help would be appreciated
My Simulation:
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class Sample extends Simulation {
val httpProtocol = http
.baseUrl("https://www.google.com")
.inferHtmlResources()
val headers_0 = Map(
"accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding" -> "gzip, deflate, br",
"accept-language" -> "en-US,en;q=0.9",
"cache-control" -> "max-age=0",
"upgrade-insecure-requests" -> "1",
"user-agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36")
def before = {
println("In the Before")
}
def after = {
println("All done!")
}
val scn = scenario("Sample")
.exec(http("request_0")
.get("/")
.headers(headers_0)
)
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
I am using a object to run the simulation. Included below in case it's relevant:
import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder
object temp {
def main(args: Array[String]): Unit = {
val simulation = classOf[Sample].getName
val runner = new GatlingPropertiesBuilder
runner.simulationClass(simulation)
Gatling.fromMap(runner.build)
}
}
Problem in chair, not in computer... solution below. Credit to Stéphane Landelle for solution.
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class Sample extends Simulation {
val httpProtocol = http
.baseUrl("https://www.google.com")
.inferHtmlResources()
val headers_0 = Map(
"accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding" -> "gzip, deflate, br",
"accept-language" -> "en-US,en;q=0.9",
"cache-control" -> "max-age=0",
"upgrade-insecure-requests" -> "1",
"user-agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36")
before {
println("In the Before")
}
after {
println("All done!")
}
val scn = scenario("Sample")
.exec(http("request_0")
.get("/")
.headers(headers_0)
)
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

How import a object or Class in Scala file from another Scala file?

I have two Scala files and i need to import from second Scala file a class, but i dont know
In the first scala file i have a requests, and in especific request i want to call a object from second file in this object i have a authenticate request.
How i can import?
Sorry for my basic question, im new in Gatling, i need help :c
My first file has:
class SearchCustomerClientNumber2 extends Simulation {
val httpProtocol = http
.baseURL("http://URL")
.inferHtmlResources()
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("es-CL,es;q=0.8,en-US;q=0.5,en;q=0.3")
.userAgentHeader("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0")
.exec(http("request_9")
.get("/bei010Web/bei010/sp_MX/bei10.jsp")
.headers(headers_0))
.pause(1)
.exec(http("request_10")
.get("/bei010Web/Security?WSDL")
.resources(http("request_11")
.get("/bei010Web/Activities?WSDL")))
.pause(4)
//here i want to import a object from another scala file is
aauthenticate web service
.resources(http("request_13")
.post("/bei010Web/Security")
.headers(headers_13)
.body(RawFileBody("SearchCustomerClientNumber2_0013_request.txt")),
My second Scala file:
Class IC6SaaSRestUAT_Tuves extends Simulation {
val httpProtocol = http
.baseURL("http://URL") // PROD
.inferHtmlResources()
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("es-CL,es;q=0.8,en-US;q=0.5,en;q=0.3")
.userAgentHeader("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0")
val csvFeeder = csv("Users.csv").circular // use a comma separator
val headers_12 = Map(
"Content-length" -> "1135",
"Content-type" -> "text/xml; charset=utf-8",
"SOAPAction" -> """""""")
val uri1 = "http://URL/bBBBBWeb/"
print("*******")
print("*******")
print(csvFeeder)
object IC6SaaS { //I want to import this object if is possible
val ic = feed(csvFeeder)
.exec(http("request_12")
.post("/bei010Web/Security")
.headers(headers_12)
//.body(RawFileBody("SearchAccountNumberxxx_0012_request.txt"))
.body(StringBody("""<SOAP-ENV:Envelope xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<tns:authenticateUser
xmlns:tns="http://webservice.bei.inffinix.com/">
<login>${Username}</login>
<password>${pass}</password>
<program>1</program>
</tns:authenticateUser>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>"""))
check(regex("""errors""").count.is(0)))
}

How do I use Scala dispatch to get the URL returned in a 301 redirect?

I am using Scala dispatch HTTP library, version 0.10.1. I make a request to a URL that returns an HTTP 301, permanent redirect. For example, http://wikipedia.com returns a 301 that redirects to http://www.wikipedia.org/. How do I do I use dispatch to get the redirected URL?
Following the tutorial, here's what I've done.
import dispatch._, Defaults._
val svc = url("http://wikipedia.com")
val r = Http(svc OK as.String)
r()
This throws a "Unexpected response status: 301" exception. Presumably I need to either query the r value for the redirected URL, or maybe specify some argument other than OK in its definition, but I can't figure out what to do from the documentation.
Configure the underlying asyncClient to follow redirects:
val r = Http.configure(_ setFollowRedirects true)(svc OK as.String)
To get the redirected URL:
val svc = url("http://wikipedia.com/")
val r = Http(svc > (x => x))
val res = r()
println(res.getHeader("Location"))
dispatch / reboot v1.2.0:
val myRequest = url(theUrl)
def myGet = myRequest.GET
def myGetFollowRedi = myGet.setFollowRedirects(true)
def myRequestWithHeader = myGetFollowRedi <:< Map(
"User-Agent" -> "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.",
"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.",
"Accept-Language" -> "de-DE,de;q=0.9,en-US;q=0.7,en;q=0.6,en-GB;q=0.4,nl-NL;q=0.3,nl;q=0.1",
"Accept-Encoding" -> "gzip, deflate, br",
"DNT" -> "1",
"Connection" -> "keep-alive",
"Upgrade-Insecure-Requests" -> "1",
"Sec-Fetch-Dest" -> "document",
"Sec-Fetch-Mode" -> "navigate",
"Sec-Fetch-Site" -> "none",
"Sec-Fetch-User" -> "?1"
)