Im trying to run a test that is repeated for x amount of minutes.
My idea for the keyword:
*** Keywords ***
Run test looped
FOR ${i} IN RANGE 9999
Do something
Exit For Loop If ${ELAPSED} > ${MAX_DURATION}
END
Im trying to find how to calculate the elapsed time in minutes.
I found the datetime type for robotframework but dont know how to get minutes elapsed. How can I get the elapsed time in minutes?
In builtin library there's Repeat Keyword - it does exactly what you need:
Repeat Keyword 2 minutes Do Something arg1 arg2
For more info see: http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Repeat%20Keyword
It's easier to work with epoch for such use cases - get it before the loop, and compare the current value inside it:
Run test looped
${start}= Evaluate time.time() time
FOR ${i} IN RANGE 9999
Do something
${now}= Evaluate time.time() time
Exit For Loop If (${now} - ${start})/60 > ${MAX_DURATION} # divide the runtime seconds by 60, as ${MAX_DURATION} is in minutes
END
Related
I want to make a VDP scheduler job in Denodo 8 wait for a certain amount of time. The wait function in the job creation process is not working as expected so I figured I'd write it into the VQL. However when i try the suggested function from the documentation (https://community.denodo.com/docs/html/browse/8.0/en/vdp/vql/stored_procedures/predefined_stored_procedures/wait) the Denodo 8 VQL shell doesn't recognize the function.
--Not working
SELECT WAIT('10000');
Returns the following error:
Function 'wait' with arity 1 not found
--Not working
WAIT('10000');
Returns the following error:
Error parsing command 'WAIT('10000')'
Any suggestions would be much appreciated.
There are two ways of invoking WAIT:
Option #1
-- Wait for one minute
CALL WAIT(60000);
Option #2:
-- Wait for ten seconds
SELECT timeinmillis
FROM WAIT()
WHERE timeinmillis = 10000;
Python 3.6.0
APScheduler 3.3.1
I have a program that I have just modified to implement APScheduler.
The program is working exactly as intended.
Here is the code snippet where I added in APScheduler:
def main():
sched = BackgroundScheduler()
sched.start()
sched.add_job(errordetect)
sched.add_job(errordetect, 'interval', minutes=5)
input("Press enter to exit.")
The job runs 'right now' and then every 5 minutes. My issue is this:
I have to stop the job manually by pressing 'Enter'.
Is there a way to say either:
1) Stop running after X amount of time (say one hour) or
2) stop after X iterations (say twelve iterations)
What I am wanting is to run the job every 5 minutes for one hour, so I
want it to stop on it's own after twelve iterations (or one hour -- effectively the same thing). I am not finding anything like that in the documentation, but I am hoping that I am either missing something in the docs or that there is another way to accomplish what I am after.
Thanks.
I solved it like this:
x = 0
starttime = time.time()
while x < 5:
i = 0
for a_connection in ssh_conns:
errordetect(a_connection, ip_addrs[i])
i += 1
x += 1
if x == 5:
break
time.sleep(15.0 - ((time.time() - starttime) % 15.0))
Here is my situation: I need to run number of test cases repeatedly over long period of time (Stress test + Longevity test). In the test case, there are number of events that should be passed all the time. However, I would like to catch any expected failure.
Is there a way to set robot test suite to keep executing over period of time or until it encounter a failure?
While you certainly can do an endurance test in Robot Framework, you may find that too much memory is consumed and may cause the interpreter to exit prematurely with a MemoryError. If you implement your test as a keyword, you can run your "test" many times with a for loop. In the below example, Scenario is where your test code would go. This is just a simulation that will fail after 200 runs.
*** Variables ***
${ITERATION} ${1}
*** Test Cases ***
Endurance Test
[Timeout] 4 hours
:FOR ${i} IN RANGE 1000
\ Scenario
*** Keywords ***
Scenario
Set Suite Variable ${ITERATION} ${ITERATION+1}
Run Keyword If ${ITERATION} > 200 Fail You wore me out
I make my first simple test case, and I have one problem.
Is it possible write a loop in Robot Framework?
I want to retrieve the value from the address and the address of the modified variable "i". I want to perform until such an address exists, because it is a row in the table.
${f1} A
${f_temp} B
While ${f1} != ${f_temp}
or
While element xpath=//${i} is visible
\ ${F_temp} Get Text xpath=//${i}
\ ${i} ${i}+1
\ Run Keyword And Continue On Failure Should be equal ${f_temp} ${f1}
Any ideas?
I'm updating my answer because modern Robot Framework does have a while loop.
The old answer, do not use this:
Robot Framework does not have a while loop. You must use the FOR-loop and "exit for loop if" keywords to exit. It will run in a finite time, but if you select a large enough number in range, it is close enough for practical purposes.
*** Test Cases ***
For Test
FOR ${i} IN RANGE 999999
Exit For Loop If ${i} == 9
Log ${i}
END
Log Exited
You might be looking for the Wait Until Keyword Succeeds keyword, which enables you to do a similar construction to a while loop. It is much more readable than FOR cycles with conditional exiting.
You then use your custom keyword, which fails when you need to end the "loop".
This are other kinds of FOR Loops in Robot Framework, I have this on my own notes and its very helpfull.
FOR Loop with Upper Bounds Range
[Documentation] This gives us a 0 based range
FOR ${Index} IN RANGE 5
Do Something ${Index}
${RANDOM_STRING} = Generate Random String ${Index}
Log ${RANDOM_STRING}
END
FOR Loop with Start and Finish Range
[Documentation] No longer a 0 based range because I provided start
FOR ${Index} IN RANGE 1 4
Do Something ${Index}
${RANDOM_STRING} = Generate Random String ${Index}
Log ${RANDOM_STRING}
END
FOR Loop with Start, Finish, and Step Range
[Documentation] The counter will jump by 2 each time ("step" value = 2)
FOR ${Index} IN RANGE 1 10 2
Do Something ${Index}
${RANDOM_STRING} = Generate Random String ${Index}
Log ${RANDOM_STRING}
END
#index for elements in for
${index} = Set Variable 0
FOR ${col} IN #{cols}
${colum} Format String css:div[class='v-widget v-has-caption v-caption-on-top'] table[aria-rowcount='{0}'] tbody tr:nth-of-type({1}) td:nth-of-type(10) ${r_count} ${col}
Click element ${colum}
press Keys none ${net_config.broadcast}
Press Keys none TAB
Press Keys none ${net_config.${index}}
${index}= Evaluate ${index} + 1
END
#-------
FOR Loop with List
#{ITEMS} = Create List Item 1 Item 2 Item 3
FOR ${MyItem} IN #{ITEMS}
Log ${MyItem}
END
Exit a FOR Loop
#{ITEMS} = Create List Item 1 Item 2 Item 3 Item 4
FOR ${MyItem} IN #{ITEMS}
Log ${MyItem}
Run Keyword If "${MyItem}" == "Item 3" Exit For Loop
Log Didn't exit yet
END
Log Now we're out of the loop
As the above answer said, Robot doesn't support native WHILE loop.
But this one may help if you insist.
https://github.com/robotframework/robotframework/issues/3235
I encountered a freezing test but actually it was stuck in a retry loop.
Wait Until Keyword Succeeds | 60 sec | 12 sec
The first parameter is the timeout for an attempt and the second is retry interval. However, if the task is something like "Xpath Should Match X Times" on a large data set it might never succeed in given time and next attempt starts from scratch again.
Is there way to limit the maximum number of retry attempts in this kind of situation?
Your situation is a bit strange because theoretically there is no such thing as "infinite retry loop" with Wait Until Keyword Succeeds because the first parameter is not "timeout for an attempt" but rather "global timeout for all the attempts". So in your case, it would try every 12 seconds and stop after 60 secs elapsed. Maybe you should reconsider the value you use with this information.
To answer your question, there is no way (AFAIK) to give a max number of attempts. I had such a need for some keywords and I came up with my own custom keyword:
Run_keyword_n_times_and_stop_if_success
[Arguments] ${keyword} ${number_tries}
:FOR ${index} IN RANGE ${number_tries}
\ ${result} ${error_message} = Run Keyword And Ignore Error ${keyword}
\ Pass Execution If '${result}' == 'PASS' keyword execution was successful
Fail ${error_message}
This works only with keywords having no arguments, but maybe that could be helpful for you (either because you don't have args, or because you could elaborate on that first version)
Thanks for the Retry keyword. To use it with a keyword with arguments.
Run Keyword N Times And Stop If Success
[Arguments] ${number_tries} ${keyword} #{args}
: FOR ${index} IN RANGE ${number_tries}
\ ${result} ${error_message} = Run Keyword And Ignore Error ${keyword} #{args}
\ Pass Execution If '${result}' == 'PASS' keyword execution was successful
Fail ${errorLog_message}
Sample usage:
#{args} Create List #{User} ${Url} ${Browser}
Run Keyword N Times And Stop If Success 5 Login #{args}
Since April 2015, this has been implemented as an argument for the keyword.
An example of usage could be seen as:
Wait Until Keyword Succeeds | 5x | 30 sec | Flaky Keyword
More information on the keyword is available in the BuiltIn documentation.