I've tests where I've to check whether current time and current date/time is correctly returned by my APIs through automation.
Suppose, getCurrentTime()
returns current time in format HH:MM:SS (A/P)M
and getCurrentDateTime()
returns current date/time in format DD/MM?YYYY HH:MM:SS (A/P)M
In automation, I'm storing current time like -
actualCurrentTime=getCurrentTime()
suppose this returns 03:25:35 AM
and after above call, I make java API call to get expectedCurrentTime and it'll return with differences of one or two seconds like 03:25:37 AM
Now, if I add assertion
Assert.assertEquals(actualCurrentTime, expectedCurrentTime);
This will fail because time is differing with few seconds. This is also true for current date/time because it contains time part.
I'm confused how to automate this or what approach should be used to automate this.