I'm trying to do this:
stubFor(get("/my/path")
.withQueryParam("paramName", matching(format("^(%s)|(%s)|(%s)$", v1, v2, v3)))
.willReturn(okJson(RESPONSE)));
and I get this error:
GET | GET
/my/path | /my/path?paramName=v1Value <<<<< URL does not match
|
Query: paramName [matches] ^(v1Value)|(v2Value)|(v3Value)$ | paramName: v1Value
I have tested the regex and it works. I also debugged and I saw that the RegexPattern also matches. But for some reason, I still get this error. I believe I'm using it wrongly.
I tried a simpler version that also didn't work:
stubFor(get("/my/path")
.withQueryParam("paramName", equalTo("v1Value"))
.willReturn(okJson(RESPONSE)));
Any ideas? Thanks in advance.
WireMock documentation recommends matching on url path only and matching on query parameters separately.
That would look something like...
stubFor(get(urlPathEqualTo("/my/path"))
.withQueryParam("paramName", matching(format("^(%s)|(%s)|(%s)$", v1, v2, v3)))
.willReturn(okJson(RESPONSE)));
If I recall correctly, just using stubFor(get("my/url")) defaults to using urlEqualTo, which checks equality matching on path and query parameters
Related
I'm trying to allow users to paste a list that is separated by , ; or | using ngx-chips.
There is an option to do this with pasteSplitPattern - [?string | RegExp]
https://github.com/Gbuomprisco/ngx-chips
When I try the following though, I get an error
[pasteSplitPattern]="[,|;]"
Parser Error: Unexpected token ,
What should I be doing differently?
Try using the following:
Define a new regex :
splitPattern = new RegExp('[\,\;]');
and then use it in your template:
[pasteSplitPattern]= "splitPattern"
I had the same problem : you have to add [addOnPaste]="true" to make it work!
use the below to separate by comma or enter
[separatorKeyCodes]="[32, 188]"
Faceted search is giving me problems when the facet name includes special characters - specifically /, (, and ). I am trying to replace special characters using the handlebars helpers built into Stencil. I keep getting a 500 error any time I use the replace handlebar helper.
npm's documentation example:
{{replace "Liquid Snake" "Liquid" "Solid"}}
Even using that exact bit of code (simple Strings, not variables), I get the 500 error.
Here's the log:
Debug: internal, implementation, error
TypeError: Uncaught error: options.inverse is not a function
at Object.<anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/#bigcommerce/stencil-paper/helpers/replace.js:19:28)
at Object.template.1 (eval at <anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/#bigcommerce/stencil-paper/index.js:71:44), <anonymous>:11:72)
at Object.prog [as fn] (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/handlebars/dist/cjs/handlebars/runtime.js:193:15)
at Object.<anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/#bigcommerce/stencil-paper/helpers/if.js:85:28)
at Object.template.main (eval at <anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/#bigcommerce/stencil-paper/index.js:71:44), <anonymous>:70:35)
at Object.ret [as components/faceted-search/facets/multi] (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/handlebars/dist/cjs/handlebars/runtime.js:159:30)
at Object.<anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/#bigcommerce/stencil-paper/helpers/dynamicComponent.js:32:50)
at Object.template.7 (eval at <anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/#bigcommerce/stencil-paper/index.js:71:44), <anonymous>:33:109)
at Object.prog [as fn] (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/handlebars/dist/cjs/handlebars/runtime.js:193:15)
at Object.<anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/#bigcommerce/stencil-cli/node_modules/#bigcommerce/stencil-paper/helpers/if.js:85:28)
I think you are looking at the documentation for the wrong replace helper. The helper library you are using is from BigCommerce and its replace helper is a Handlebars Block Helper. The way to use it would be:
{{#replace "Liquid" "Liquid Snake"}}Solid{{/replace}}
Edit
Thanks for pointing out that I had incorrectly wrapped the replacement string in my example in mustache brackets. I have replaced {{"Solid"}} with Solid in my original code block, so the example is now correct.
As to your follow-up about there being no output when the string to be replaced (the needle) is not found in the target string (the haystack): It turns out that this is the designed behavior of the helper. I have checked the source code, and I can confirm that it implements the following rules:
If the haystack contains the needle, return the haystack with all instances of the needle replaced.
If the haystack does not contain the needle, return the else branch of the helper.
This means that if we want to display any output, like the original haystack, when there are no matches of the needle within the haystack, then we must do so with an else branch in our template:
{{#replace "Liquid" "Liquid Snake"}}Solid{{else}}Liquid Snake{{/replace}}
Truthfully, this does seem like a quite awkward implementation of this helper.
Wanting to capture a variable called scanNumber in the http response loking like this:
{"resultCode":"SUCCESS","errorCode":null,"errorMessage":null,"profile":{"fullName":"TestFirstName TestMiddleName TestLastName","memberships":[{"name":"UA Gold Partner","number":"123-456-123-123","scanNumber":"123-456-123-123"}]}}
How can I do this with a regular experssion?
The tool I am using is Gatling stress tool (with the Scala DSL)
I have tried to do it like this:
.check(jsonPath("""${scanNumber}""").saveAs("scanNr")))
But I get the error:
---- Errors --------------------------------------------------------------------
> Check extractor resolution crashed: No attribute named 'scanNu 5 (100,0%)
mber' is defined
You were close first time.
What you actually want is:
.check(jsonPath("""$..scanNumber""").saveAs("scanNr")))
or possibly:
.check(jsonPath("""$.profile.memberships[0].scanNumber""").saveAs("scanNr")))
Note that this uses jsonPath, not regular expressions. JsonPath should more reliable than regex for this.
Check out the JsonPath spec for more advanced usage.
use this regex to match this in anywhere in json:
/"scanNumber":"[^"]+"/
and if you want to match just happens in structure you said use:
/\{[^{[]+\{[^{[]+\[\{[^{[]*("scanNumber":"[^"]+")/
Since json fields may change its order you should make your regex more tolerant for those changes:
val j = """{"resultCode":"SUCCESS","errorCode":null,"errorMessage":null,"profile":{"fullName":"TestFirstName TestMiddleName TestLastName","memberships":[{"name":"UA Gold Partner","number":"123-456-123-123","scanNumber":"123-456-123-123"}]}}"""
val scanNumberRegx = """\{.*"memberships":\[\{.*"scanNumber":"([^"]*)".*""".r
val scanNumberRegx(scanNumber) = j
scanNumber //String = 123-456-123-123
This will work even if the json fields will be in different order (but of course keep the structure)
I'd like to setup a JMeter test plan to suggest whether a web site (URL) is Drupal-based (based completely on the HTTP response from the site) and compare it with existing data that I have on the environment. (I realize that using an HTTP approach, as opposed to say examining the site's file system, is "iffy" but I'm curious how useful the approach is)
The JMeter command line might look like this:
JMeter -t "DrupalAssertions.jmx" -Jurl=http://my.dot.com -Jdrupal=true
where I provide the URL to test and an additional property "drupal" indicating my best guess on whether the site is Drupal-based.
In my test plan, I add an HTTP Request to return the HTML content of the page for the URL. I'm then able to successfully add a Response Assertion that tests a pattern (say (?i)(drupal) for a sadly lacking pattern) to see if it's contained in the response.
That much works fine, or as expected, but what I'd like to do is to compare the value of the "drupal" property against the result of that pattern test in that same Response Assertion. I know I'm missing something simple here, but I'm not seeing how to do that.
I want to try to use an expression like this:
(?i)(drupal) == ${__P(drupal)}
in a pattern, but that doesn't work. The name of the Compare Assertion looks promising, but I don't see how to incorporate the property into a comparison.
Update: The approach suggested by PMD UBIK-INGENIERIE does work. I used a Regular Expression Extractor like this:
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Extract Drupal in Response" enabled="true">
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
<stringProp name="RegexExtractor.refname">drupalInResponse</stringProp>
<stringProp name="RegexExtractor.regex">(.*drupal.*)</stringProp>
<stringProp name="RegexExtractor.template">$0$</stringProp>
<stringProp name="RegexExtractor.default">__false__</stringProp>
<stringProp name="RegexExtractor.match_number">1</stringProp>
</RegexExtractor>
followed by this BeanShell Assertion:
// Variable "drupalInResponse" is "__false__" by default
if ( !(vars.get("drupalInResponse").equals("__false__") ) ) {
vars.put("drupalInResponse","true");
}
else {
vars.put("drupalInResponse","false");
}
print("\n\nThe value of property 'drupal' is: " + props.get("drupal") + "\n");
print("\n\nThe value of variable 'drupalInResponse' is: " + vars.get("drupalInResponse") + "\n");
if (vars.get("drupalInResponse").equals( props.get("drupal") ) ) {
print("Site Drupalness is consistent with your beliefs");
}
else {
print("You're wrong about the site's Drupalness");
Failure = true;
FailureMessage = "Incorrect Drupal assumption";
}
In the Regular Expression Extractor, I'd set a default value that I felt wouldn't be matched by my pattern of interest, then did an ugly verbose Java comparison with the "drupal" property in the BeanShell Assertion.
Wish somehow that the assertion could be made in a single component rather than it having two parts, but you can't argue with "working" :)
You can use a regexp extractir with your first pattern
Then use a Beanshell assertion which will use your variable and compare it to drupal property.
I need some help with a regular expression, please help if you can
I have the following code: I am using Javascript and ASP
{In|inside|during|into|in the sphere
of} {this} {article|piece of
writing|editorial|commentary|paragraph|section}
{we} {will|desire to|wishto|want
to|resolve to|will} {tell} {you}
{more} {about|regarding|with reference
to} {the}
The desired code should look like this:
{In|inside|during|into|in the sphere
of} this {article|piece of
writing|editorial|commentary|paragraph|section}
we {will|desire to|wishto|want
to|resolve to|will} tell you
more {about|regarding|with reference
to} the
The brackets around the single words with no | should be removed like - this - we - tell you more - the in the example above.
I am thinking that the solution should be something like this
replace(/{.+?[^\|]/ig, '');
to replace the { there should not be a | in the code; {.+?[^\|] and replace { with nothing
Then if there is not a starting { to replace the } with nothing
I am not sure how to do this, and how to only remove the {} where there is no | inside without removing the content...
x.replace(/{([^|}]*)}/g, '$1')
Try:
var string = "{hello|there} {yes} {no|me} {ok}";
string = string.replace(/{[A-Za-z0-9]+)}/g, "$1");
Gives you:
{hello|there} yes {no|me} ok