Dynamic/Formatted GuiWidget Locators¶
There are many situations where you would like to use dyanamic or formattable locators.
Arjuna’s $<name>$ Placeholder¶
You can use Arjuna’s $<name>$ placeholders in locators to define dynamic locators.
- The placeholder name can be:
A C/L/R query which Arjuna will auto-format (Auto-Formatting using C,L,R Magic Functions)
Any name that you will parameterize in code using formatter call. (Formatting Placeholders using formatter Method)
Auto-Formatting using C,L,R Magic Functions¶
- The placeholder is more advanced than Python’s {} placeholder:
Provides case-insensitive match for names in placeholders
- Supports auto-parameterization of the placeholders with the following prefixes:
C.<query>: Reference configuation option value. For example C.abc
L.<query>: Localized value for the name. For example L.abc
R.<query>: Data Reference Value for the name. For example R.abc
Note
The query in each of the above formats corresponds to the query string format that you use for the magic C(), L() and R() calls.
In the following examples, the values are automatically formatted for dyanmic locators:
Coded¶
# From Reference Configuration
app.element(link="$C.link.name$")
# From Data Reference
app.element(link="$R.links.test1.navlink$")
# From Localizer
app.element(link="$L.links.posting$")
GNS¶
nav_link1:
link: $C.link.name$
nav_link2:
link: $R.links.test1.navlink$
nav_link3:
link: $L.links.posting$
Formatting Placeholders using formatter Method¶
Arjuna provides an easy way to programmatically format dynamic identifiers.
Coded¶
Rather than using the element method of a Gui, you use formatter call and use the element method of formatter object.
app.formatter(text="Media").element(link="$text$")
In the above example, $text$ placeholder is defined for the link locator.
Using formatter you pass one or more keyword arguments to format the locator.
The above call is equivalent to the following non-dynamic locator call:
app.element(link="Media")
Following is some more involved examples of the power of dyanmic identifiers:
app.formatter(tg="input", idx="er_l", sz=20).element(node=node(tags="$tg$", id="$idx$", size="$sz$"))
app.formatter(tg="input", attr1='id', idx="er_l", attr2='size', sz=20).element(node=node(attrs={'tags':"$tg$", '$attr1$': "$idx$", '$attr2$': "$sz$"}))
GNS¶
Placeholdrs can also be defined in GNS so that programmatically values can be passed to format the locators:
nav_link1:
link: $text$
password:
node:
tags: $tg$
$attr1$: $idx$
$attr2$: $sz$
Rather than using the element method of a GNS, you use formatter call and use the element method of formatter object.
Using formatter you pass one or more keyword arguments to format the locator.
app.gns.formatter(text="Media").nav_link1
app.gns.formatter(tg="input", attr1='id', idx="er_l", attr2='size', sz=20).password
Note
Note that in case of placeholders in GNS, you use app.gns.formatter method instead of app.formatter method as seen in coded version of this situation.