Keeping same variable name inside a keyword

Viewed 17

Anyone know is it possible for the keyword to keep same variable name as it received?

Following short example will add values to list. Once it has been updated it needs to be set as a new variable (If i add "${first_list_values}" as test variable after new list insertion, it will only work with one specific list) and the same keyword can't be used anymore.

Id much rather use same keyword to loop multiple lists.

**Keyword**
Change List value 
[Arguments]         ${received_list}
${new_list}  Insert Into List   ${received_list}   0    xxx
Set Test Variable   ${new_list}
    
**Test Cases*
Checking new list values
     Change List value       ${first_list_values}
1 Answers

Maybe something like this:

*** Settings ***
Library   Collections

*** Variables ***
@{ORIGINAL_LIST}    First   Second

*** keywords ***
Change List value
  [Arguments]         ${received_list}
  Append to List      ${received_list}   Appended Third   Appended Fourth
  [return]            ${received_list}


*** Test cases ***
Use Return
    Log To Console      ORIGINAL_LIST: @{ORIGINAL_LIST}
    @{ORIGINAL_LIST}=   Change List value   ${ORIGINAL_LIST}
    Log To Console      ORIGINAL_LIST AFTER CHANGE: @{ORIGINAL_LIST}

Related