Forum Discussion

JoostDG's avatar
JoostDG
Frequent Contributor
3 years ago

How to set "store locally" to default = true (or how to set it via groovy script)

Hi,

I am trying to get store ALL of my properties locally (see https://support.smartbear.com/readyapi/docs/testing/properties/local-properties.html). This because a simple run of my tests dynamically changes my properties values and the track change always shows a zillion changes, while in fact, those are just property value changes, no test case changes. 

I could go and check all of my testSuite & testCase properties checkboxes manually (one-by-one), but it's 2022 and don't want to ruin it ðŸ˜‹

As far as I know there is no way to set a default "store all properties locally" option. There should be this option imho, since I believe all properties are set at runtime, independently from where they are run (physically or environment). Any "hardcoded" properties that you want to use should NOT go directly in the custom properties fields in ReadyAPI, but instead (if really needed) I write them in a setup script with a setPropertyValue("hardcodedProperty", "xValue"). 

 

My goal is 2-folded: I want to be able to set all existing properties and all future properties that I'll create also to "store locally" (= "userSpecific" = true). 

 

I tried to use below self-made groovy script snippet, but that resulted in error Caused by: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap$Entry.setUserSpecific() is applicable for argument types: (Boolean) values: [true]

From the apiDocs I can't find any way of adjusting the userSpecific values...

 

 

for( prop in testCase.properties) {
     prop.setUserSpecific(true)
   }

 

 

 

Any pointers anyone?

  • JoostDG's avatar
    JoostDG
    3 years ago

    Thanks DLeidelmeijer !

    Your solution works, I did needed a little adaptation to get it working for both test suite & test case properties. Below a project setup script that makes sure that each time it runs ALL properties (excluding of course project properties) are set to save locally.

    Cheers!

     

    EDIT: You might also add this to the "save script" via project-settings, as technically speaking it's more fit to be set there than in the project setup script. On the  save script: You might need to disable the checkbox in your preferences as otherwise you get the message "Save script might contain malicious code...". It's not clear to me why, or why this save script feature is so very hidden...

     

    project.testSuiteList.each { suite ->
    //Set all testSuite properties to "userSpecific" = true. We store value locally so it will not be saved into the GIT track changes.
    	for (prop in suite.getPropertyList()){
    	prop.setUserSpecific(true)
    	}
    //Set all testCase properties to "userSpecific" = true. We store value locally so it will not be saved into the GIT track changes.
    //note: We cannot use the wording "case" in below for each as "case" is reserved when we use a project setup script, so we use here "testkase" 
    	suite.testCaseList.each { testkase ->
    		for (prop in testkase.getPropertyList()){
    		prop.setUserSpecific(true)
    		}
    	}	
    }

     

     

     

  • Hi,

     

    I was also struggling with this but your post has put me on the right track. This works for me:

     

    def Suite = '<TestSuitename>'
    def tSuite = testRunner.testCase.testSuite.project.getTestSuiteByName(Suite)
    tSuite.testCaseList.each
    { Case ->
    for (prop in Case.getPropertyList())
    {

    prop.setUserSpecific(true)

    }
    }

    • JoostDG's avatar
      JoostDG
      Frequent Contributor

      Thanks DLeidelmeijer !

      Your solution works, I did needed a little adaptation to get it working for both test suite & test case properties. Below a project setup script that makes sure that each time it runs ALL properties (excluding of course project properties) are set to save locally.

      Cheers!

       

      EDIT: You might also add this to the "save script" via project-settings, as technically speaking it's more fit to be set there than in the project setup script. On the  save script: You might need to disable the checkbox in your preferences as otherwise you get the message "Save script might contain malicious code...". It's not clear to me why, or why this save script feature is so very hidden...

       

      project.testSuiteList.each { suite ->
      //Set all testSuite properties to "userSpecific" = true. We store value locally so it will not be saved into the GIT track changes.
      	for (prop in suite.getPropertyList()){
      	prop.setUserSpecific(true)
      	}
      //Set all testCase properties to "userSpecific" = true. We store value locally so it will not be saved into the GIT track changes.
      //note: We cannot use the wording "case" in below for each as "case" is reserved when we use a project setup script, so we use here "testkase" 
      	suite.testCaseList.each { testkase ->
      		for (prop in testkase.getPropertyList()){
      		prop.setUserSpecific(true)
      		}
      	}	
      }