StateLocaleby Group Public on Monday July 13 2009 @ 10:20:01 (1/1 Points) |
|
| Configuration ↪Reference ✑ Reply ✓ Stick It ✗ Ditch It ⚐ Tag It |
The StateLocale is a special construct which allows moving strings out of your test files into properties files. It provides a mechanism for language independence and easy lookup of keys based on the state.
State Hierarchy
Lookup of a text label can be done via the StateLocale context item. For example the below would click a link containing the label entry for Save.
Click link:%StateLocale:Save%
This works in conjunction with the current state as last set by Verify→ or Goto→. It works by walking up the state to find a matching label. For example, if the current state is Web.Login.Edit it will look for a locale property in the below order (note the Text part is used as a separator).
- Web.Login.Edit.Text.Save
- Web.Login.Text.Save
- Web.Text.Save
In this fashion you can specify common labels at a higher level in your hierarchy and have them usable in any child state.
Configuration
The above referred to something known as the locale properties. Before you can use the StateMap you must configure how the states map to specific locales. Each state is mapped based on the root of its name and is specified as an entry in the global StateLocaleMap item.
For example the below would be a common configuration for the StateLocaleMap as specified in a ptest→ file.
StateLocaleMap:Base=UserLocale StateLocaleMap:Web=WebLocale StateLocaleMap:Default=StaticLocale External.Locale.en=en.ptest External.Locale.de=de.ptest External.StaticLocale=static_locale.ptest
This says several things:
- lookups in the Base state will be done via the UserLocale. (see below)
- lookupgs in the Web state will be done via the WebLocale. (see below)
- All other lookups will be done in the StaticLocale map which is defined in the static_locale.ptest file.
WebLocale
Lookups in the special WebLocale use the context item Web.Language to determine in which locale object they check.
For example:
set %Web.Language% en Notice %WebLocale:Web.Text.Hello% Verify Web.State Notice %StateLocale:Hello%
In the first notice the Web.Hello key will be looked in the Locale.en map, which above was defined to be loaded from the en.ptest file.
In the second case the state hierarchy lookup will be used such that these keys will be looked up, in order, in the en.ptest file.
- Web.State.Text.Hello
- Web.Text.Hello
Notice that when you use the WebLocale directly you'll have to specify the complete key.
UserLocale
The UserLocale works like WebLocale except that it loads a language from a custom variable. This variable must be specified in the context as UserLocaleLangKey.
So in the above example where the state locale Base is mapped to UserLocale a lookup will traverse the state hierarchy.
# This first line would normally be in a properties file set %UserLocaleLangKey% App.CurrentUser:Language set %App.CurrentUser:Language% de Verify Base.Mine.Sub Notice %StateLocale:Happy%
This lookup will search for the following keys in the de.ptest file.
- Base.Mine.Sub.Text.Happy
- Base.Mine.Text.Happy
- Base.Text.Happy
TestPlan StateLocale
