Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

When trying to cast a string to a Window datatype in Silk Test Classic I receive the error “Error: variable is not defined” how can I resolve this issue?

When trying to cast a string to a Window datatype in Silk Test Classic I receive the error “Error: variable is not defined” how can I resolve this issue?

Within Silk Test Classic assuming a declaration for Notepad as follows:-

window MainWin Notepad

locator "/MainWin[@caption=’*Notepad']"

     Menu File

     locator "File"

 

It is possible to cast the string “Notepad” to a window with the use of the reference operator @, an example is shown in the statement below:-

testcase castWindow() appstate none

String str = "Notepad"        

Window w = @str              

 

The use of the @ symbol acts as a variable lookup for the "Notepad" declaration in the frame.inc file and is evaluated at runtime rather than compile time.

 

It is important to note that this approach will work only for a single member object, it not supported for multiple levels.  This is the reason we receive the error.

Given the above example we are unable to cast a string to a window for the file button as follows:-

     String str = "Notepad.File"

     Window w = @str

To resolve the issue we will be required to call the custom function below which will split the string by using the dots as separators.  A lookup is then performed on each of the respective members.

WINDOW makeWindow(String str)

STRING remainder = str

Int index = StrPos(".", remainder)

WINDOW retVal = NULL

    while(index > 0)

        STRING windowDecl = SubStr(remainder, 1, index - 1)

             remainder = SubStr(remainder, index + 1)

             if(retVal != NULL)

             retVal = retVal.@windowDecl

             else

                 retVal = @windowDecl

             index = StrPos(".", remainder)

          return retVal

 

Give the above example we can then use the makeWindow() function as follows:-

               String str = "Notepad.File"

         Window w = makeWindow(str)

         w.TypeKeys("xxx")

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2017-04-13 12:13
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.