Forum Discussion

andrea's avatar
11 years ago

while loop does not work

Hello every,

I am using the following groovy script to do the automation in SoupUI. And it works well with If statement. However, when I used While loop to do it, it failed. Please take a look and let me know what wrong with it. Thanks a lot in advance!

----------------------------------------------1. Worked well ---------------------------------------------
def id = context.expand( '${DataSource#id}' )
def exitFeeEstimateOID = context.expand( '${DataSource#ExitFeeEstimateOID}' )
def rtlrContractIdentifier = context.expand( '${DataSource#RtlrContractIdentifier}' )
def estimatedDropDate = context.expand( '${DataSource#EstimatedDropDate}' )
def amount = context.expand( '${DataSource#Amount}' )
def waiveReason = context.expand( '${DataSource#WaiveReason}' )
def db_insertBy = context.expand( '${DataSource#db_insertBy}' )
def db_insertDate = context.expand( '${DataSource#db_insertDate}' )
def db_updateBy = context.expand( '${DataSource#db_updateBy}' )
def db_updateDate = context.expand( '${DataSource#db_updateDate}' )

//def x="3"

if (id=="1")
{
def response11 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:ExitFeeEstimateOID[1]}' )

def rtlrContractIdentifier1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:RtlrContractIdentifier[1]}' )
//def estimatedDropDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:EstimatedDropDate[1]}' )
def amount1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:Amount[1]}' )
def waiveReason1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:WaiveReason[1]}' )
def db_insertBy1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:db_insertBy[1]}' )
def db_insertDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:db_insertDate[1]}' )
def db_updateBy1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:db_updateBy[1]}' )
def db_updateDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:db_updateDate[1]}' )

assert exitFeeEstimateOID==response11
assert rtlrContractIdentifier==rtlrContractIdentifier1
//assert estimatedDropDate==estimatedDropDate1
assert amount==amount1
assert waiveReason==waiveReason1
assert db_insertBy==db_insertBy1
assert db_insertDate==db_insertDate1
assert db_updateBy==db_updateBy1
assert db_updateDate==db_updateDate1

}
else if (id=="2")
{

def response11 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:ExitFeeEstimateOID[1]}' )

def rtlrContractIdentifier1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:RtlrContractIdentifier[1]}' )
//def estimatedDropDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:EstimatedDropDate[1]}' )
def amount1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:Amount[1]}' )
def waiveReason1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:WaiveReason[1]}' )
def db_insertBy1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:db_insertBy[1]}' )
def db_insertDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:db_insertDate[1]}' )
def db_updateBy1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:db_updateBy[1]}' )
def db_updateDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:db_updateDate[1]}' )

assert exitFeeEstimateOID==response11
assert rtlrContractIdentifier==rtlrContractIdentifier1
//assert estimatedDropDate==estimatedDropDate1
assert amount==amount1
assert waiveReason==waiveReason1
assert db_insertBy==db_insertBy1
assert db_insertDate==db_insertDate1
assert db_updateBy==db_updateBy1
assert db_updateDate==db_updateDate1

}
else if (id=="3")
{

def response11 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[3]/a:ExitFeeEstimateOID[1]}' )
def rtlrContractIdentifier1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[3]/a:RtlrContractIdentifier[1]}' )
//def estimatedDropDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[2]/a:EstimatedDropDate[1]}' )
def amount1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[3]/a:Amount[1]}' )
def waiveReason1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[3]/a:WaiveReason[1]}' )
def db_insertBy1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[3]/a:db_insertBy[1]}' )
def db_insertDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[3]/a:db_insertDate[1]}' )
def db_updateBy1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[3]/a:db_updateBy[1]}' )
def db_updateDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[3]/a:db_updateDate[1]}' )

assert exitFeeEstimateOID==response11
assert rtlrContractIdentifier==rtlrContractIdentifier1
//assert estimatedDropDate==estimatedDropDate1
assert amount==amount1
assert waiveReason==waiveReason1
assert db_insertBy==db_insertBy1
assert db_insertDate==db_insertDate1
assert db_updateBy==db_updateBy1
assert db_updateDate==db_updateDate1

}

----------------------------------------------2. Failed----------------------------------------
def rtlrContractIdentifier = context.expand( '${DataSource#RtlrContractIdentifier}' )
def estimatedDropDate = context.expand( '${DataSource#EstimatedDropDate}' )
def amount = context.expand( '${DataSource#Amount}' )
def waiveReason = context.expand( '${DataSource#WaiveReason}' )
def db_insertBy = context.expand( '${DataSource#db_insertBy}' )
def db_insertDate = context.expand( '${DataSource#db_insertDate}' )
def db_updateBy = context.expand( '${DataSource#db_updateBy}' )
def db_updateDate = context.expand( '${DataSource#db_updateDate}' )

//def x="3"
def x="3"

while (id==x)
{
def response11 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory['+ 1 +']/a:ExitFeeEstimateOID[1]}' )

def rtlrContractIdentifier1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[' + 1 +']/a:RtlrContractIdentifier[1]}' )
//def estimatedDropDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[1]/a:EstimatedDropDate[1]}' )
def amount1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[' + 1 +']/a:Amount[1]}' )
def waiveReason1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[' + 1 +']/a:WaiveReason[1]}' )
def db_insertBy1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[' + 1 +']/a:db_insertBy[1]}' )
def db_insertDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[' + 1 +']/a:db_insertDate[1]}' )
def db_updateBy1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[' + 1 +']/a:db_updateBy[1]}' )
def db_updateDate1 = context.expand( '${Cyberdyne--GetCustomerExitFeeInquiryHistory-1#Response#declare namespace ns1=\'http://tempuri.org/\'; declare namespace a=\'http://schemas.datacontract.org/2004/07/Cyberdyne.DataContracts\'; //ns1:GetCustomerExitFeeInquiryHistoryResponse[1]/ns1:GetCustomerExitFeeInquiryHistoryResult[1]/a:ExitFeeInquiryHistory[' + 1 +']/a:db_updateDate[1]}' )

assert exitFeeEstimateOID==response11
assert rtlrContractIdentifier==rtlrContractIdentifier1
//assert estimatedDropDate==estimatedDropDate1
assert amount==amount1
assert waiveReason==waiveReason1
assert db_insertBy==db_insertBy1
assert db_insertDate==db_insertDate1
assert db_updateBy==db_updateBy1
assert db_updateDate==db_updateDate1

x++
}

1 Reply

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    I think you are displaying a bit too much of your code without any information about what is happening in the code.

    The issue is most likely that id does not equal x and thus the while loop is never being executed. Without something a bit smaller and simpler to attempt to execute it will be very difficult to test and debug though.