Print duration of every step in terminal, during watir-cucumber execution - cucumber

Is there a standard way of printing the duration of every step in the terminal, during a watir-cucumber execution?
It might be possible to make some kind of invention, using the "after step" and a global variable. But, there is a proper way?

You can use hooks like this:
Before do
#last_time = Time.new
end
AfterStep do
now = Time.new
puts "Step duration: #{((now - #last_time)*100).round} ms" # if (now-#last_time) > 10
#last_time = now
end
This is more verbose by outputting the duration on a new line, but unless you want to get more in-depth (by creating your own formatter), you cannot output stuff where you indicated it.
Uncomment the if if you are only interested in steps that take longer than a certain threshold.

The simplest way to do this would be using Ruby's built in Time class. Using Time.new we can record the current time into a local variable before and after the code within the step definition is executed. Then we work out the duration by subtracting start_time from end_time.
#get the start time
start_time = Time.new
#do whatever the step needs to do here
#get the end time
end_time = Time. new
#calculate duration
duration = end_time - start_time
puts duration

Related

How can I get the current time in Godot?

I'm trying to make a digital clock in my game and need the current time (hours and minutes), formatted as so: HH:MM:SS How can I get the time necessary for this?
You can use the Time singleton, with the get_datetime_dict_from_system method to get the time dictionary from the current system time.
# Get the time dictionary
var time = Time.get_time_dict_from_system()
print(time) # {day:X, dst:False, hour:xx, minute:xx, month:xx, second:xx, weekday:x, year:xxxx}
In your case, to format it as HH:MM, you can use the less noisy function get_time_dict_from_system which only has hours, minutes, and seconds
var time = Time.get_time_dict_from_system()
# we can use format strings to pad it to a length of 2 with zeros, e.g. 01:20:12
print("%02d:%02d:%02d" % [time.hour, time.minute, time.second])
For older versions of Godot (-3.4), OS.get_time() also works but in 3.5+ it's deprecated and 4.x it's removed:

Sikulix - exists function has timeout?

i have a sikulix code with 5 if statement like this :
if exists("1642200162130.png"):
It enter in only one if statement, where there is only one click()
click(Location(me.x + paddingx, me.y + paddingy))
For a complete run, the scritp take ~7seconds to execute. It's too slow for me. Do you know if there is a timeout on exists function ? And if we can lower it ?
Thank you !
Yes, as described in the documentation here, you can overload the exists() function like this:
exists(PS[, seconds])
Check whether the give pattern is visible on the screen.
Parameters:
PS – a Pattern object or a string (path to an image file or just plain text)
seconds – a number, which can have a fraction, as maximum waiting time in seconds. The internal granularity is milliseconds. If not specified, the auto wait timeout value set by Region.setAutoWaitTimeout() is used. Use the constant FOREVER to wait for an infinite time.

How can I make a variable dynamically change while on console python3

I am working on a program and it needs to display the number of seconds that passed since it started. The variable is inside input() like this:
while True:
something = input(str(x) + "seconds have passed. Please input the number in 60 seconds:")
if x == 60:
break
Is there any way to make the x change dynamically while on screen? So it raises every second and also updates on screen without the need to press enter.
If yes, is there also a way to add an if statement that checks when the variable reached 60 and break the loop.

Compare A Variable Regularaly Using Linux Scripts and Cron

I'm trying to check if a number differs from what it was last time it was checked, in this case checking a number every minute, using Linux scripts and cron.
eg:
newNum = getNum()
if oldNum != newNum: run some code
oldNum = newNum
(repeat every minute using crontab)
But the problem I am having is that the variables aren't accessible between scripts and using source (eg. source script.sh) runs the script again, hence getting the latest version, not the one from a minute ago.
The best I've got is running a first script which gets the current number, then sleeps for a minute, then runs a second script which is essentially the first two lines of the code above.
eg:
oldNum = getNum()
sleep 60
export oldNum
script2.sh
This seems inefficient to me and I'd like to know if there is a better solution if possible.
You could cache the previous number in a file:
number_cache=/path/to/cache_file
# read the previous number
oldNum=$(< "$number_cache" )
# acquire the new number
newNum=$(getNum)
if [[ "$oldNum" -eq "$newNum" ]]; then
do_something
fi
# cache the new number
printf "%d\n" "$newNum" > "$number_cache"

Wildcards in Assertion on groovy-generated dates?

We are using SoapUI to test a Webservice of ours. This Webservice generates different Timestamps after a predictable pattern, so we use a groovy script to generate them on the SoapUI side and use these in assertions to assert the correct calculation on the webserver side. So far so good, it works like a charm on dates (pattern yyyy-MM-dd) and Timestamps with fixed hours / minutes (pattern yyyy-MM-dd'T'HH:mm':00.000'). We use variations of this script to do this, sometimes adding days, months, hours and so forth:
def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
Calendar instance = Calendar.getInstance();
instance.setTime(new Date());
Date date= instance.getTime();
s = sdf.format(date)
return s
===
Now I run into the following problem: This new project generates exact timestamps, down to the millisecond. Problem is, I cannot accuratly predict this, SoapUI generates the dates slightly earlier (thats no surprise, just a fact) than the webservice, and so there is a discrepancy of around 100 to 500 milliseconds between the timestamps.
I tried to add wildcards (*) (and enabled them, too) into this pattern to ignore the millisecond part, since it was deemed uneccessary as long as the second is right, but I guess they don't work within groovy scripts. Is there a way to make them work? Are there other approaches to check wether the timestamp down to the second is correct, and then ignore the milliseconds?
This is very easy! In a Script Assertion find the difference between the date you get back and "now", and assert that the difference is less than some tolerance.
def nowDate = new Date()
def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX")
def currentDate = sdf.parse(context.expand('${getCurrentDateTime#ResponseAsXml#//*:current}'))
def minutesDiff = Math.abs(nowDate.getTime() - currentDate.getTime()) / 1000 / 60
assert minutesDiff < 5 : "Too great of a difference with server!"

Resources