Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

ElementComparators allow you to define your own way of verifying that values output from a pipeline and displayed in XNAT are correct. Out of the box, NRG_Selenium comes with support for the following comparators. The "CSV key" is the value that should be used in the spreadsheet to indicate what type of comparator to use:

ElementComparator
CSV key
"type"Extra config required
EqualityElementComparator"Equals"
OR "" OR empty
None
PercentToleranceElementComparator (minimum)
MinPercentToleranceElementComparator"minPercentTolerance"Minimum percent tolerance allowed (e.g. 1.5)
PercentToleranceElementComparator (maximum)
, specified as "percent" property.
MinPercentToleranceElementComparator"maxPercentTolerance"Maximum percent tolerance allowed (e.g. 2.3), specified as "percent" property.

When creating the YAML file for element comparison, the root level should specify "comparators" with a list of objects. Each comparator object must include the "type" property matching one of the above options. Additionally, some comparators may require additional parameters to be used correctly. Each comparator object should also include an "elements" property which points to a list of element objects. An element object consists of two properties, a "value" with the expected value of the element, and a "locator" property. If the "locator" property is simply a text string, it will be interpreted as an xpath string by which the element can be located. Otherwise, it should be another object with a "type" and "value", where the type is either "id" or "xpath", specifying that the text in "value" is either the DOM id for the element, or an xpath selector. A full example can be seen below:


Code Block
languagetext
titleElementComparators YAML example
linenumberstrue
collapsetrue
comparators:
- type: Equals
  elements:
  - locator: //div[@id='whitematter']
    value: 44.4
  - locator:
      - type: xpath
        value: //div[@id='graymatter']
    value: 55.5
  - locator:
      - type: id
        value: errors
    value: No errors.
- type: maxPercentTolerance
  percent: 1.0
  elements:
  - locator: //div[@id='whitematter']
    value: 44.4



Tip
A quick tip about PercentToleranceElementComparatorMinPercentToleranceElementComparatorthe minimum version this comparator specifies that the percent error between the values must be greater than some specified value, while the maximum version specifies that the percent error bewteen the values must be less than some specified value. The maximum version is much more useful and logical, but it was easy to include the other version.
Tip
If you wish to write your own comparator, simply extend ElementComparator and define a custom version of checkPointsMatch(...). For optimal results, don't throw an Exception when the check fails; instead, simply return any non-null String describing the error, and this will be collected for you and listed at the end with pipeline errors. If the comparator is satisfied correctly, simply return null.this version on the off-chance of it being useful.