Undefined parameters are not set to default value.

Hi Katalon,

Thanks for your hard work to bring such an amazing tool for us.

When I was working on web services testing, I wanted to dynamically map variables into request object and keep rest of predefined variable of default value automatically.

However, currently private static RequestObject findRequestObject(String requestObjectId, Element reqElement, String projectDir, Map<String, Object> variables) only assigns default values to variables when variables == null || variables.size() == 0.

Therefore, it turned out like following.
Define request object


Test case

Debug this requestObject

So, I am wondering if it is possible to overload a findTestObject method to allow passing in maybe a Boolean value to assign variables that have not been passed in as default values. Or if we can just simply modify the logic of findRequestObject

Thanks so much for your time!!

Replying to note that I also encountered this while working on some Web Service tests.

Our suite has WebService test objects defined for the various endpoints of our app. We recently went through and refactored them to use a GlobalVariable for the hostname, planning to use profiles to allow us to switch running the tests against various test environments. These were added to the objects’ Variables list with a default value populated from our GlobalVariables.

However, for endpoints in which we were using findTestObject() and passing in new values for variables (rather than using the defaults), those tests failed to resolve our new ${hostname} variable. And this broke only for scenarios in which new variable values were provided.

A lot of troubleshooting later, and then finding this post, and we realized that by not including the new “hostname” variable in the Map of variables, that was no longer defined in the object’s variables list, and so was being parsed as the literal string “${hostname}” instead of the value defined in the profile.

I’d also like to add my request to “merge” the Map of properties passed through findTestObject() into the properties (and their default values) of the object definition.

Until then, our workaround is to go from this:

findTestObject(objectID, [('id') : _id])  // expect hostname defaulted in test object

to this:

findTestObject(objectID, [('id') : _id, ('hostname') : GlobalVariable.host])  // explicitly set hostname

We’re fortunate that this isn’t impacting a huge number of our tests, but

/**
 * Creates a request object
 * @param testObjectRelativeId - Can be test object full id or test object relative id
 * @param {Map<String, Object>} variables the variables map to parameterized the found test object
 * @return an instance of {@link TestObject} or <code>null</code> if test object id is null
 */
private static customTestObject(String testObjectRelativeId, Map<String, Object> variables){
	String testObjectId = getTestObjectId(testObjectRelativeId);
	File objectFile = new File(RunConfiguration.getProjectDir(), testObjectId + WEBELEMENT_FILE_EXTENSION);
	Element rootElement = new SAXReader().read(objectFile).getRootElement();
	String elementName = rootElement.getName();
	Map<String, String> rawVariables = new HashMap<>();
	if (WEB_SERVICES_TYPE_NAME.equals(elementName)) {
		List<Element> variableElements = rootElement.elements("variables");
		if(variableElements != null && variableElements.size() > 0 ){
			for(Element variableElement : variableElements){
				if(variableElement != null){
					Element defaultValue = variableElement.element("defaultValue");
					Element name = variableElement.element("name");

					if(!defaultValue.equals(StringUtils.EMPTY)){
						rawVariables.put(name.getData().toString(), defaultValue.getData().toString());
					}
				}
			}
		}
	}
	Map<String, Object> oldVariables = evaluateVariables(rawVariables);
	oldVariables.putAll(variables);
	RequestObject originalObject = findTestObject(testObjectRelativeId, oldVariables);
	return originalObject;
}

Sharing a workaround.

Hi @passPassPass,

What Katalon Studio version are you using?

Thanks

Hi,

Version 6.2.0.

Many thanks