Forum Discussion

veronica_glynn's avatar
veronica_glynn
Contributor
11 years ago

Increment of integer variable not working

My goal is to create a variable that will increment by 1 with each test run. I need the final result to be passed into a text field reading: 'AutomationSet_100' with the integer increasing in value each run. So far I have performed the following actions:



1. In my Keyword Test; Set Variable Value 'attemptToIncrement' default value 100

2. Inserted a Code Expression on that variable of 'KeywordTests.TG_NewSetContextMenu.Variables.QS_increment +1'

3. Passing 'KeywordTests.TG_NewSetContextMenu.Variables.attemptToIncrement' into my control's text field.



I am running into several issues. 

1. If I add a string to the Code Expression in step 3, then nothing gets passed to my SetText. Example would be "QuestionSet" + 'KeywordTests.TG_NewSetContextMenu.Variables.attemptToIncrement

2. It only increments my value by 1. I need it to be a running count. Always increasing in value. Never re-using a number.



Any input would be greatly appreciated. 
  • Hello,

    Keyword test variables do not store values between test runs. They reset their value to defaul value upon each new run.

    To store values between test runs, use persistent project variables or persistent project suite variables. See Project And Project Suite Variables - Overview

    Thus the actions should be:

    1. Add a project variable in the Persistent Variables section of the Variables page of Project Editor.

    Name: TestRunsCounter; Type: Integer; Default Value: 100

    2. In Keyword Test insert a Set Variable Value operation.

    Mode:  Code Expression; Value: Project.Variables.TestRunsCounter+1

    3. In Keyword Test, pass that variable to your control's text field:

    aTextField.SetText(IntToStr(Project.Variables.TestRunsCounter))
  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)
    Hello,

    Keyword test variables do not store values between test runs. They reset their value to defaul value upon each new run.

    To store values between test runs, use persistent project variables or persistent project suite variables. See Project And Project Suite Variables - Overview

    Thus the actions should be:

    1. Add a project variable in the Persistent Variables section of the Variables page of Project Editor.

    Name: TestRunsCounter; Type: Integer; Default Value: 100

    2. In Keyword Test insert a Set Variable Value operation.

    Mode:  Code Expression; Value: Project.Variables.TestRunsCounter+1

    3. In Keyword Test, pass that variable to your control's text field:

    aTextField.SetText(IntToStr(Project.Variables.TestRunsCounter))
  • Thank you!!! I knew it was something silly that I was doing. I followed your steps and it is working perfectly.