Language of aqConvert.DateTimeToFormatStr
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Language of aqConvert.DateTimeToFormatStr
Hello,
I have an application that i have to test in English and in French, at different URL-s.
One of the things i have to test is, at the last page, a string which, with words, tells me the date of an appointment, and it is of the form
Friday, December 13, 2019 ─ 08:00 pm
I have the date the form of numbers, i.e. 13 for the day, 12 for the month, and so on.
So i put these numbers in a datetime structure and use aqConvert.DateTimeToFormatStr to convert the datetime to a string with the appropriate format modifiers, and compare the obtained string with the string really displayed on the web page.
When my page is in English, everything is fine!
However, the problem arises when the application is in French. In this case, since my computer has an English language OS, so DateTimeToFormatStr converts the date to a string in an english language, as above. But my application is in French, so it displays the string as:
Vendredi 13 décembre 2019 ─ 20:00 pm
So my question is, is there any way to tell DateTimeToFormatStr to use another locale, not the default one in English?
Or alternatively, is there any way to change via the script the regional settings of my computer temporarily to French, to make the comparison, and to switch them back to English? Of course without stopping the script?
The idea is to compare the result of DateTimeToFormatStr with the string displayed by my application, regardless of the app language.
All suggestions are appreciated!
Solved! Go to Solution.
- Labels:
-
Checkpoints
-
Scripting
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure if it will work in conjunction with the aqConvert.DateTimetoFormatStr method.... but the aqEnvironment object has a SetLocale method that you can utilize to set the language parameters of your environment.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your suggestion!
Unfortunately it does not work for me, not sure why. SetLocaleInfo always return false, and GetLastError is 0, no matter what arguments i give to it. i tried with LOCALE_SNAME as type and "fr-CA" as value, with LOCALE_SLOCALIZEDLANGUAGENAME as type and "French (Canada)" as value, tried also with LOCALE_ILANGUAGE and others, to no avail...
It would have been nice if DateTimeToFormatStr accepted the locale as parameter, but ... it does not.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @krosav,
Do you mind sharing the script you developed?
Tanya Yatskovskaya
SmartBear Community and Education Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm with @TanyaYatskovska . We can probably help you debug your use of aqEnvironment to apply the Locale and see if we can find a way to use aqConvert.DateTimeToFormatStr.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, thank you for your replies!
Here is the function i use to create the baseline string (The one i compare with the string displayed in the application).
This function works pretty well, no problems with it, except for the fact that the returned string is always in English, because that are my regional settings.
def ParseIdStr( idStr 😞
sInput = idStr[:-2]
numbers = sInput.split("/")
myDate = aqDateTime.SetDateElements(numbers[2],numbers[1],numbers[0])
sDayOfWeek = aqConvert.DateTimeToFormatStr(myDate, "%A ")
sDayOfWeek = sDayOfWeek.capitalize()
sReste = aqConvert.DateTimeToFormatStr(myDate, "%#d %B %Y")
return sDayOfWeek + sReste
So i tried to follow the Robert Martin's suggestion above to use the SetLocaleInfo method of the aqEnvironment object.
Since it did not work, i did not kept the code, and i disabled the validation when the app is in French.
But it was something like that:
aqEnvironment.SetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SNAME, "fr-CA")
Or:
aqEnvironment.SetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SLOCALIZEDLANGUAGENAME, "French (Canada)")
I tried also other combinations of parameters, but unfortunately i did not kept them, because no combination worked.
The SetLocaleInfo method always returned False, and tried to call Win32API.GetLastError() to try to determine why, i always got 0, i.e. no error...
(And after calling SetLocaleInfo, the string was always generated in English ).
So for now i deactivated the validation of that string when the app is in French, perhaps later i will try to develop a function to translate the date myself, should not be too complicated.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, my account has administrative rights ...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you do that, please, and try again?
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, you are right of course, it is not the same thing, i did not think of that...
However, i just tried to run TestComplete as administrator, and it did not help, same results...
