Wednesday, December 23, 2015

Object Modesl - TOM, DOM, COM, AOM




Source: http://automated-360.com/qtp/advanced-concepts/all-about-object-models-in-qtp-uft/

All About Object Models in QTP / UFT


An Object Model is basically the way we use the object properties in a Programming language or technology. When we say usage of object properties, it means accessing the objects by object references to achieve the objectives like invoking a particular method of object. For example, object model of MS Excel, which enables other program to control it via different methods and properties.
A collection of objects or classes through which a program can examine and manipulate some specific parts of its world. In other words, the object-oriented interface to some service or system. Such an interface is said to be the object model of the represented service or system.

In this post we will discuss about the four different types of Object Models
  1. Test Object Model ( TOM )
  2. Document Object Model ( DOM )
  3. Component Object Model ( COM )
  4. Automation Object Model ( AOM )

Test Object Model ( TOM )
A collection of object types or classes which represents the different objects in the application. For Example a button object or edit box object in an application are the objects of and represent Button class or Edit box class. These test object class has a several properties to uniquely identify the objects of the particular class and methods to perform specific actions.
There are two types of objects in TOM,
  • Test Object and
  • Run-time object.
The objects which QuickTest creates and stores to represent the object in application, is a test object whereas a run-time object is the actual object in the application on which methods are performed during the run session, i.e the test object object properties are the properties as they are saved in the test object repository. Run time properties refers to the object properties as it appears in the application under test.
for example, a button with one of the properties “enable” is “true” in the object repository, which can be enable/disable at run time depending on certain conditions.
with this we can understand that the test object properties does not require your application to open and can be modified whereas a run-time object property requires the application to be open and it cannot be modified.
If you have ever wondered about the RO in GetROProperty and TO in SetTOProperty, now you know that RO is for Run-time Object and so GetROProperty is used to retrieve the value of the object at run time. TO is for Test Object and so the value of an object in object repository can be modified using SetTOProperty.

Document Object Model ( DOM )
Web Pages are organized into different objects like document, tables etc using the properties and methods available for the objects. These objects can be accessed by using scripts for the web pages. The Document Object Model is an interface(API) which allow programs and scripts to access and update the content, structure and style of documents. This is not only applicable for web pages (HTML) but for XML as well.
The objects in the document are in a hierarchy. DOM helps QTP to access this hierarchy of a web page directly by scripting. To access the DOM we use “.object” method for the specific web object.
For example, you can use DOM to identify an object when QTP is not able to identify an object. Consider the part of page source below for Google search page.

the part of the source is for the two buttons at Google search page.

GoogleSearch_buttons

If you need to click on the Google Search button using DOM, you will have to look into the source. For the button there are certain properties like id, name etc, you can find in the source above. These properties can be used to identify the object and do the action. If we take the Name property, this can be used by GetElementsbyName method as below

You can use GetElementsbyTagName to have all the button objects and then search for the required one as below

I am listing here some important properties and methods that you can use in QTP
GetElementById Method – returns a list of objects with specified id. If the id for the objects are not unique it take the first object with the specified value of the ID attribute.


ElementFromPoint Method – returns the object at specific coordinate on the page. for example the below code finds the search text box as per x and y coordinate and sets the value.


Some useful Properties which can be used for different purposes
activeElement – Retrieves the object that has the focus when the parent document has focus. Get the name of the text box which has the focus during runtime


cookie – Sets or retrieves the string value of a cookie. Find more details on Cookie here


documentElement - Retrieves the root node of the document.


readyState - Retrieves a value that indicates the current state of the object. This property can be used for sync in QTP scripts.


