Forum Discussion

vikititor's avatar
vikititor
Contributor
4 years ago
Solved

Clean TC and TS propertis when saving project

I am using the ReadyAPI and GIT. I wnat to have all the properties visible to me during developing the tests = I dont want to enable the new settins in preferences (to clean properties after test case run).

Now a tons os tests are created.. there are some properties used in test case level or test suite level.. 

When commited in to GIT, next time the values will be changed.. So in next commit will be visible in each TC update..

How to solve the problem:

 

Enable script when project saving.. 

def project = testRunner.testCase.testSuite.project

log.info "start"
for ( t in testRunner.testCase.testSuite.project.getTestSuiteList() ) {
	log.info " -s " + t.name 
	//log.info "-suite propertis count: " + t.getPropertyCount()
	
	for ( c in t.getTestCaseList() ) {
		log.info " --tc " + c.name
		//log.info " -- suite propertis count: " + c.getPropertyCount()
		
		if (c.getPropertyCount() > 0) {
			
			for( n in c.propertyNames ){
				log.info " --- tcp " + n + " value: " + c.getPropertyValue(n)
				if (n == "countDown") {
					c.setPropertyValue( n, '0')		
					}  					
					else {
						c.setPropertyValue( n, '')
						}
				}
			}	   	
		}
	}

log.info "done"

 

I am not the groovy expert.. just validator.. But I spend searching of the solution on internet half of a day.. So I hope.. I can save some energy to the others.

Because even here were some scripts foundable.. but with errors.. 

This script works. 

  • in the project save script remove line with "def project".. 

    and enable save/load scripts in ReadyAPI preferences

  • Here is updated script, you can even filter the propertie name, when for example insluce # prefix in the name.. so skip the clening.. 

     

    Here is full script for project = will not work under groovy script test step.. 

    log.info "*********** SAVE PROJECT script ***********";
    log.info "Cleaning the properties values - start"
    for ( t in project.getTestSuiteList() ) {
    	log.info " -s " + t.name 
    	//log.info "-suite propertis count: " + t.getPropertyCount()
    	
    	for ( c in t.getTestCaseList() ) {
    		log.info " --tc " + c.name
    		//log.info " -- suite propertis count: " + c.getPropertyCount()
    		
    		if (c.getPropertyCount() > 0) {
    			
    			for( n in c.propertyNames ){
    				log.info " --- tcp " + n + " value: " + c.getPropertyValue(n)
    				if (n.substring(0,1) != "#"){
    					if (n == "countDown") {
    						c.setPropertyValue( n, '0')		
    						}  					
    					else {
    						c.setPropertyValue( n, '')
    						}
    					}
    				else
    					{log.info " ---- cleaning skipped"}				
    				}
    			}	   	
    		}
    	}
    
    log.info "Cleaning the properties values - finished"

3 Replies

  • in the project save script remove line with "def project".. 

    and enable save/load scripts in ReadyAPI preferences

      • vikititor's avatar
        vikititor
        Contributor

        Here is updated script, you can even filter the propertie name, when for example insluce # prefix in the name.. so skip the clening.. 

         

        Here is full script for project = will not work under groovy script test step.. 

        log.info "*********** SAVE PROJECT script ***********";
        log.info "Cleaning the properties values - start"
        for ( t in project.getTestSuiteList() ) {
        	log.info " -s " + t.name 
        	//log.info "-suite propertis count: " + t.getPropertyCount()
        	
        	for ( c in t.getTestCaseList() ) {
        		log.info " --tc " + c.name
        		//log.info " -- suite propertis count: " + c.getPropertyCount()
        		
        		if (c.getPropertyCount() > 0) {
        			
        			for( n in c.propertyNames ){
        				log.info " --- tcp " + n + " value: " + c.getPropertyValue(n)
        				if (n.substring(0,1) != "#"){
        					if (n == "countDown") {
        						c.setPropertyValue( n, '0')		
        						}  					
        					else {
        						c.setPropertyValue( n, '')
        						}
        					}
        				else
        					{log.info " ---- cleaning skipped"}				
        				}
        			}	   	
        		}
        	}
        
        log.info "Cleaning the properties values - finished"