Store an incremental number when the same code is used more than once

Hi, i try to keep an incremental number when the same code is used more than once.
The code has test1.robot and test2.robot files.

test1.robot
*** Variables ***
${countval} 0

*** Keywords ***
${counter} IncrementNumber ${countval}
${countval} Set Variable ${counter}

IncrementNumber located in the test2.robot and returns incremental number in ${countval} → then pass the new number to ${countval} to be reuse when executing the same code a second time. I try many different combination to get it work but on second run ${countval} was always = 0
Why does ${countval} always take default to 0 on the second run of the same line of codes?
How can i get this code to work in my scenario?

Thank you

Hi NK (Nat?),

You didn’t include test2.robot, so just want to clarify how you are calling this:

  1. Do you have one test case in test2.robot that calls ${countval} once and each time you are running the test case ${countval} is 0? (this would be expected)

or

  1. Do you have multiple test cases in test2.robot each one calls ${countval} and they all find that ${countval} is 0?

I suspect you are encountering scenario 1? if so and you need to retain the count across multiple runs then you need to store the count outside a variable, either in a file or a database or something similar.

If i’ve misunderstood you question can you provide an example where you are calling ${countval} and are expecting it to be 1 or higher?

Hope this helps,

Dave.

Hi Dave, you’re right - the code runs as # 1 … test1.robot - connects to a multi-line .xls file and includes the “keywords” names … the real execution code is at test2.robot … in this case, each line from test1.robot call to test2.robot for execution … after executing the last line in test1.robot, the application call to the next line in the .xls file and starting test1.robot from the beginning … it looks like a loop on test1.robot … it’s a good idea to 'store the counter outside a variable , either in a file, or in a database, or something like that '… I don’t have that experience … any advice how to do this easily and delete after the test is finished?

Hi NK,

Well you can make this as simple or as complicated as you like.

You say your already reading xls files, so you already know how to do that, so start with something really simple

  1. create an excel file called counter.xls and on the first sheet in cell A1 put the number 0
  2. Setup test1.robot to open this excel read the number, increment it and save the xls file and return the number

when your finished each round of testing you can just open the spreadsheet and reset back to 0

later when you’ve worked out a start point you can add another keyword to test1.robot to reset the count to zero and then call that in the appropriate test.

That should give you something that will work well for now, and give you time to work out if you even need a more complex solution.

Dave.