SoapUI XPath assertion with wildcards - xpath

Is there a way to use a wildcard inside an assertion in a XPath test with SoapUI?
I took a look at SoapUI's documentation and they say you can do something like this
<path1>
<path2>*</path2>
</path1>
I checked the 'Allow Wildcards' checkbox.
My question is : I want to assert my date starts with 2012-08-22 but i dont care about the minutes and seconds. I guess my the expression should be something like 2012-08-22* but it doesn't work.

What you are doing sounds like it should work. Here is a quick example i cooked up using a rest service from http://www.geonames.org/export/web-services.html#timezone. I'm using the demo they have supplied
http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo
output is
<geonames>
<timezone tzversion="tzdata2012c">
<countryCode>AT</countryCode>
<countryName>Austria</countryName>
<lat>47.01</lat>
<lng>10.2</lng>
<timezoneId>Europe/Vienna</timezoneId>
<dstOffset>2.0</dstOffset>
<gmtOffset>1.0</gmtOffset>
<rawOffset>1.0</rawOffset>
<time>2012-07-25 04:39</time>
<sunrise>2012-07-25 05:50</sunrise>
<sunset>2012-07-25 21:00</sunset>
</timezone>
</geonames>
If you do an xpath match on the result and use the select from current button you get
//geonames/timezone/time
2012-07-25 04:39
If you update this to
//geonames/timezone/time
2012-07-25*
this will work fine and when updating the rest request with a new lat and lng the assertion will still pass since it is not checking the time. If this doesn't help, please supply your full assertion and maybe i could help more.
*note: for soap requests, make sure to declare the namespace and then use the proper format
//ns1:message

It will be sort of a pain, but here is what you can do:
1) Figure out an Xpath 'base' using the assertion tab (sounds like you are here already). I used this public site to test against: http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl
I used the CornerPoints method with 'hawaii' as the single param.
I created this 'base' xpath:
declare namespace ns1='http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl';
declare namespace SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/';
declare namespace SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/';
/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:CornerPointsResponse/listLatLonOut
(it will write the declare statements for you if you click declare)
(which you can test out in the assertions window)
2) Create a Properties step
3) Create a Property transfer step
4) Create a groovy script
5) add a property... i called mine misc
6) add a transfer step
* transfer from the CornerPoints - Request 1 --- Response
* paste the Xpath stuff in the box under the 'transfer from'
* Transfer to your property
(You can test with the little play button)
7) Add something like this to your groovy script:
def x = context.expand( '${Properties#misc}' )
def parts = x.tokenize(',')
for (def part in parts)
{
log.info(part)
if (part.startsWith("-153"))
log.info("good")
}
In the groovy step you can do anything you need to get at your (partial) data. The sample code I added gets lat/lons out of a long line wrapped in CDATA and then checks for just the starting part of some of the data.. just an example.
Remember that you can use groovy and java string methods:
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html
More groovy tips:
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html

Related

Using XPATH in jmeter - based on parent

I have a xml file having the following structure:
<subscriberDetailsItem>
<externalSubId>911</externalSubId>
<paymentIndicator>2</paymentIndicator>
<IMSI>302</IMSI>
<MSISDN>416</MSISDN>
<status>A</status>
<outSubscriptionDetails>
<subscriptionDetailsItem>
<socId>ABCDEF</socId>
<featureCode>GHIJKL</featureCode>
<startDate>20180720000000</startDate>
<featureSeq>47452111</featureSeq>
<subscriptionType>DATA</subscriptionType>
<shareGroupCd>SHARE</shareGroupCd>
<initialValueBytes>1073741824</initialValueBytes>
<priority>3000</priority>
<balanceType>BAL</balanceType>
</subscriptionDetailsItem>
</outSubscriptionDetails>
</subscriberDetailsItem>
I want to be able to extract the socID field based on the externalSubId field. Essentially, I want to be able to do this:
if externalSubId=911, then, extract SOCID. Anyone has tips?
You didn't specify where would you want to extract it, so I assume you can use XPath Extractor as a post-processor to some sampler that reads that file.
You configure post-processor like this:
XPath Query can be built like this:
Select subscriberDetailsItem that has externalSubId with the value you want:
//subscriberDetailsItem[externalSubId=911]
Select socId either by using absolute path:
//subscriberDetailsItem[externalSubId=911]/outSubscriptionDetails/subscriptionDetailsItem/socId
or you can omit entities in the middle if socId cannot be found elsewhere in the item:
//subscriberDetailsItem[externalSubId=911]//socId

nightwatchjs, run same test on multiple pages

