EachWithIndex groovy statement

后端 未结 4 772
[愿得一人]
[愿得一人] 2021-02-02 08:03

I am new to groovy and I\'ve been facing some issues understanding the each{} and eachwithindex{} statements in groovy.

Are each a

4条回答
  •  感动是毒
    2021-02-02 08:42

    EachWithIndex can be used as follows:

    package json
    import groovy.json.*
    import com.eviware.soapui.support.XmlHolder
    def project = testRunner.testCase.testSuite.project
    def testCase = testRunner.testCase;
    
    def strArray = new String[200]
    //Response for a step you want the json from
    def response = context.expand('${Offers#Response#$[\'Data\']}').toString()
    
    def json = new JsonSlurper().parseText(response)
    
    //Value you want to compare with in your array
    def offername = project.getPropertyValue("Offername")
    
    log.info(offername)
    
    Boolean flagpresent = false
    Boolean flagnotpresent = false
    
    strArray = json.Name
    
    def id = 0;
    
    //To find the offername in the array of offers displayed
    strArray.eachWithIndex
    {
        name, index ->
        if("${name}" != offername)
        {
            flagnotpresent= false;
    
        }
        else
        {
            id = "${index}";
            flagpresent = true;
            log.info("${index}.${name}")
            log.info(id)
        }
    
    }
    

提交回复
热议问题