Gatling. Check, if a HTML result contains some string - scala

Programming Gatling performance test I need to check, if the HTML returned from server contains a predefined string. It it does, break the test with an error.
I did not find out how to do it. It must be something like this:
val scn = scenario("CheckAccess")
.exec(http("request_0")
.get("/")
.headers(headers_0)
.check(css("h1").contains("Access denied")).breakOnFailure()
)
I called the wished features "contains" and "breakOnFailure". Does Gatling something similar?

Better solutions:
with one single CSS selector:
.check(css("h1:contains('Access denied')").notExists)
with substring:
.check(substring("Access denied").notExists)
Note: if what you're looking for only occurs at one place in your response payload, substring is sure more efficient, as it doesn't have to parse it into a DOM.

Here ist the solution
.check(css("h1").transform((s: String) => s.indexOf("Access denied"))
.greaterThan(-1)).exitHereIfFailed

You can write it very simple like:
.check(css("h1", "Access denied").notExists)
If you are not sure about H1 you can use:
.check(substring("Access denied").notExists)
IMO server should respond with proper status, thus:
.check(status.not(403))
Enjoy and see http://gatling.io/docs/2.1.7/http/http_check.html for details
EDIT:
My usage of CSS selector is wrong see Stephane Landelle solution with CSS.
I'm using substring way most of the time :)

Related

Mule esb 3.8 how to add object variable (HashMap) into payload (HashMap)

