Troubleshooting Performance Issues for XPath

When testing applications with a complex object structure, for example complex web applications, you may encounter performance issues, or issues related to the reliability of your scripts. This topic describes how you can improve the performance of your scripts by using different locators than the ones that Silk Test Classic has automatically generated during recording.

Note: In general, we do not recommend using complex locators. Using complex locators might lead to a loss of reliability for your tests. Small changes in the structure of the tested application can break such a complex locator. Nevertheless, when the performance of your scripts is not satisfying, using more specific locators might result in tests with better performance.
The following is a sample element tree for the application MyApplication:
Root
  Node id=1
    Leaf id=2
    Leaf id=3
    Leaf id=4
    Leaf id=5
  Node id=6
    Node id=7
      Leaf id=8
      Leaf id=9
    Node id=9
      Leaf id=10
You can use one or more of the following optimizations to improve the performance of your scripts:
  • If you want to locate an element in a complex object structure , search for the element in a specific part of the object structure, not in the entire object structure. For example, to find the element with the identifier 4 in the sample tree, if you have a query like Root.Find("//Leaf[@id='4']"), replace it with a query like Root.Find("/Node[@id='1']/Leaf[@id='4']"). The first query searches the entire element tree of the application for leafs with the identifier 4. The first leaf found is then returned. The second query searches only the first level nodes, which are the node with the identifier 1 and the node with the identifier 6, for the node with the identifier 1, and then searches in the subtree of the node with the identifier 1 for all leafs with the identifier 4.
  • When you want to locate multiple items in the same hierarchy, first locate the hierarchy, and then locate the items in a loop. If you have a query like Root.FindAll("/Node[@id='1']/Leaf"), replace it with a loop like the following:
    testcase Test() appstate none
      WINDOW node
      INTEGER i
     
      node = Root.Find("/Node[@id='1']")
      for i = 1 to 4 step 1
        node.Find("/Leaf[@id='{i}']")