Reply
Occasional Contributor
Accepted Solution

RequestFilter.filterRequest Script applied to only specific Test Cases

hello,

 

I have a Project in SoapUI that contains lots of Test Cases.  I have created a Event Handler Script to add a Header to the Rest Requests that uses the RequestFilter.filterRequest Event. 

My problem is I want to apply the Event script to ALL Test Cases that do not end in the words "- forbidden" 
(See photo below)
TestCasesNotNamed.PNG

How should I go about this problem?  If I use the field 'Target' in the Event Handler? If so how do I filter using test cases names that end in "- forbidden"? 

EventHandler Script.PNG



If I try and include in the logic of the Event Handler to check if the Test Case name, I'm unable to access the TestRunner to access the test case name.


Highlighted
Contributor

Re: RequestFilter.filterRequest Script applied to only specific Test Cases

In requestFilter.FilterRequest:

 

 


String tcName = testRunner.getTestCase().getName()
log.info "test case name is " + tcName
String str2 = new String("forbidden")
if (!tcName.toLowerCase().contains(str2.toLowerCase()) )
{
log.info "allowed"
// handle event
}
else
{
log.info "forbidden"
// well...Bye!
}

Occasional Contributor

Re: RequestFilter.filterRequest Script applied to only specific Test Cases

[ Edited ]

Hey thank you for that code, I'm running into an issue when I'm running the event script with a test case and I'm trying to get the test case name.
(see photo)

Do I need to import some type of package in order to use "testRunner"?

Posts: 5,067
Registered: ‎05-17-2013

Re: RequestFilter.filterRequest Script applied to only specific Test Cases

[ Edited ]

@stewmoon, Here you go:

 

if (!context.testCase.name.endsWith("forbidden") {

 //Have your logic here
}

 

Occasional Contributor

Re: RequestFilter.filterRequest Script applied to only specific Test Cases

 hi nmaro,

 

Thank you very much for that solution that fixed my issue with getting the test case name when not using the testrunner.

I have two questions:

 

1.  What resources did you use to get this answer?    I looked at the http://www.soapui.org/apidocs/overview-summary.html to try and find what methods are avaiable for that class, but was unable to find the solution there.


2.  How can I check if there is already a Header named "X-Active-Customer-ID" present within the request.

thank you!!

Posts: 5,067
Registered: ‎05-17-2013

Re: RequestFilter.filterRequest Script applied to only specific Test Cases

Glad that helped.
Rearding #1, please go thru thread below:
https://community.smartbear.com/t5/SoapUI-Open-Source/How-to-read-and-use-SoapUI-API-for-non-Dev-peo...

Regarding #2, encourage you to create a new thread with details.