Component Object Model ( COM )
It is used to enable interprocess communication and dynamic object creation in a large range of programming languages. COM is the basis for several other Microsoft technologies and frameworks, including OLE, OLE Automation, ActiveX, COM+, DCOM, the Windows shell, DirectX, and Windows Runtime.
COM is basically used by developers to make the things simpler and easier to build and link by creating reusable components. The objects can be accessed by the interface (properties and methods) provided by COM for a particular class. Basically the properties and methods of an object can be the interface of the object and accessed by taking the reference of the object.
COM objects can be used with any tool that supports COM automation. And since VBScript supports COM automation, It becomes very easy to use in QTP scripting. But we cannot use all the COM objects, we can use only those objects that expose a string called a programmatic identifier (ProgID). Although not all COM objects have a ProgID, all COM objects have a 128-bit number called a class identifier, or CLSID. If a COM object has a ProgID, you can use VBScript to instantiate the object, invoke its methods and properties, and destroy the object.
To use a COM object in a script, you must first create an instance of the object. You can do this by calling the CreateObject or GetObject method.

CreateObject creates an Automation object of the specified class. If the application is already running, it creates a new instance. Set statement creates the reference between the object variable and the object. once the work is done the object reference should be destroyed as below

You can also use GetObject method which returns a reference to an instance of an object. It can be used in two way with its parameters, the object’s pathname and the object’s ProgID.

or


Automation Object Model ( AOM )
An Object Model is a structural representation of objects that comprise the implementation of a system or application. Automation enables software packages to expose their unique features to scripting tools and other applications. Usually Automation uses the Component Object Model (COM). A critical aspect of COM is, how client and servers interact. A COM server is any object that provides services to clients; these services are in the form of COM interface implementations like Properties, Methods, Events and their relationships. Which can be called by any client that is able to get a pointer to one of the interfaces on the server object.
QuickTest Professional is also a COM Server and its different methods and properties are exposed by its COM interface which can be accessed by other applications and scripting tools to control it from outside. In this post, we will see how to interact with QTP from outside via Automation Object Model.
Find more detail in the post Automation Object Model : QuickTest Professional by Anurag . It is same for UFT as well without any changes. Below code snippet illustrates the launch of UFT.

I hope you enjoyed reading about these object models and this will definitely help you in your automation. 

Tuesday, December 22, 2015

Training - Websites (cts), other sort of material

12/22/2015

Access onecognizant.cognizant.com, go to mylearning app and search for the following course codes. Trainings are really informative.

Course Code
Course Name
Duration
Delivery Mode
Start Date
End Date
(in Hrs)
BTLNA6
4.2
eLearning
26-Oct
27-Oct
CSEST045
2
eLearning
28-Oct
28-Oct
CSEST062
24
eLearning
28-Oct
4-Nov
CSEST179
4
eLearning
5-Nov
6-Nov
CSEST186
24
Classroom Training
(Location – Phoenix, AZ)
9-Nov
11-Nov
CSEST185
15
Classroom Training
(Location – Phoenix, AZ)
12-Nov
13-Nov
ATSTC4
NA
CCP-Assessment
16-Nov
20-Nov
ASEST077
QTP- Case Study Presentation
NA
Assessment
16-Nov
20-Nov


 

Sunday, December 20, 2015

Issues

12/21/2015

- Is it possible to compare values of properties in Object Repository??

The reason why I am asking is, everytime when I try to execute Bing rewards script, webedit box is not recognized so I have spy the object again and add the object. If I have comparison thing, I could make out which property is not matching..... Will it not make sense now???


Training Notes2

                                    
12/1/2015

                                   Day 1:
- Automation scripts could be used for functional and system testing, Release 1 features being used for Release 2
- More test coverage -- using multiple browser and parameterization
- Before automation - validate the application manually
- UFT - could be used for API testing
- Generally API does not have front end application, that is difficult test. UFT = API+QTP
- Can we integrate Rally with QTP?
- Web services ex: When you give zip code, to the service, response it will give weather condition
- Service virtualization:(Non GUI)
-> request -> Virtualization tool -> Service

UFT takes care of Service virtualization as a whole.

Here in virtualization tool, you need not have service to test, you can create mock up service.

If you wanted to test service down scenario, you need not make service down to test, just use virtualization

- That is how UFT covers GUI and Non GUI

- UFT Insight- Image based automation?

