Web51.4
Web – Pseudo Attributes
The idea of pseudo attributes is to simplify resolvers using JavaScript to retrieve values from a browser. You can register a pseudo attribute in QF-Test which receives its value as result of some JavaScript code execution.
In a SUT script you can fetch attribute values of HTML elements
via the method getAttribute()
(This is also the way the
CustomWebResolver (see subsection 51.1.2) evaluates its
genericClasses
category). Pseudo attributes values are fetched with the
same mechanism, behaving just like normal attributes in the "eyes" of QF-Test.
Only, they are not defined via the HTML source code or explicitly set via
node.setAttribute()
, but execute a piece of JavaScript code.
When you define a pseudo attribute you can mark it as "cacheable". In that case the pseudo attribute will be evaluated the first time referenced and then its value will be saved until the next complete scan of the page. This improves the overall testing performance. Pseudo attributes should not be cached for values subject to change (e.g. the status of a check box), because then a change of the value would not be "visible" to QF-Test. Uncached pseudo attributes will not save their value, but it will be fetched (and kept shortly for processing) each time an event will be recorded, like for example the single events "moved", "pressed", "released" and "clicked" of a mouse click, or for the identification of a component during replay.
The following example defines a pseudo attribute for all HTML elements
with the tag "ICON" or "IMAGE" evaluating the value of
iconname
via JavaScript (Technically speaking, it calls the
sample method inspect
defined by the framework for the HTML node).
import de.qfs.apps.qftest.client.web.dom.DomNodeAttributes import de.qfs.apps.qftest.client.web.dom.FunctionalPseudoAttribute def attr = new FunctionalPseudoAttribute("js_icon", "try {return _qf_node.inspect('iconname')} catch(e){}", true) DomNodeAttributes.registerPseudoAttributes("ICON", attr) DomNodeAttributes.registerPseudoAttributes("IMAGE", attr)
The pseudo attribute can then be used in a feature resolver. In comparison to
a direct call of node.callJS()
in the script this method takes advantage
of the internal caching mechanisms of QF-Test:
def getFeature(node, feature): iconname = node.getAttribute("js_icon") return iconname resolvers.addResolver("iconFeature", getFeature, "ICON", "IMAGE")
The following script deregisters the pseudo attribute.
import de.qfs.apps.qftest.client.web.dom.DomNodeAttributes DomNodeAttributes.unregisterPseudoAttributes("ICON", "js_icon") DomNodeAttributes.unregisterPseudoAttributes("IMAGE", "js_icon")
A pseudo attribute has to be defined via the following method from the
module de.qfs.apps.qftest.client.web.dom.pseudo attributes
:
|
|
||||||||||||||||||||||||||||||||||
Having defined the pseudo attribute you need to register it via the following method
from module de.qfs.apps.qftest.client.web.dom.DomNodeAttributes
:
|
|
||||||||||||||
|
|
||||||||||||||