Passing variables to object in Windows App Testing

Hi
I’m trying to pass a String “KOI” to my object named “menuItem” to click on a selected position in menu by:

Windows.click(findWindowsObject(‘Object Repository/mainWindow/menuItem’, [(‘itemName’) : “KOI”] ))

image

//MenuItem[@Name=“KOI”] works fine, but //MenuItem[@Name=“${itemName}”] doesn’t.

Log:

2020-02-20 09:14:19.862 DEBUG testcase.TEST                            - 8: switchToWindow(findWindowsObject("Object Repository/mainWindow/mainFrame"))
lut 20, 2020 9:14:20 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: OSS
2020-02-20 09:14:20.033 DEBUG testcase.TEST                            - 9: click(findWindowsObject("Object Repository/mainWindow/menuItem", ["itemName":"KOI"]))
2020-02-20 09:14:21.419 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'APS00076262-MB', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: io.appium.java_client.windows.WindowsDriver
Capabilities {appTopLevelWindow: 808ba, javascriptEnabled: true, platform: WINDOWS, platformName: WINDOWS}
Session ID: B4334F10-B953-4EF6-B814-E43A3B191EFA
*** Element info: {Using=xpath, value=//MenuItem[@Name="${itemName}"]} (Root cause: org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'APS00076262-MB', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: io.appium.java_client.windows.WindowsDriver
Capabilities {appTopLevelWindow: 808ba, javascriptEnabled: true, platform: WINDOWS, platformName: WINDOWS}
Session ID: B4334F10-B953-4EF6-B814-E43A3B191EFA
*** Element info: {Using=xpath, value=//MenuItem[@Name="${itemName}"]}

@piotr.kochanek.2

Passing variables for Windows object is not supported for this moment. We will consider to support in the near feature.

Pleas track the development status via this issue: https://github.com/katalon-studio/katalon-studio/issues/274

Thanks for your report.

Hey @duyluong, thanks for reply.

Is there any workaround for such a scenario?
Im creating an order with random ID, lets say “123321”. The ID shows on a message box where can I getText() the order ID. Now I’m opening a list of current orders and I want to right-click on the row with orderID = 123321. Can I do it without passing a variable to the object?

Maybe something like:
Windows.rightClick(findWindowsObject(where XPATH=“//Window/Pane[3]/Pane[1]/Pane[1]/Pane[1]/Pane[1]/List[1]/ListItem[contains(@Name, ‘MY_STRING_VAR’)]”)) ?

image

@piotr.kochanek.2

You can get the object’s locator and set the locator again.

Example:

import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import org.apache.commons.text.StringSubstitutor as StringSubstitutor
import com.kms.katalon.core.testobject.WindowsTestObject as WindowsTestObject

WindowsTestObject obj = findWindowsObject('your object id')

String MY_STRING_VAR = '123321'

String newLocator = StringSubstitutor.replace(obj.getLocator(), [('MY_STRING_VAR') : MY_STRING_VAR])
obj.setLocator(newLocator)

println(obj.getLocator())
1 Like

@duyluong

That’s exactly what I needed. It worked. Thanks a lot :sunglasses:.