Micro Focus QTP (UFT) Forums
DP Encapsulation Within Class Object - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: DP Encapsulation Within Class Object (/Thread-DP-Encapsulation-Within-Class-Object)



DP Encapsulation Within Class Object - TheGlovner - 10-10-2018

First post so hopefully this makes sense.

I've been given my first tasks within UFT having moved into a new role (previous experience was mainly using VBA and SQL within the Excel Environment, so have an understanding of classe module objects within the VBA Structure).

I'm keen to use the descriptive programming concept within the cases being designed so we can encapsulate the object recognition in the class itself, not sure if this is doable though.

Code:
option explicit

Function ApplicationClassCreation
   ApplicationClassCreation = new Application
End Function

Class Application
    
    Public Window
    
    Sub Initialise
        
        Set SPICEWindow = Description.Create
        Window("Class") = "SwfWindow"
        Window("swfname") = "ShellUI"
        Window("regexpwndtitle") = "SPICE (Environment: Syst)"
        Window("is owned window") = False
        Window("is child window") = False
  
    End  sub
    
    
End Class

The above is an extract of the external function library being used to host the class code.

The structure of the program is:
  -High Level Test Script (which loads)
      - Pre Processing Function Library (Which sets up various file paths according to the local install of the git directory, which also loads)
          - Application Class
The application class once instantiated in the Pre Processing Function Library is then passed back up to high level test script for use.
I was then calling the Initialisation routine from the high level test script thinking this would create the window object that I could reference from the class object, but none of these lines of code work.

Hoping someone can shed some light on this and if what I'm doing is possible within UFT.

Thanks.


RE: DP Encapsulation Within Class Object - TheGlovner - 10-11-2018

Realise that I had made a school-boy error with the above code, so while I can get the lines of code to run now, the created object appears to be of a "collection" type (I'm assuming this because the only methods available to it are Add, Item, Count and Remove which are obviously collection methods).

My expectation was that it would create a window object and give me access at runtime to the methods of a window (.exists).

Here is the updated code:


Code:
Function SpiceClassCreation
    set SpiceClassCreation = new SPICEApplication
End Function

Class SPICEApplication
    
    Public SPICEWindow
    
    Sub Initialise
        Set SPICEWindow = Description.Create
        SPICEWindow("Type").value = "SwfWindow"
        SPICEWindow("swfname").value = "ShellUI"
        SPICEWindow("regexpwndtitle").value = "SPICE (Environment: Syst)"
        SPICEWindow("is owned window").value = False
        SPICEWindow("is child window").value = False
        check = SPICEWindow.Exists
    End  sub
    
    
End Class



RE: DP Encapsulation Within Class Object - TheGlovner - 10-12-2018

Another school-boy error it seems.

I hadn't realised when using descriptive programming you still need to encapsulate your object within the keyword of the class it denotes.

I've altered the check to:

check = swfwindow(SPICEWindow).exist

And it now works exactly as I thought it would.