Gatling: check binary response not empty - scala

I'm doing some tests with Gatling using Scala. I'm trying to check whether a response body that is returned is not empty.
I'm doing it like this:
def getImages: ChainBuilder = feed(credentials)
.exec(http("Get Image")
.get(GET_MY_URI)
.queryParam("guid", "${branch}")
.queryParam("t", "0.458654")
.check(status.is(200))
.check(bodyString.transform(_.size > 1).is(true)))
But it's not working. I get:
java.nio.charset.MalformedInputException: Input length = 1
Does somebody know how to achieve what I'm trying?

Replace
.check(bodyString.transform(_.size > 1).is(true)))
with
.check(bodyBytes.exists)
All the DSL is explained here: https://gatling.io/docs/current/cheat-sheet/

Related

Convert XML like String to PySpark Dataframe

I'm using azure.storage.queue's receive_messages() function in databricks to pull messages from a azure queue. The response looks like xml but it is really just a string:
<?xml version="1.0" encoding="utf-16"?>
<root>
<col1>123</col1>
<col2>1</col2>
<col3>Unknown</col3>
<col4>Dog</col4>
<col5>Owner</col5>
<col6>-1</col6>
<col7>Owner</col7>
<col8></col8>
</root>
When I write the response to a list, it looks like:
'<root>\r\n <col1>123</col1>\r\n <col2>1</col2>\r\n <col3>Unknown</col3>\r\n <col4>Dog</col4>\r\n <col5>Owner</col5>\r\n <col6>-1</col6>\r\n <col7>Owner</col7>\r\n <col8></col8>\r\n</root>'
I know that I can split on \r\n with something like:
l = [x.strip().split(' ') for x in a[0].split('\r\n')]
l
This gives:
['root'],
['<col1>123</col1>'],
['<col2>1</col2>'],
['<col3>Unknown</col3>'],
['<col4>Dog</col4>'],
['<col5>Owner</col5>'],
['<col6>-1</col6>'],
['<col7>Owner</col7>'],
['<col8></col8'],
['</root>']]
I'm not sure if this is the best route and I don't want to hard code each value into the spark dataframe, because I need to iterate through all messages in the queue. Looking for a solution that converts each 'col' into a header and then grabs the value between 'tags'.
Here is an answer:
data=[]
for message in response:
#print(message.content)
soup = BeautifulSoup(message.content, "xml")
c=soup.find_all('col1')
c1=soup.find_all('col2')
c2=soup.find_all('col3')
c3=soup.find_all('col4')
c4=soup.find_all('col5')
c5=soup.find_all('col6')
c6=soup.find_all('col7')
c7=soup.find_all('col8')
for i in range(0,len(c)):
rows=[c[i].get_text(),
c1[i].get_text(),
c2[i].get_text(),
c3[i].get_text(),
c4[i].get_text(),
c5[i].get_text(),
c6[i].get_text(),
c7[i].get_text()]
data.append(rows)
#print(data)
out_df = spark.createDataFrame(data,schema = ['c','c1','c2','c3','c4',
'c5','c6','c7'])
This was faster, but requires the response to always be in the same order, which mine is.
data=[]
for message in response:
#print(message.content)
root=etree.fromstring(message.content.encode('utf-16'))
arr=[]
for child in root:
r=child.text
arr.append(r)
data.append(arr)
out_df = spark.createDataFrame(data,schema = ['c','c1','c2','c3','c4',
'c5','c6','c7'])
display(out_df)

Gatling - how to achieve feeders to pick a new value in loop

