Robot framework for circular application

Time:2022-5-21

In the process of automated testing, if we want to run a certain statement multiple times and use different values each time, we need to use a loop.

In robot framework, for is the keyword to be recycled. See the following for common applications.

Application 1:

For ${variable} in} Parameter1} parameter2} parameter3

Parameters can be numbers or strings,For must be capitalized

Execution result:

Starting test: TEST.LogTest.for
            INFO : 1
            INFO : 2
            INFO : 3
Ending test: TEST.LogTest.for

Execution result:

Starting test: TEST.LogTest.for
             INFO : apple
             INFO : pear
Ending test:   TEST.LogTest.for

Application 2:

For ${variable} in range} initial value} final value (optional) step size (optional)

 

Execution result:

Starting test: TEST.LogTest.for
            INFO : 0
            INFO : 1
            INFO : 2
Ending test:   TEST.LogTest.for

Note: the above two execution results are the same, starting from 0 and ending with - 1.

Set the step size to: 2

Execution result:

Starting test: TEST.LogTest.for
               INFO : 0
               INFO : 2
Ending test:   TEST.LogTest.for

Application III:

Use exit for loop to exit the loop (similar to break), combined with run keyword if keyword

Execution result:

Starting test: TEST.LogTest.loop
            INFO : @{list} = [ 1 | 3 | 5 | 7 ]
            INFO : 1
            INFO : 3
            INFO : 5
            INFO : Exiting for loop altogether.
Ending test:   TEST.LogTest.loop

Why@{list}instead of${list}, replace with${list}The execution result is

Starting test: TEST.LogTest.loop
            INFO : ${list} = ['1', '3', '5', '7']
            INFO : ['1', '3', '5', '7']
Ending test:   TEST.LogTest.loop

Application 4:

Continue for loop skips the current execution of the next cycle and is used in combination with the run keyword if keyword

Execution result:

Starting test: TEST.LogTest.loop

            INFO : Continuing for loop from the next iteration.

            INFO : 1

            INFO : Continuing for loop from the next iteration.

            INFO : 3

Ending test:   TEST.LogTest.loop

expand:

Repeat keyword: execute the specified keyword multiple times. You can set the number of times or execution time

1. Execute log keyword 2S

Execution result:

Starting test: TEST.LogTest.continue

            INFO : Repeating keyword, round 1, 2s remaining.

            INFO :apple

            INFO : Repeating keyword, round 2, 1s 998ms remaining.

            INFO : apple

            INFO : Repeating keyword, round 3, 1s 996ms remaining.

            INFO : apple

            。。。。。。

Ending test:   TEST.LogTest.continue

2. Execute the log keyword twice

Execution result:

Starting test: TEST.LogTest.continue

            INFO : Repeating keyword, round 1/2.

            INFO : apple

            INFO : Repeating keyword, round 2/2.

            INFO : apple

Ending test:   TEST.LogTest.continue