Hello need a bit of help to understand how I can merge 2 payloads from db calls into one - final payload.
First payload is like:
[{Name=John, Age=31}]
Second payload is like:
Address=[{Planet=Earth, Continent=Europa, Town=London},{Planet=Earth, Continent=Europa, Town=Dublin}]
Final result I am expecting as such:
[{Name=John, Age=31, Address=[{Planet=Earth, Continent=Europa, Town=London},{Planet=Earth, Continent=Europa, Town=Dublin}]}]
I was try ++ and putAll but its not happy and don't allow me to do it, preferable without dw.
Technically I understand that its need to add but cant find right syntactic and help is not helpful for such :(
Thanks in advance.
Your payload is an ArrayList of HashMap, not a HashMap. Similarly your flowVars.Address is also a List. For adding it in the first HashMap of your payload you can try the following
<expression-component doc:name="Expression"><![CDATA[#[payload.get(0).put("Address", flowVars.Address)]]]></expression-component>

Removing Data Type From Tuple When Printing In Scala

I currently have two maps: -
mapBuffer = Map[String, ListBuffer[(Int, String, Float)]
personalMapBuffer = Map[mapBuffer, String]
The idea of what I'm trying to do is create a list of something, and then allow a user to create a personalised list which includes a comment, so they'd have their own list of maps.
I am simply trying to print information as everything is good from the above.
To print the Key from mapBuffer, I use: -
mapBuffer.foreach(line => println(line._1))
This returns: -
Sample String 1
Sample String 2
To print the same thing from personalMapBuffer, I am using: -
personalMapBuffer.foreach(line => println(line._1.map(_._1)))
However, this returns: -
List(Sample String 1)
List(Sample String 2)
I obviously would like it to just return "Sample String" and remove the List() aspect. I'm assuming this has something to do with the .map function, although this was the only way I could find to access a tuple within a tuple. Is there a simple way to remove the data type? I was hoping for something simple like: -
line._1.map(_._1).removeDataType
But obviously no such pre-function exists. I'm very new to Scala so this might be something extremely simple (which I hope it is haha) or it could be a bit more complex. Any help would be great.
Thanks.
What you see if default List.toString behaviour. You build your own string with mkString operation :
val separator = ","
personalMapBuffer.foreach(line => println(line._1.map(_._1.mkString(separator))))
which will produce desired result of Sample String 1 or Sample String 1, Sample String 2 if there will be 2 strings.
Hope this helps!
I have found a way to get the result I was looking for, however I'm not sure if it's the best way.
The .map() method just returns a collection. You can see more info on that here:- https://www.geeksforgeeks.org/scala-map-method/
By using any sort of specific element finder at the end, I'm able to return only the element and not the data type. For example: -
line._1.map(_._1).head
As I was writing this Ivan Kurchenko replied above suggesting I use .mkString. This also works and looks a little bit better than .head in my mind.
line._1.map(_._1).mkString("")
Again, I'm not 100% if this is the most efficient way but if it is necessary for something, this way has worked for me for now.

Apply Command to String-type custom fields with YouTrack Rest API

and thanks for looking!
I have an instance of YouTrack with several custom fields, some of which are String-type. I'm implementing a module to create a new issue via the YouTrack REST API's PUT request, and then updating its fields with user-submitted values by applying commands. This works great---most of the time.
I know that I can apply multiple commands to an issue at the same time by concatenating them into the query string, like so:
Type Bug Priority Critical add Fix versions 5.1 tag regression
will result in
Type: Bug
Priority: Critical
Fix versions: 5.1
in their respective fields (as well as adding the regression tag). But, if I try to do the same thing with multiple String-type custom fields, then:
Foo something Example Something else Bar P0001
results in
Foo: something Example Something else Bar P0001
Example:
Bar:
The command only applies to the first field, and the rest of the query string is treated like its String value. I can apply the command individually for each field, but is there an easier way to combine these requests?
Thanks again!
This is an expected result because all string after foo is considered a value of this field, and spaces are also valid symbols for string custom fields.
If you try to apply this command via command window in the UI, you will actually see the same result.
Such a good question.
I encountered the same issue and have spent an unhealthy amount of time in frustration.
Using the command window from the YouTrack UI I noticed it leaves trailing quotations and I was unable to find anything in the documentation which discussed finalizing or identifying the end of a string value. I was also unable to find any mention of setting string field values in the command reference, grammer documentation or examples.
For my solution I am using Python with the requests and urllib modules. - Though I expect you could turn the solution to any language.
The rest API will accept explicit strings in the POST
import requests
import urllib
from collections import OrderedDict
URL = 'http://youtrack.your.address:8000/rest/issue/{issue}/execute?'.format(issue='TEST-1234')
params = OrderedDict({
'State': 'New',
'Priority': 'Critical',
'String Field': '"Message to submit"',
'Other Details': '"Fold the toilet paper to a point when you are finished."'
})
str_cmd = ' '.join(' '.join([k, v]) for k, v in params.items())
command_url = URL + urllib.urlencode({'command':str_cmd})
result = requests.post(command_url)
# The command result:
# http://youtrack.your.address:8000/rest/issue/TEST-1234/execute?command=Priority+Critical+State+New+String+Field+%22Message+to+submit%22+Other+Details+%22Fold+the+toilet+paper+to+a+point+when+you+are+finished.%22
I'm sad to see this one go unanswered for so long. - Hope this helps!
edit:
After continuing my work, I have concluded that sending all the field
updates as a single POST is marginally better for the YouTrack
server, but requires more effort than it's worth to:
1) know all fields in the Issues which are string values
2) pre-process all the string values into string literals
3) If you were to send all your field updates as a single request and just one of them was missing, failed to set, or was an unexpected value, then the entire request will fail and you potentially lose all the other information.
I wish the YouTrack documentation had some mention or discussion of
these considerations.

Fiddler AutoResponder - Regular Expression to ignore timestamp in URL

I just start to use fiddler in my project for debug purpose, but haven't figure out how to handle following case with autoresponder :(
I need replace the timestamp in the request url then point to the my personal path, like
from http://www.test.com/static/20140828/js/test.js
to http://www.test.com/static/mycode/js/test.js,
while the timestamp "20140828" changing frequently so I hope can have a rule can match and handle this kind replacement automatically, without update the timestamp every time.
I tried the regex but not found the solution for this case. Any suggestions would be appreciated. Thanks.
You're right that you need to use a regular expression; you haven't said what expression you tried.
You'll probably want to use something like:
MatchText REGEX:^.*test\.com/static/\d+/(.*)$
ActionText http://www.test.com/static/mycode/$1

Possible to isElementPresent(:id, "id") in watir webdriver

Using Watir Webdriver, I wanted to have a helper that would check for any element with given id. I may not know what type it is ( button or link or text). Can I just do
browser.Element(:id, id).exists
All of the examples i've found on google check against a specific element type, as in
browser.button(:id," ").exits
If there is a way, please share the syntax.
In Watir-Webdriver, I would use something like this:
browser.element(class: 'post-tag').exists?
which would find the watir-webdriver tag on this page and report that it exists. Note that I used the 1.9 syntax instead of the alternative syntaxes of:
browser.element(:class => 'post-tag').exists?
or
browser.element(:class, 'post-tag').exists?
As Dave points out, there is #element method. (You were wrong just in capitalization, it is not #Element.)
Since you are asking about accessing it using id attribute, try this:
browser.element(:id => id)
I've never gotten .exists? to work right on it's own.
What I've had to use in these cases has been to explicitly validate the "exist?"... like:
cf_checbox = #browser.text_field(:id=>'continue-ring', :value=>true).exists?
assert( cf_description == true)
without that explicit assertion, I would always get a "true" even when the value didn't exist.