In Gatling, I am using feeders to pass the values of the coordinates in a request, below is the code. I want on each repeat a new value from the feeder to be picked up. I am get the following error --
/mapping/v2/: Failed to build request: No attribute named 'map 30 (100.0%) x' is defined
Could someone please advice how this can be achieved. thanks.
val mapfeeder = csv(fileName = "data/cordinates.csv").circular
object PDP {
val pdp = group("ABC_01_DetailsPage") {
exec(http("PropertyDetailsPage")
.get("/abc/property/detail.html?propertyId=12345&index=0&q=${address_json6}&qt=address&_qt=address&offset=1&sort=address&limit=20&view=property&mode=&radius=1.0Km&landuse=All")
.check(substring("Change in Median Price")))
}
.pause(duration = 1)
.feed(mapfeeder) //this works but only take the fist value and repeats it 30 times
.group("ABC_02_DetailsPage_MAP") {
repeat(30) {
feed(mapfeeder) // this one fails with the error mentioned in the post
exec(http("/mapping")
.get(uri22 + "?mapTypeId=1006&x=${mapx}&y=${mapy}&z=19&access_token=${maptoken}"))
}
val scn = scenario("RecordedSimulation")
.feed(SearchFeeder)
.exec(Homepage.homepage, Login.login, SearchLink.search, SearchEntry.searchentry, PDP.pdp, Logout.logout)
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
You're missing a dot to attach your feed and the following exec, so only the result of the last instruction (the exec) is passed to the repeat method.
It should be:
repeat(30) {
feed(mapfeeder)
.exec(
http("/mapping") // <== HERE, DOT WAS MISSING
.get(uri22 + "?mapTypeId=1006&x=${mapx}&y=${mapy}&z=19&access_token=${maptoken}")
)
}

Correlation Of dynamic value in Gatling

I'm trying to correlate or create a "Check" in Gatling load tool, but not sure how to do it. I Went through the advanced tutorial doc from official Gatling website but couldn't exactly find much on correlation of the dynamic value.
Below is the peice of code from my script
.feed(feeder)
.exec(http("EnterDetails")
.post("/events/review.action")
.headers(headers_6)
.formParam("userInfo.spgEmail", "")
.formParam("userInfo.title", "")
.formParam("userInfo.firstName", "${FirstName}")
.formParam("userInfo.lastName", "${LastName}")
.formParam("userInfo.address1", "Open")
.formParam("userInfo.address2", "")
.formParam("userInfo.city", "${City}")
.formParam("userInfo.state", "NYY")
.formParam("userInfo.country", "US")
.formParam("userInfo.zipCode", "10016")
.formParam("userInfo.primaryNoInfo.optedIn", "false")
.formParam("userInfo.phoneTwoInfo.optedIn", "false")
.formParam("userInfo.phoneThreeInfo.optedIn", "false")
.formParam("userInfo.primaryNoInfo.validInd", "Y")
.formParam("userInfo.phoneTwoInfo.validInd", "")
.formParam("userInfo.phoneThreeInfo.validInd", "")
.formParam("userInfo.phoneUseType1", "0")
.formParam("userInfo.primaryNoInfo.phoneNumber", "9876543211")
.formParam("userInfo.primaryNoInfo.extension", "")
.formParam("userInfo.country1", "US%28%2B1%29")
.formParam("__checkbox_userInfo.primaryNoInfo.oneTimeOptInPresent", "true")
.formParam("userInfo.phoneUseType2", "-1")
.formParam("userInfo.phoneTwoInfo.phoneNumber", "")
.formParam("userInfo.phoneTwoInfo.extension", "")
.formParam("userInfo.country2", "US%28%2B1%29")
.formParam("__checkbox_userInfo.phoneTwoInfo.oneTimeOptInPresent", "true")
.formParam("userInfo.phoneUseType3", "-1")
.formParam("userInfo.phoneThreeInfo.phoneNumber", "")
.formParam("userInfo.phoneThreeInfo.extension", "")
.formParam("userInfo.country3", "US%28%2B1%29")
.formParam("__checkbox_userInfo.phoneThreeInfo.oneTimeOptInPresent", "true")
.formParam("userInfo.email", "")
.formParam("userInfo.retypeEmail", "")
.formParam("userInfo.nonCCPayment", "true")
.formParam("userInfo.SPGNumber", "")
.formParam("userInfo.arrivalCarrier", "")
.formParam("userInfo.transportationNumber", "")
.formParam("userInfo.transportationArrTime", "")
.formParam("userInfo.hotelArrivalTime", "")
.formParam("userInfo.hotelDepartureTime", "")
.formParam("userInfo.SRequest", "")
.formParam("userInfo.IAgree", "true")
.formParam("__checkbox_userInfo.IAgree", "true")
.formParam("method%3Aexecute", "Review+Your+Reservation+"))
.pause(2)
.exec(http("ReviewREservation")
.get(uri3 + "/s01000706679492?AQB=1&ndh=1&pf=1&t=21%2F3%2F2016%2012%3A45%3A54%204%200&D=D%3D&fid=31A8BC73D5B8ACEB-2B64CD0ACE185774&ce=UTF-8&pageName=Review%20Reservation&g=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Freview.action&r=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Fselectcreate%21execute.action%3FselRoom%3D1&cc=USD&ch=StarGroups&server=StarGroups&c2=SOCIAL&c3=1603295001&c4=271&c5=SI&c6=YES&c8=en&s=1600x838&c=24&j=1.6&v=N&k=Y&bw=1042&bh=733&AQE=1")
.headers(headers_3))
.pause(7)
.exec(http("request_13")
.post("/events/confirm.action")
.headers(headers_6)
.formParam("method%3Aexecute", "Complete+Your+Reservation"))
.pause(4)
.exec(http("CompleteReservation")
.get(uri3 + "/s03623649917832?AQB=1&ndh=1&pf=1&t=21%2F3%2F2016%2012%3A46%3A5%204%200&D=D%3D&fid=31A8BC73D5B8ACEB-2B64CD0ACE185774&ce=UTF-8&pageName=Reservation%20Confirmation&g=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Fconfirm.action&r=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Freview.action&cc=CAD&purchaseID=20160421_734091125&ch=StarGroups&server=StarGroups&events=purchase&products=%3B271%3B1%3B100.00&c2=SOCIAL&c3=1603295001&c4=271&v4=20160421_734091125&c5=SI&c6=YES&c8=en&s=1600x838&c=24&j=1.6&v=N&k=Y&bw=1042&bh=733&AQE=1")
.headers(headers_3))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
In The above code I have a dynamic Purchase ID in
.exec(http("CompleteReservation")
which gets generated from the server and needs to be correlated.
From The Gatling Documentation, I understand( correct me if I'm wrong) that we need the inspect element code to get the CSS path.(Shown Here).
Inspect Element
Please let me know how do we correlate .TIA.
In Gatling you have to use checks to extract a value from response. Take a look in documentation.
You can choose to use regex or xpath to extract value in tag. But in your case I'd recommend to use simple regex because IMO in your example response there are not tags or IDs where you can easily hook with xpath. I mean the way that the xpath expression will still remain simple and understandable. Next thing is to extract value into session and afterwards to use it.
Following is the example scenario extracting query path of URI from response received from example.com which is afterwards printed in console:
val scn = scenario("Checks")
.exec(
http("root")
.get("/")
.check(
// Extracting URI query path from response body via regexp and storing into session
regex("""www\.iana\.org/([a-z/]*)""").find.saveAs("queryPath")
)
)
// Printing the value from session
// Important thing to note is how you can access stored value from session
.exec { session =>
println(" QUERY PATH --> " + session("queryPath").as[String])
session
}
In your case your last part could look something like this:
.exec(http("CompleteReservation")
.get(uri3 + "/s03623649917832?AQB=1&ndh=1&pf=1&t=21%2F3%2F2016%2012%3A46%3A5%204%200&D=D%3D&fid=31A8BC73D5B8ACEB-2B64CD0ACE185774&ce=UTF-8&pageName=Reservation%20Confirmation&g=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Fconfirm.action&r=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Freview.action&cc=CAD&purchaseID=20160421_734091125&ch=StarGroups&server=StarGroups&events=purchase&products=%3B271%3B1%3B100.00&c2=SOCIAL&c3=1603295001&c4=271&v4=20160421_734091125&c5=SI&c6=YES&c8=en&s=1600x838&c=24&j=1.6&v=N&k=Y&bw=1042&bh=733&AQE=1")
.headers(headers_3))
.check(
regex("""Your confirmation number is (\d+)""") // Regular expression with group which represents confirmation number.
.find
.saveAs("confirmationNumber") // Now the extracted regexp group is stored in session under "confirmationNumber" as name.
)
// Missing, check, transformation or use of value from session
I don't know your usage of extracted value thus it's missing in snippet above . But I hope that you will already have an idea how to handle responses and how to use the extracted values next.
I hope that it helps.

Groovy script for count value matches with offset

<... count="6" offset="3,2,7,1,4,5"/>
from the above snippet, i want to verify number of offset values should get match with count value. Please help to get SOAPUI REST services groovy script for this one.
Thanks!
Your question it's not clear so supposing that you've something like:
<myTag count="6" offset="3,2,7,1,4,5"/>
You can use XmlSlurper in groovy script to validate your requirement as follows:
def xmlStr = '<myTag count="6" offset="3,2,7,1,4,5"/>'
def xml = new XmlSlurper().parseText(xmlStr)
// use # notation to acces attributes
def count = xml.#count
def offset = xml.#offset.toString().split(',')
// assert that count matches the length of the array
assert count == offset.length
Anyways consider to provide more details and what you tried as #Opal suggest in it's comment.
Hope it helps,

reactivemongo : How to println a TraversableBSONDocument content?

for debugging purpose I would like to see what a TraversableBSONDocument has inside, I'm not able to see the content of a response.
I found it ! :
val query = BSONDocument()
.equal("userId", user.id.map(_.value).map(_.toLong).get)
.greaterThanOrEqual("start", interval.start.jodaDateTime)
.lesserThan("end", interval.end.jodaDateTime)
.count("RREntity")
println(BSONDocument.pretty(query))