- UFT Mobile - Extended support for mobile testing?

- HP Lab Management - with the help of Jenkins

Traditional Client execution:

HPClient   Remote Host
||

Server     Server


- UFT compatable with Jenkins, will save time in virtual machine execution

- Run Debug mode -- is newly introduced in UFT???
Ex: object.method.debugmode

- Tool home page:
Menu bar, tool bar, document tabs, canvas, solution explorer pane, Data pane

- UFT new test -> GUI, API, BPT, BPF??

- Tabs displayed in the Record and Run settings, is based on the addins that you selected during the initial stage

- UFT/QTP records in Mozilla, Chrome also???—yes, you could see chrome and Mozilla in and Record and Run settings window.

- Low level recording -- is also for conitinous mouse movements based on coordinates

- Insight Recording - Images. Appearance. Not image comparision.

- In Amex laptop, windows recording even if it is defualt is showing dimensions.

- Captche -- cannot be automated, better disable it and then test application

- Insight recording - expecially for image look and feel. Icons are stored here.???

- How API testing is done using QTP??

Open test as API
Load WSDL(get it from the website)
Methods are displayed in explorer
drag the methods to canvas
you could see xml(Request and response parameters) on the right side - properties window
Give the input values to the xml in the request xml
Run the tool
You could see result in response xml tags on the right side window
In the result you could clearly see request and response xmls

Note - Web Service url- WSDL file

Note: Authorization error when you try to import the WSDL file to UFT??
- UFT mostly uses ordinal identifier by default..looks like?
-  UFT costs 8000 to 12k per seat
- Pefromance of other applications will be reduce while running UFt
- UFT does not work on all browser versions --- so testers use patch file
- UFT works with Mac…if it is on remote machine???
- Selenium supports more browsers but UFT does only Mozilla, chrome and IE
- Selenium used only for web but UFT could be used for web  and windows
- UFT does continuous integration using Jenkins or ALM, but selenium uses many tools to do continuous integration
- Image based tests easy in UFT(using insight recording), but in selenium its bit tough
- Integrating with Jenkins for Selenium, you can use more reporting concepts than QC has.
-  what is testing scroll and tab functionality called as?
- Editors view or expert view the same. Keyword view gives the object- value details. Using toggle you can move the respective object in keyword view to the respective object in the editors view.
-  If object has html id then it will always be unique.
- Preference:
UFT identifies objects based on the following order
Mandatory property -> Assistive property -> Ordinal identifier
-        Native property(could be found only in object spy not in object repository)(Browser specific) and test object property(that QTP has it)
-        We can create script(add steps) using only Keyword view. Documentation column in the keyword view is not editable but it gives details of what that step is doing
-        Object is a collection of class, Ex: webbutton and web edit are the classes of two different objects.
-        Description properties – the objects listed in here are looked by QTP.
Browser(“”).page(“”).webedit(“objectname”)…here objectname is not the property or value, its name given by qtp to whole d that QTP has considered to identify the object. Objectname – here are editable

-        Scripts based objectnames when run are more faster than descriptive programming
-        Problem with shared repositories??—common objectnames could create problem or the properties included in the object when merged with other repositories
-        Test objects and Run time objects:
Run time objects are --- marking regular expression to the existing objects and using them without adding new objects to repository
-        http://www.knowledgeinbox.com/articles/qtp/object-identification/gettoproperty-vs-getroproperty/
QTP provides 4 methods for working on a Test object properties
·        GetTOProperty  --- this give the property from test objects I,e is from object Repository (Note: TO – test objects)
·        SetTOProperty … this sets the property of the test objects within Object Repository with some specific value during only Run time. Again after run is completed, property value will be back to the original value, what it was there when recorded or added the objects.
·        GetTOProperties ---
·        GetROProperty  --- this give the property of the object during run time(note: RO – Run time objects)


                                                                        Day 2
