determine the type of a request programmatically
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
determine the type of a request programmatically
Hello,
I'm trying to find a way, by groovy scripting, to determine which is the type of a request in my project (PUT, POST, GET, etc.). I could only go as far as parsing the step and get its rest method (getRestMethod() on a RestTestRequestStep but it does not always give me relevant information.
for some of my APIs it gives setterXX or getterYY which is exactly what I need but for many others it does not give this type of information.
is there a property that clearly provide this information ?
thank you
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have to types of requests. For rest requests, it can do 'getRestMethod' which gives information containing 'setter' or 'getter' or, at least, a string that contains the information. It's not straightforward but it works.
The problem is with http requests, in fact I found the information in the config data of the request (which is a xml structure) but I do not manage to parse it correctly.
I can get the highest level information by just pointing to it, ie. config.type = httprequest, I can also get name, id ... but the config method is not at the same level.
I get this information, which is a class com.eviware.soapui.config.impl.TestStepConfigImpl
<xml-fragment type="httprequest" name="Request 1" id="373fc2ed-1b98-4ce7-9695-dfcca6469ce8" xmlns:con="http://eviware.com/soapui/config"> <con:settings/> <con:config method="PUT" xsi:type="con:HttpRequest" id="b85fadf8-b989-4b71-ba0b-f0c5aa73e5b4" name="Request 1" postQueryString="false" mediaType="application/json" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <con:settings> <con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><entry key="Accept" value="application/json" xmlns="http://eviware.com/soapui/config"/></con:setting> </con:settings> ...
How can I get the config method field content ?
I tried to use xmlparser and xmlslurper but it does not accept the data from TestStepConfigImpl object.
Is there a way to cast it ? is there a particular way to use xmlparser or slurper to achieve this ?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@krogold , any luck with solving this?
Sonya Mihaljova
Community and Education Specialist
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
well, so far no 😞
it's not critical though, I'll try to investigate this thoroughly when I'll have more spare time
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The script you came up with so far, though it is not working? Would help to understand the issue.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it's just that I have some REST requests and some HTTP requests, and I'd like to determine the type of request (GET or PUT) in order to initialize properties and other features for each requests
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is my understanding:
If you have the test step already added to the test case, all the properties such as parameters if GET or request body if POST or PUT being inherited from service definition. So it is easy if the context or test case structure,
Where you are trying to write the code along with what you have currently would help to understand it better?
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
finally I found out the information.
unfortunately, in the project under test, som PUT requests are, in fact, get requests so I have an additional test to do to determine the 'functional' role of the request.
To get the rest method of a REST request step :
testRunner.testCase.testSuite.project.testSuiteList.each
{
suite ->
name = suite.getName()
suite.testCaseList.each{
TC ->
log.info "test case ****** " + TC.getName()
TC.testSteps.each{
if (it.getValue().config.type.equals("restrequest"))
{
method_functional_type = "unknown"
method_functional_type = it.getValue().getRestMethod().getMethod().toString() // provides 'PUT', 'GET', etc.
if (method_functional_type != "GET")
{
// do an additional check
// ie. the API /m2m/fim/items/fim:users:settings:manager/operations/getServerTimestamp
// it is a PUT request but it is senseless to not use the output
op = it.getValue().getOperation().toString()
if (op.split("\\/")[-1].take(3) == "get")
{
// the PUT request returns relevant data that has to be used
method_functional_type = "GET"
}
}
if (method_functional_type == "GET")
{
if (TC.tearDownScript == null){
log.info "update teardown script for $name - ${TC.name}"
// if there is no teardown script available, set the generic teardown script for GET API's
TC.setTearDownScript('testCase.setPropertyValue("testResponse", context.response)')
}
}
}
}
}
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@krogold Great job figuring this one out! Kudos!
Sonya Mihaljova
Community and Education Specialist
