I am currently writing an automation test where I firstly call a method to retrieve a date value from a database and then call a method to drive Selenium to obtain a date value from the UI and then assertEquals them to ensure they match. I actually get these date values concatenated with some other values into one string value and assert that which adds another thing to bear in mind.
In my database method the date is pulled out in its raw form which look like 2018-06-30 00:00:00.000
and this is a Date data type.
So I then convert this Date into string and reformat is as follows:
SimpleDateFormat formatter = new SimpleDateFormat("d MMMM yyyy");
String strPolicyExpiry = formatter.format(strPolicyExpiryUnformatted);
Which then makes the date look like 30 June 2018
.
But my UI element pulls back a string of 30th June 2018
which in turn fails the assertEquals as the UI has the 'th' there'
I've tried removing the 'st, nd, rd, th' from the UI string with regex but this doesnt look easy. So now I'm trying to change the database side to add in 'st, nd, rd, th' but again it all seems a bit messy and long winded.
I'm hoping there is an easy way around this as it must be a common problem for automation testers. Any ideas?