Forum Discussion

sriguda's avatar
sriguda
Frequent Contributor
9 years ago
Solved

Set Variable Valueis not saving new value to the variable.

Hello,

I am trying to set a new value for a variable, Name_Num(Integer) by following Set Variable value expression,

KeywordTests.IncrementValues.Variables.Name_Num + 1.

 

When I execute the statement, the value of the variable is being incremented but it doesn't save and update the new value actually to the Project or keyword test variable.

  • sriguda's avatar
    sriguda
    9 years ago

    I will try that Thanks.

     

6 Replies

  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor

    Hi Sriguda

     

    If I understand you correctly, it sound like you need something like this:

     

    KeywordTests.IncrementValues.Variables.Name_Num = KeywordTests.IncrementValues.Variables.Name_Num + 1

     

    Does this solve your problem?

     

    Regards

    Stephen.

    • sriguda's avatar
      sriguda
      Frequent Contributor

      I am using Set Variable Value statement function as shown in the attatchment.

      In the log statements, I am displaying updated values of variables.

      I see the variables being updated with new values when executing the code but it doesn't finally save the value in the varables that are defined in variables section of keyward test .

       

      I used the staement you have given in Run Code Snippet. I don't see the values being updated while executing the code itself.

       

       

      • joseph_michaud's avatar
        joseph_michaud
        Moderator

        You are using a variable local to the test.  The variable goes away when the test is done.  If you want the value to persist between test runs then use a persistent project variable.  In the following image, I increment a test-local variable, a temporary project-local variable, and a persistent project-local variable and print out their values.  Their initial values are 0, 10, and 100 respectively.  After the first run of the test, the incremented values are 1, 11, and 101.  After the second run, the incremented values are 1, 11, and 102.  Only the persistent project variable will save the value between test runs.

         

        increment.PNG

         

        For more info, see the article on Variable Collections