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
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)') } } } } } }