Nunit assert AreEqual dif because quotes - unit-testing

I´m writing automation test for Api Rest.
In the body response to return:
"New Current Account"
I do the follow validation:
Assert.AreEqual("New Current Account", response.Content);
But it doesn´t work the Nunit return failed beacuse:
Message:
Expected string length 19 but was 21. Strings differ at index 0.
Expected: "New Current Account"
But was: ""New Current Account""
-----------^
Can someone help me?

Apparently, the string being returned actually contains quotes.
The proper way to reference this is by escaping the quotes that are part of the data in the string you use for an expected value.
Assert.AreEqual("\"New Current Account\"", response.Content);
This is preferable to using logic to trim off the quotes, because you are comparing actual to expected data without modifying either.

I resolved with follow alternative.
Assert.AreEqual("New Current Account", response.Content.Trim('"'));

Related

How to skip null and empty value while performing Regular/JSON Expression Extract?

From the below response, I need to retrieve all the values of backgroundImage field(which can be found in Debug Sampler) and by using the ForEach Controller I need to call the values fetched from backgroundImage field and pass it in the path of the next request.
I used Regular exp Extract with code "backgroundImage":"(.*?)" to extract all the non-values, but sometimes it returns empty values and in this case, it fetches just an empty "" (double code) and passes in the path of the URL which leads to an error.
How can I avoid null and empty values in this scenario?
Response:
{"data":[{"id":5031,"createdAt":1582657779000,"updatedAt":null,"contentType":"TEXT","author":{"id":32,"teamName":"Team Content","teamShirtNumber":null,"role":"TEAM_LEAD","firstName":"Team Lead Jeremiah","lastName":"Dominguez Gorrin","profilePictureReference":"aca511ec-c552-4bce-90ce-d993684c5854"},"text":"Teeeeest"},{"id":5030,"createdAt":1582657696000,"updatedAt":null,"contentType":"TEXT","author":{"id":32,"teamName":"Team Content","teamShirtNumber":null,"role":"TEAM_LEAD","firstName":"Team Lead Jeremiah","lastName":"Dominguez Gorrin","profilePictureReference":"aca511ec-c552-4bce-90ce-d993684c5854"},"text":"Sassafras"},{"id":5029,"createdAt":1582657466000,"updatedAt":null,"contentType":"TEXT","author":{"id":32,"teamName":"Team Content","teamShirtNumber":null,"role":"TEAM_LEAD","firstName":"Team Lead Jeremiah","lastName":"Dominguez Gorrin","profilePictureReference":"aca511ec-c552-4bce-90ce-d993684c5854"},"text":"Lkdsasdad"},{"id":5028,"createdAt":1582657243000,"updatedAt":null,"contentType":"POLL","author":{"id":32,"teamName":"Team Content","teamShirtNumber":null,"role":"TEAM_LEAD","firstName":"Team Lead Jeremiah","lastName":"Dominguez Gorrin","profilePictureReference":"aca511ec-c552-4bce-90ce-d993684c5854"},"text":"Umfrage mit Bild Preview Upload","minValue":0.0,"maxValue":10.0,"minLabel":null,"maxLabel":null,"sliderIcon":null,"backgroundImage":"f426549f-b1e0-4d07-8786-685fcfa28835","result":{"attendances":0,"averageValue":null,"myAnswer":null},"votingEndAt":1585090800000},{"id":5027,"createdAt":1582657195000,"updatedAt":null,"contentType":"POLL","author":{"id":32,"teamName":"Team Content","teamShirtNumber":null,"role":"TEAM_LEAD","firstName":"Team Lead Jeremiah","lastName":"Dominguez Gorrin","profilePictureReference":"aca511ec-c552-4bce-90ce-d993684c5854"}
Thanks in Advance for your knowledgeable help!
How about this:
"backgroundImage":"([^"]+)"
It repeats non double quotes character at least one.
You can go for a filter operator like:
$.data[?(#.backgroundImage != null && #.backgroundImage != "")].backgroundImage
Demo:
More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

How to match specific string in ROBOT FRAMEWORK using regex?

I am using REST-API for testing
I am stuck where I am checking the response with some specific string.
please refer below info
I got the response from a request is
{
"clusters":[
{
"id":10,
"name":"HP2",
"status":2,
"statusDisplay":"HParihar#4info.com",
"lastModifiedBy":"HParihar#4info.com",
"lastModifiedTime":"06/08/2017 23:42",
"sitesAppsCount":0
},
{
"id":799,
"name":"Regression_cluster_111_09",
"status":2,
"statusDisplay":"admin#4info.net",
"lastModifiedBy":"admin#4info.net",
"lastModifiedTime":"07/11/2017 08:19",
"sitesAppsCount":0
}
]}
and I wanted to match just
"name":"Regression_cluster_111_09",
"status":2,
"statusDisplay":"admin#4info.net",
"sitesAppsCount":0
right side values I'll be keeping as hard coded.
any guesses?
Since you are only checking those 4 parameters are in response or not.
Do no use regex for this.
Use jsonObject's find key/value feature.
Check whether the values to the keys are there.
If key/value is null, the parameter is not in response.
I got my answer
I used the following regex
"name":"Regression_cluster_111_09","status":2,"statusDisplay":"admin#4info.net","lastModifiedBy":"[a-z]+#[0-9a-z]+\.[a-z]+","lastModifiedTime":"[0-9]{2}\/[0-9]{2}\/[0-9]{4}\ [0-9]{2}:[0-9]{2}","sitesAppsCount":0
or I can simply use
"name":"Regression_cluster_111_09","status":2,"statusDisplay":"admin#4info.net",.+"sitesAppsCount":0
thank you all

Extract username from forward slash separated text

I need to extract a username from the log below via regex for a log collector.
Due to the nature of the logs we're getting its not possible to define exactly how many forward slashes are going to be available and I need to select a specific piece of data, as there are multiple occurances of similar formatted data.
Required data:
name="performedby" label="Performed By" value="blah.com/blah/blah blah/blah/**USERNAME**"|
<46>Jun 23 10:38:49 10.51.200.76 25113 LOGbinder EX|3.1|success|2016-06-23T10:38:49.0000000-05:00|Add-MailboxPermission Exchange cmdlet issued|name="occurred" label="Occurred" value="6/23/2016 10:38:49 AM"|name="cmdlet" label="Cmdlet" value="Add-MailboxPermission"|name="performedby" label="Performed By" value="blah.com/blah/blah blah/blah/USERNAME"|name="succeeded" label="Succeeded" value="Yes"|name="error" label="Error" value="None"|name="originatingserver label="Originating Server" value="black"|name="objectmodified" label="Object Modified" value="blah/blah/USERNAME"|name="parameters" label="Parameters" value="Name: Identity, Value: [blah]Name: User, Value: [blah/blah]Name AccessRights, Value: [FullAccess]Name: InheritanceType, Value: [All]"|name="properties" label="Modified Properties" value="n/a"|name="additionalinfo" label="Additional Information"
I've tried a few different regex commands but I'm not able to extract the necessary information without exactly stating how many / there will be.
blah\.com[.*\/](.*?)"\|name
Try this :
blah\.com.*\/(.*?)"\|
Check here
If your username format is this :
value="abc.xyz/something/something/..../USERNAME"
then use this :
\..*\/(.*?)"
check here
Possible solution:
value="[a-z\.\/]*\/(.*)"
(The first capture group is the username)
Working example:
https://regex101.com/r/qZ0zC8/2
Mayby like this?
blah.(\w+\/)+\K([\w]+)
It's catch Username but since it's between ** so I also match them
tested in notepad++

R: Countrycode package not supporting regex as the origin

I have a list of countries that i need to convert into standardized format (iso3c). Some have long names, others have 2 or 3 digit codes, and others do not display the whole country name like "Africa" instead of "South Africa". Ive done some research and come up to use countrycode package in R. However, when i tried to use "regex" R doesnt seem to recognize it. Im getting the error below:
> countrycode(data,"regex","iso3c", warn = TRUE)
Error in countrycode(data, "regex", "iso3c", :
Origin code not supported
Any other option I need to do?
Thanks!
You can view the README for the countrycode package here https://github.com/vincentarelbundock/countrycode, or you can pull up the help file in R by entering this into your R console ?countrycode::countrycode.
"regex" is not a valid 'origin' value (2nd argument in the countrycode() function). You must use one of "cowc", "cown", "eurostat", "fao", "fips105", "imf", "ioc", "iso2c", "iso3c", "iso3n", "p4_ccode", "p4_scode", "un", "wb", "wb_api2c", "wb_api3c", "wvs", "country.name", "country.name.de" (using latest version 0.19).
If you use either of the following 'origin' values, regex matching will be performed automatically: "country.name" or "country.name.de"
If you're using a custom dictionary with the new (as of version 0.19) custom_dict argument, you must set the origin_regex argument to TRUE for regex matching to occur.
In your example, this should do what you want:
countrycode(data, origin = "country.name", destination = "iso3c", warn = TRUE)

How to write this Regular Expression

How do i write a regular expression which accepts only value "1" in the textbox
and it should not accept zero or greter than "1"
if (theTextBoxValue == "1") {
// accept
} else {
// reject
}
You don't need regex for this simple task. And, if you only accept "1" in a user input, why provide such an input to the user at all?
/^1$/
… but for a "Must be this value, exactly this value, and nothing but this value" test, you would be much better off with a simple string comparison.
/^1$/ but a simple == "1" will be enough in most languages (or .equals("1")).
I saw your previous question (using the jquery validationEngine), and I was intrigued by it so I started looking.
The problem with using a funcCall (as you were trying in the old post) is that the function is called without any context (has no arguments, and has this == window), so you can't tell which input field is being validated.(I solved this with a trick - see example & comments linked below).
Another solution I found was using regex(as you are trying now).
This is the entry you have to add to the languages file:
"isOne":{
"regex":"/^1$/",
"alertText":"* Only '1' is valid [regex]"
}
This is how you use it on the input field:
<input type="text" class="validate[custom[isOne]]">
And this is how you start the validation engine:
$('#form').validationEngine({
validationEventTriggers:"change"
});
You can view a working example using both function and regex here
Don't think you want to use regex for this.
Pattern: ^1$