Forum Discussion

Necraatall's avatar
Necraatall
New Contributor
5 years ago

How to save log.info/error/warning from groovy test step

Hi, 

I have big groovy script usable in both SoapUI Free and SoapUI pro. 

i have there lots of Log Outgoing

how to save them by groovy script? 

all logs i found and try some kudos have result like this:

/***********************enum test*************/
import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
// firsthly def ArrayList - enums
// this enums is available for change if another enums will change, dont change another part of code
List<String> country = new ArrayList<String> (["MK", "AD", "AE", "AF"])
//, "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "CH", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"])

log.info "!!!!!!!Dont stop this Test Step!!!!!!!!!"
log.info "!!!!!!!Dont change this Test Step when run!!!!!!!!!"
log.info "!!!!!!!Wait for results at least 10 minutes!!!!!!!!!"

//def actual test Case and Test STep 
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def testCase = testRunner.testCase;
def testStep = testCase.getTestStepAt(context.currentStepIndex + 2);

//set property country with value item into TestCase
testRunner.testCase.setPropertyValue("country", country[0])
   //log.info testStep + ": " + country[0]
   
//now run test step (will be run by count of enum values)
testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null);
testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
testStep.run(testRunner, testStepContext);

// here we detect if test case were failed (when is not firsth if, then list all assertion test steps in test case, is usable as Tear Down Script too)
def StepList = testCase.getTestStepList()

if (country != country[0] && country[0] != null){
	StepList.each{
    		if(it.metaClass.hasProperty(it,'assertionStatus')){
        		if(it.assertionStatus != AssertionStatus.FAILED){
            		log.error "${it.name} FAIL with value of: " + item
		    		return;    		
        			}
        			else if(it.assertionStatus == AssertionStatus.VALID){
            		log.info "${it.name} OK!"
					// now loop arrayList value by value it means item and run it in Test step MTD-ESB-TLM-Country-all (next 1th test step)
					for (String item : country) {
						//set property country with value item into TestCase
						testRunner.testCase.setPropertyValue("country", item)
   						//log.info testStep + ": " + item
   						
						//now run test step (will be run by count of enum values)
						testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null);
						testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
						testStep.run(testRunner, testStepContext);						
					}
        			}
        			else if(it.assertionStatus == AssertionStatus.UNKNOWN){
            			log.info "${it.name} UNKNOWN (PROBABLY NOT ALREADY EXECUTED)"
            			log.error "${it.name} FAIL with value of: " + item
		    			return;
        			}
        		}
    		}
	}
}/***********************enum test*************/
import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
// firsthly def ArrayList - enums
// this enums is available for change if another enums will change, dont change another part of code
List<String> country = new ArrayList<String> (["MK", "AD", "AE", "AF"])
//, "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "CH", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"])

log.info "!!!!!!!Dont stop this Test Step!!!!!!!!!"
log.info "!!!!!!!Dont change this Test Step when run!!!!!!!!!"
log.info "!!!!!!!Wait for results at least 10 minutes!!!!!!!!!"

//def actual test Case and Test STep 
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def testCase = testRunner.testCase;
def testStep = testCase.getTestStepAt(context.currentStepIndex + 2);

//set property country with value item into TestCase
testRunner.testCase.setPropertyValue("country", country[0])
   //log.info testStep + ": " + country[0]
   
//now run test step (will be run by count of enum values)
testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null);
testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
testStep.run(testRunner, testStepContext);

// here we detect if test case were failed (when is not firsth if, then list all assertion test steps in test case, is usable as Tear Down Script too)
def StepList = testCase.getTestStepList()

if (country != country[0] && country[0] != null){
	StepList.each{
    		if(it.metaClass.hasProperty(it,'assertionStatus')){
        		if(it.assertionStatus != AssertionStatus.FAILED){
            		log.error "${it.name} FAIL with value of: " + item
		    		return;    		
        			}
        			else if(it.assertionStatus == AssertionStatus.VALID){
            		log.info "${it.name} OK!"
					// now loop arrayList value by value it means item and run it in Test step MTD-ESB-TLM-Country-all (next 1th test step)
					for (String item : country) {
						//set property country with value item into TestCase
						testRunner.testCase.setPropertyValue("country", item)
   						//log.info testStep + ": " + item
   						
						//now run test step (will be run by count of enum values)
						testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null);
						testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
						testStep.run(testRunner, testStepContext);						
					}
        			}
        			else if(it.assertionStatus == AssertionStatus.UNKNOWN){
            			log.info "${it.name} UNKNOWN (PROBABLY NOT ALREADY EXECUTED)"
            			log.error "${it.name} FAIL with value of: " + item
		    			return;
        			}
        		}
    		}
	}
}

It means: 

it log only part of code, but not log.info/error/warning... from Log Output with the values of variables - I may made it manualy, but I want execute all project from command line its general task from our DevOps.

How to script it in both versions (not all testers here have full version)

 

Thanks for answer 

  • nmrao's avatar
    nmrao
    Champion Level 3
    Unclear question.

    Logging will happen based on the log configuration irrespective of log statements in the code.
    • Nastya_Khovrina's avatar
      Nastya_Khovrina
      SmartBear Alumni (Retired)

      Necraatall 

      It seems that you pasted code two times, also, there are some issues. For example, I get the following error:

      No such property: item for class: Script4 
      
      error at line: 30

      Also, can you please clarify what exactly should be written to files?