Create and run dynamic script statements

How can the object’s properties used on a descriptive programming approach be on a single concatenated string without using Description objects? For example having the following scenario:

Dim var1

var1 = "Hello"

If Window(" text:=Untitled – Notepad" ,"index:=0").Exist(0) = false then

SystemUtil.Run "notepad"

End if

Window("text:=Untitled – Notepad" ,"index:=0").Activate

Window("text:=Untitled – Notepad" ,"index:=0").Type var1

How to make the ( "text:=Untitled – Notepad" ,"index:=0" ) including the coma symbol (,) part of a dynamic statement or string appropriate for descriptive programming, because if the string is set to a variable and provided to the descriptive programming statement it will fail.

‘…

aux = "<all the properties>"

Window(aux).Activate

‘…

With strings similar to:

aux = "text:=Untitled – Notepad" ,"index:=0" ‘This will fail on this line due to syntax general error

‘Or

aux = "text:=Untitled – Notepad,index:=0" ‘This will fail when used against the directly Test Object

Descriptive Programming feature doesn’t support working several properties on a single string.

One alternative, is offered by the Microsoft VBScript Engine, with built-in methods that evaluate (EVAL function) or execute (EXECUTE or EXECUTEGLOBAL statement) run-time VBScript statements which allow performing dynamic creation of scripting statements and then either evaluate or execute them.

•MSDN Reference – Execute Statement – http://msdn.microsoft.com/en-us/library/03t418d2(VS.85).aspx

•MSDN Reference – ExecuteGlobal Statement – http://msdn.microsoft.com/en-us/library/342311f1(VS.85).aspx

•MSDN Reference – Eval Function – http://msdn.microsoft.com/en-us/library/0z5x4094(VS.85).aspx

Considering that QuickTest Professional (QTP) / Unified Functional Testing (UFT – GUI Testing) are based on VBScript itself, a combination of the mentioned statements and QTP / UFT code could work same as any other VBScript statement however the combination isn’t quality assured by Hewlett-Packard therefore their functionality can’t be assured. Please review the provided references to analyze when each statement is appropriate to the scenario’s requirements.

Using the logic provided and combining all concepts, a possible conversion of the QTP code shown above could result as follow:

Note: The below script is provided "AS-IS" for example purposes only.

Execute "Dim var1"

Execute "var1 = " & chr(34) & "Hello" & chr(34)

If EVAL("Window(" & chr(34) & "text:=Untitled – Notepad" & chr(34) & "," & chr(34) & "index:=0" & chr(34) & ").Exist(0) = false") then

Execute "SystemUtil.Run " & chr(34) & "notepad" & chr(34)

End if

Execute "Window(" & chr(34) & "text:=Untitled – Notepad" & chr(34) & "," & chr(34) & "index:=0" & chr(34) & ").Activate"

Execute "Window(" & chr(34) & "text:=Untitled – Notepad" & chr(34) & "," & chr(34) & "index:=0" & chr(34) & ").Type var1"

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s