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 Workbench 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 7 in the sample tree, if you have a query like Root.Find("//Node[@id='7']"), replace it with a query like Root.Find("/Node[@id='6']/Node[@id='7']"). The first query searches the element tree for the elements with the identifiers 1 to 7. The second query searches only for the element first level nodes, which are the node with the identifier 1 and the node with the identifier 6, for the node with the identifier 6, and then searches in the subtree of the node with the identifier 6 for the first leaf with the identifier 7.
  • When you want to locate multiple items in the same hierarchy, first locate the hierarchy, and then locate the items based on their common root node. If you have a query like Root.FindAll("/Node[@id='1']/Leaf"), replace it with a query like the following:
    Public Sub Main()
      Dim commonRootNode = _desktop.Find("//Node[@id='1']")
      commonRootNode.Find("/Leaf[@id='2']")
      commonRootNode.Find("/Leaf[@id='3']")
      commonRootNode.Find("/Leaf[@id='4']")
      commonRootNode.Find("/Leaf[@id='5']")             
    End Sub