Forum Discussion

stewmoon's avatar
stewmoon
Occasional Contributor
7 years ago

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)


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"? 





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.


  • nmrao's avatar
    nmrao
    7 years ago

    stewmoon, Here you go:

     

    if (!context.testCase.name.endsWith("forbidden") {
    
     //Have your logic here
    }

     

  • 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!
    }

    • stewmoon's avatar
      stewmoon
      Occasional Contributor

      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"?

      • nmrao's avatar
        nmrao
        Champion Level 3

        stewmoon, Here you go:

         

        if (!context.testCase.name.endsWith("forbidden") {
        
         //Have your logic here
        }