I have written some tests for my homepage but the tests are very generic, like footer, header checking.
My test structure is like:
const footerCheck = function(browser){
browser.url("example.com");
browser.verify.elementPresent(".footer-top", "Footer-top is present.")
browser.verify.elementPresent(".footer-middle", "Legal notice bar is present")
browser.verify.elementPresent(".footer-bottom", "Copyright bar is present")
}
export.module = {
"Footer Check" : footerCheck
}
Lets say I have 100 pages. I would like to run footerCheck function run on all hundred pages.
URLs like example.com/page1 , example.com/page2 , example.com/page3...
Since all the tests are valid for other pages I would like to loop all pages for the same test cases. Somehow could not get my head around it.
How is that possible, any help would be appreciated.
Thanks
In my personal experience, the best way to do BDD is adding cucumber that uses gherkin syntax. It is clearer and helps a lot to reduce redundant code if you know to use it well. There is a Nightwatch npm plugin to add cucumber, once you have added it you have to create your .feature file like the following
Feature: Check elements are present
Scenario Outline:
Given the user enters on a <page>
Then .footer-top, .footer-middle and .footer-bottom class should be enabled
Examples:
|page|
|page.com/page1|
|page.com/page2|
|page.com/page3|
And your step definitions (where you declare what will do each step) it automatically will run each step for each url provided in the examples (note the <page> flag that will be replaced on the example, first row is the name of the tag).
Take a look to the examples

How do I validate responses with Gauge (getgauge.io)?

I've looked in the documentation and sample C# project: http://getgauge.io/documentation/user/current/
However, I'm not sure how to validate the response from a "Step". Maybe Gauge isn't the right tool for this but I'm trying to validate the format of a JSON response for instance.
On their standard "StepImplementation" class, I can see the following method. I added 'return "blah";' to the end:
[Step("Say <what> to <who>")]
public string SaySomething(string what, string who)
{
Console.WriteLine("{0}, {1}!", what, who);
return "blah";
}
And of course in the spec file:
First scenario
--------------
tags: hello world, first test
* Say "hello" to "gauge"
* Check if "blah" is returned from SaySomething
It fails on that last line because the Step isn't defined (duh). But, what I really want is something like - Say "hello" to "gauge" and expect "blah".
Yeah... Apparently I wasn't fully understanding the power of Gauge and what it is designed to do. The answer to my silly question is:
Use your favorite testing framework and use Asserts. Those Assert failures will show up on the Gauge reports (even though those Asserts aren't actually coming FROM Gauge - errors will fail the Scenario/Step too). Whether you are using C# or Java, just assume that Gauge is your test runner I guess, and you can do whatever you want for validation.

Automatic Step Generation in cucumber javascript using javascript

I am using javascript for cucumber javascript for automation.My concern is can i generate .js file for step definitions automatically? as of now am copy pasting them(steps) from command line window so can I skip it and directly generate the step file?
Two Suggestions:
1.
You can create a new gherkin file, and run it with cucumber.js, it will generate JavaScript stub automatically for you. For example:
"cucumber-js math.feature"
It will output something like:
1) Scenario: easy maths - math.feature:7
Step: Given a variable set to 1 - math.feature:8
Message:
Undefined. Implement with the following snippet:
this.Given(/^a variable set to (\d+)$/, function (arg1, callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
It has the parameter automatically generated based on your tests. You can then copy the snippet into your code file.
2.
If you are using Windows 10, you can also try a BDD development tool CukeTest, and it provide some convenient features like code generation from step text, or navigate between code and steps etc.
You can use 'Live Template'/'Code snippets' in your IDE. It's the best way to improve performace.
https://www.jetbrains.com/help/idea/creating-code-constructs-by-live-templates.html
If you use VC Code then you can use extension Cucumber (Gherkin) Syntax and Snippets:
https://marketplace.visualstudio.com/items?itemName=stevejpurves.cucumber

How to make jmeter while controller work

I'm having trouble getting the while controller to work in jmeter.
I've a feeling that I read that it doesn't re-evalute user defined variables, so I am trying to use properties instead.
I start off by using a BSF assertion to set a property called keepLooping
${__setProperty(keepLooping, true)};
This seems to work as it enters the While controller with a condition of
${__property(keepLooping)}
But I cannot for the life of me get it to change that property to something else. I want it to change the property depending on the resulting text of an http request.
So I am using a Regular Expression Extractor to set a variable, which I can see is getting set. Then I am trying to use a BSF assertion to set the keepLooping property on the basis of the variable that I have set. I am using javascript as follows:
log.info("IM IN HERE");
log.info("props is "+props);
//log.info("props keep looping is "+props["keepLooping"]);
if (${surveyRequired} == false){
log.info("IM IN HERE 1A and props is "+props);
${__setProperty(keepLooping, true)};
log.info("IM IN HERE 1B");
}
else {
log.info("IM IN HERE 2A");
${__setProperty(keepLooping, false)};
log.info("IM IN HERE 2B");
}
I can't figure out how to set the property with javascript - I've tried several things. Can anyone help? Many thanks!
Also can anyone recommend a good resource that negotiates what seem to be the many 'quirks' of jmeter? Many thanks!
"I've a feeling that I read that it doesn't re-evalute user defined variables" -- I use JMeter 2.9 and it really does. I use user defined variable in order to count number of loops. It looks like: ${__javaScript(${MY_USER_DEFINED_VARIABLE}>0)}. The only one annoying thing is that I have to get value of variable, increment it, cast to string (toString() in Groovy), and then put new value into MY_USER_DEFINED_VARIABLE (by using vars.putObject("MY_USER_DEFINED_VARIABLE",localBSFVariable))
Using vars.put or props.put will help, as explained in detailed in detail in this jmeter thread.

Resources