Note: So that is why we cannot set the property of the object during run time.
-        Dynamic objects: The object that change during runtime
-        Mail Inbox(232)…has 232 messages and it changes based on the number of unread messages, we could test this by using regular expression. Property could be changed as inbox(.* …. To read that object and click on 232 messages. Ex: .* should be in the double quotes.
-        Ordinal identifier is the one that will be changing frequently, so better make it none for most of the  objects.
Note: Objects could be of any case, as VB scripting is not case sensitive.





Scenario:


1.      clicking the inbox(12343)…in gmail.
2. Going to policy details and getting the policy number for a specific policy holder


Sol: Go the webpage. Add table where the policies are included. Add table and then get the row details .
Like add whole table to object repository
Note: Make sure ordinal identifier is made none, else QTP will also consider those property values that are there in that section along with description properties.
Use GetRowWithCellText  ‘get the row number  of specific policy name
Using row number give it html id of the policy number object.
Ex: htmlid =”dgdfgfdg”&rownumber&”dgdfg”
Using setRoProperty , make html id us the row number(html id might have reference to row number)
Ex: Browser(dfd).Page(dfdg).link(ddg).SetTOProperty(“html_id”, htmlid)
Browser(dfd).Page(dfdg).link(ddg).click
Note: SetTOProperty changes the property of html_id, with the value htmlid only in Object Repository.

Note: In the above example we can remove SetTO and GetRO property code, using descriptive programming.
Browser(gfdg).Page(gdf).link(“html_id:”& htmlid).click
-        Description object:
We do not use Object repository like we do in descriptive programming, but we do create an object with certain properties and values. It is called Description object.

Set obj1= Description.Create
Obj1.set
-        Drawback of Descriptive programming and descriptive object is that whenever there is a change in property of table, then  in every line we have to change in the whole code(lots of maintenance work), but  when you program using object repository then you just need to update object respository. And also object respository programming is faster than descriptive programming.
-        DP general is – is static programming
-        DP - Descriptive objects – is dynamic programming
-        DP could be used along with object repository but order is Object repository of parent with DP of child not the other way(it does not work)
-        with and End with , could be used to avoid Browser(gdfg).page(gdfgfd)…. In the code
Ex: with Browser(gfgfdg).Page(ggfdg)
.link(dfgfd).SetROProperty(dfgfd,fg)
.link(fgfd).click
End with

Note: Descriptive programming is not used regularly in the projects, due to maintenance issue, so better expertise Programming with Object Repository.

-        Smart Identification:
Ex: If the name of google site webedit box – name is changed today, your code will still recognize it even if you have name as only field in description properties. That is because when smart identification is enabled qtp will go and check tools->object identification->web…for webedit you could see mandatory property set as some other tag that could be matching with the webedit object. And smart identification is with only normal programming(that is with object repository not with descriptive programming). Configure, smart identification object.

-        Scenario: Go to blogger and click my blogs and click the ‘3 post’ link in the blog.
Note: difficulty here is ‘3 posts’ link is there in multiple blogs so that qtp will say that ‘3 posts’ exists in multiple locations.

-        Global sheet will have your business components, and Action1…. Are local sheets.
Action1 can have – login, logout etc…
-        Import operations that are done in QTP are only run time, you should have file in local machine even after import.
-        Run settings are for Global sheet only, it means the iterations mentioned in Run settings will be applied only for the rows in Global sheet. So that is why Global sheet is global to QTP but action sheet is local (that cannot be iterated by mentioning the run settings), you should have separate code for the iterations to happen for local sheets.
-        Scenario: Check the impact of iterations mentioned in the Run settings getting reflected for Global sheet and local sheets.
-        Scenario:
-         
-        Using Environment variable concept you cannot iterate but using datatable we can. Environment variable values exist with the code but not datatable values(as datatable is run time). And we can import xml using environment variable. In frameworks developer uses absolute path variables as environment variables.
-        Importing environmental variables from XML? yes
Go to File-> Test settings->Environmental variables -> Load file browse
Syntax: Environment.value(“Policy”) …. Here Policy is the tag in xml, the value will be returned from this line of code.
-         
Day 3
-        We can define new object from object repository manager.
-        We can validate regular expression from the object repository ---- and highlight the application after writing the regular expression. This acts as a validator.
-        Visual relation identifier – in Object Repository this is latest addition to UFT. This will help you to identify the present object based on the left or right object.
-         


Note: Please do not xpath in the selenium or QTP, as the hierarchy could be changed any time. So evertying


COM(component object model) components:

-        Excels:
Set excelobj = CreateObject(“Excel.Application”)
excelobj.Quit ---
Set excelobj=Nothing --- must to used to release the object memory

 Note: if you are not using Quit and Nothing, your application will hang, and creates un-necessary problems.
-        Filesystemobject
-        IE

-        Import the datatable is possible using adding resource in the tool, import in the code or use Excel application object in the code

-        ADODB is just a connection, could be used to connect Excel and other databases. But while connecting to Excel, use $ infront of the column names while interacting with Excel in the queries. So in live projects, teams use move excel data to DB(MSAccess) and create MSAccess object and then use ADODB object start interacting.

-        Registering the function
And then UnRegister function
Ex: We can also register WebEdit, not use Set method or something
1.      We can override the existing methods of QTP, like micfail is the existing thing in QTP for reporting the results, ppl registered it by adding screenshots to the micfail as it did not had by default.

              Recovery Scenario
-        In real project teams stopped using Recovery scenarios as the performance is getting impacted.  As everytime when every recovery scenario is updated in the QTP tool, so that .qrs file gets created everytime. Performance degradation is possible. Alternatively teams use a separate code, so that application could handle exceptions.
-        Resources->Recovery scenario manager


Virtual Object

UFT – has ‘Regular Expression Evaluator’ in the tools, that will help you to evaluate the Regular Expression there and then. There could be RegEx method for evaluating regular expression002E

                                                                 Day 4:
-        An alternate to childobjects method is getElementsByTagName Method (DOMDocument).
DOM could be used here by making your entire web page as a Document.
For the list of links in a page:
.getElementsByTagName(“A”)

-        Frameworks
-        DataDriven/Modular driven –
-        Keyword driven/low level – here keywords are functions.
Here in the excel(data file) we have names of business operations or functions (design function with the same name). Or sometimes we also have excel file name.

Types of files in Framework:
Business Components
Data table
Driver script
Object Repository
Configfile — name of the project name, urls---notepad???? Note: Environment.value(“url”) …If the variables are assigned values in notepad, can we read data from notepad.
Note: functions could be assigned to Set method, so that return value of the function could be assigned to the the web element.

1.      Closedescendentprocesses
2.      setcurrentpage

                                        Day 5
-        Iterations?—Iterations are something  per each record in data table. If you mention that ‘on all Iterations’ in settings, it means all records in Datatable will be picked.
-        We can create QTP object—got to QTP help for the code. Yes it is possible to create COM object for QTP
-        Fast mode – Run is possible if you set the Fast mode in Tools->Options->Fast
Qtpcomobject.Options.Run.RunMode= “Fast”.
Two types of Run modes exist 1. Normal and 2. Fast
-        If you have QTP COM object, then you could access menu bar and different options using Options method.
Support:
Cts: 127345
Sarfaraz.Hussain.aghai.mohammad@csaa.com
           Scenarios:
-        Add object




-        Exceptions:
1.      How to open the application from Start button using vbscript
2.      Unable to see
3.      Is there any alternate to ChildObjects method, as childobject is with description object(descriptive programming)—looks like DOM – getElementsbytagname…should be an alternate
4.      Adding object—new objects in the Object Repository
5.      In the config file, we have notepad too, it has variable and values, how could qtp read data from notepad that has urls and other variable values

6.      Unable to define new test object in QTP, when you click add after clicking new object, it does not add.

Working Shared Object Repository

http://sqa.fyicenter.com/FAQ/QTP-QuickTest-Professional/How_to_Merge_Object_repositories_.html