I noticed that after raising a PR, the order of entries in the of my test objects has changed, even though I didn’t make any changes to it. Specifically, the BASIC
selector key was moved below the XPATH
key, even though the actual content of the selectors hasn’t changed.
What could be the reason for this ?
Just by accident, I believe.
Here I quote the source code of com.kms.katalon.core.testobject.TestObject
class:
package com.kms.katalon.core.testobject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.openqa.selenium.WebElement;
public class TestObject implements SelectorCollector, ITestObject {
private TestObject parentObject; // Typically is parent Frame
private boolean isParentObjectShadowRoot;
private List<TestObjectProperty> properties;
private List<TestObjectXpath> xpaths;
private String objectId;
private String imagePath;
private boolean useRelativeImagePath;
private SelectorMethod selectorMethod = SelectorMethod.BASIC;
private Map<SelectorMethod, String> selectorCollection;
private WebElement cachedWebElement;
public TestObject(String objectId) {
this.properties = new ArrayList<TestObjectProperty>();
this.xpaths = new ArrayList<TestObjectXpath>();
this.selectorCollection = new HashMap<SelectorMethod, String>();
this.objectId = objectId;
}
...
You can see that the this.selectorCollection
variable is decleared to be an instance of Map
and initialized with an instance of HashMap<SelectorMethod, String>
.
I would quote a sentence from the javadoc of HashMap
class:
This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.
Therefore you should not expect any order of elements contained in the <selectorCollection>
element.
By the way, the source code is bundled in the Katalon Studio distribution. Look into the jar file found at
<Katalon Studio Installed folder>/Contents/Eclipse/configuration/resources/source/com.kms.katalon.core/com.kms.katalon.core-sources.jar