IBM Support

How to put text output into a Robot GUI script variable

Troubleshooting


Problem

This technote presents a code example for a message box from a Visual Basic script (VBS). The IBM® Rational® Robot GUI script retrieves the text output of this VBS and stores the output's content into a Robot script variable.

Resolving The Problem

The following script retrieves the two text lines from VBS message box. The VBS is the following script:

MsgBox "Hello World " & VbCrLF & "and goodbye", 0, "MyMessage"


The output is the message box in figure 1.


Figure 1: output from the Visual Basic Script.

First you record a case-sensitive alphanumeric verification prompt. Then you declare a function AlphaVPString. The actions of this function are:

  1. The function determines the location of the baseline file.
  2. The function opens the baseline file.
  3. The function reads all lines and append the lines content into a variable.
  4. The function closes the baseline file.

You can do with the variable whatever is possible in Robot scripting. The result is the following Robot script. In this case the script sends the content to the Robot console.




Declare Function AlphaVPstring(VPname As String) As String


Sub Main
    Dim Result As Integer

   'start the Visual Basic script
    Shell("wscript c:\temp\HelloWorld.vbs")
           
    Window SetTestContext, "Caption=MyMessage", ""
    Result = LabelVP (CompareText, "Text=Hello World   and goodbye", _
                                "VP=Prompt;Wait=1,10;Type=CaseSensitive")
   
    Window ResetTestContext, "", ""
     
    Window SetContext, "Caption=MyMessage", ""
    PushButton Click, "Text=OK"

    SQAConsoleWrite (AlphaVPstring("Prompt"))    
   
End Sub


Function AlphaVPstring(VPname As String) As String
    Dim ret As String
    Dim content As String
    Dim fullContent
    Const txt As String = "txt"

    ret = SQAVpGetCurrentBaselineFileName(VPname, txt)
     
    Open ret For Input As #1
   
    If fileLen(ret) > 0 Then
      Do
       Line Input #1, content
       fullContent = fullContent & content
      Loop Until EOF(1)
    End If
   
    Close #1
   
    AlphaVPstring = fullContent
   
End Function

After playback the Robot console shows the following output in a single line:


    Hello World and goodbye

[{"Product":{"code":"SSSHDX","label":"Rational Robot"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Scripting","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2003.06.00;2003.06.10;2003.06.12;2003.06.13;2003.06.14;2003.06.15;2003.06.16;7.0;7.0.0.1;7.0.1;7.0.1.1;7.0.0.3;7.0.1.2;7.0.0.4;7.0.1.3;7.0.2","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
16 June 2018

UID

swg21312707