3 Answers, 1 is accepted
0
Hello Siva,
You might find useful to read these articles about the .NET DateTime object and its ToString function.
The above code produces this output:
'8/2/2013 2:51:17 PM' - LOG: Current date and time: 8/2/2013 2:51:17 PM
'8/2/2013 2:51:17 PM' - LOG: Tomorrow is: 08/03/2013
'8/2/2013 2:51:17 PM' - LOG: In 2 hours the time will be: 04:51:17 PM
'8/2/2013 2:51:17 PM' - LOG: Current time is: 02:51:17
'8/2/2013 2:51:17 PM' - LOG: Is it AM or PM: PM
When you make sure that you have the current date and time formatted in the right way, you can set it to an extraction variable:
On your website you can use a Quick Verification for the number and use the Verify - text contains option. Select the test step and click the (Bindings) drop-down in the Properties pane. Set ExpectedString to the currentDate or currentTime variable.
I have recorded a short video to show you how you can do this.
I hope this helps.
Regards,
Velin Koychev
Telerik
You might find useful to read these articles about the .NET DateTime object and its ToString function.
DateTime now = DateTime.Now;
DateTime tomorrowDate = now.AddDays(1);
DateTime in2hours = now.AddHours(2);
string time = now.ToString("hh:mm:ss");
string ampm = now.ToString("tt");
Log.WriteLine("Current date and time: " + now.ToString());
Log.WriteLine("Tomorrow is: " + tomorrowDate.ToString("MM/dd/yyyy"));
Log.WriteLine("In 2 hours the time will be: " + in2hours.ToString("hh:mm:ss tt"));
Log.WriteLine("Current time is: " + time);
Log.WriteLine("Is it AM or PM: " + ampm);
'8/2/2013 2:51:17 PM' - LOG: Current date and time: 8/2/2013 2:51:17 PM
'8/2/2013 2:51:17 PM' - LOG: Tomorrow is: 08/03/2013
'8/2/2013 2:51:17 PM' - LOG: In 2 hours the time will be: 04:51:17 PM
'8/2/2013 2:51:17 PM' - LOG: Current time is: 02:51:17
'8/2/2013 2:51:17 PM' - LOG: Is it AM or PM: PM
When you make sure that you have the current date and time formatted in the right way, you can set it to an extraction variable:
DateTime now = DateTime.Now;
string dateTime= now.ToString("d MMM yyyy");
string time = now.ToString("HH:mm");
Log.WriteLine(dateTime);
Log.WriteLine(time);
SetExtractedValue("currentDate", dateTime);
SetExtractedValue("currentTime", time);
On your website you can use a Quick Verification for the number and use the Verify - text contains option. Select the test step and click the (Bindings) drop-down in the Properties pane. Set ExpectedString to the currentDate or currentTime variable.
I have recorded a short video to show you how you can do this.
I hope this helps.
Regards,
Velin Koychev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
Siva
Top achievements
Rank 1
answered on 02 Aug 2013, 03:31 PM
Hi Velkin
Thanks for you response, i have another issue when my variable calculated the time as "11:00:01 am"
next step will verify text contains ahead 1 second "11:00:02 am" so i'm getting failure.
appreciate your feed back
Thanks for you response, i have another issue when my variable calculated the time as "11:00:01 am"
next step will verify text contains ahead 1 second "11:00:02 am" so i'm getting failure.
appreciate your feed back
0
Accepted
Hello Siva,
If you need to verify using the time from the previous or the next second, you can use the following code:
Looking forward to hearing from you.
Regards,
Velin Koychev
Telerik
If you need to verify using the time from the previous or the next second, you can use the following code:
DateTime now = DateTime.Now;
Log.WriteLine(now.ToString());
DateTime nextSecond = now.AddSeconds(1);
Log.WriteLine(nextSecond.ToString());
DateTime lastSecond = now.AddSeconds(-1);
Log.WriteLine(lastSecond.ToString());
Looking forward to hearing from you.
Regards,
Velin Koychev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings