Hi, I would to validate if the date in the site that I am testing is equivalent to the current date. I found a few articles but most of them were not able to cover how to check if the date being validated contains a different format. In this case, the format of the date that I am checking is example: Wed, 12 Aug 2020, how would I check if that date is the current date?
Thank you.
Hi @mark.jabay
- Use the below code to get the system date as per your desired format at runtime.
import java.text.SimpleDateFormat;
import java.util.Date;
Date date = new Date();
SimpleDateFormat myDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy");
String dateText = myDateFormat.format(date);
System.out.println(dateText); // output: Wed, 12 Aug 2020
- Use WebUI.getText to capture the date from the application
'Get text of date'
result = WebUI.getText(findTestObject('date'))
- Use the Verify match to compare both the dates
'Use WebUI keyword'
WebUI.verifyMatch('expectedDate, 'actualDate', false)
4 Likes
WOW. This is a very clear explanation. I will try it now and will get back to this thread as soon as I can execute the test case. Thank you.
I tried it just now and it works! Thank you for the quick response and help. 