Pages

Saturday, 23 June 2012

Databases


Databases
A database is an integrated collection of logically-related records or files consolidated into a common pool that provides data for one or more multiple uses. One way of classifying databases involves the type of content, for example: bibliographic, full-text, numeric, image. Other classification methods start from examining database models or database architectures: see below. Software organizes the data in a database according to a database model. As of 2010[update] the relational model occurs most commonly. Other models such as the hierarchical model and the network model use a more explicit representation of relationships.

Architecture

A number of database architectures exist. Many databases use a combination of strategies.
Databases consist of software-based "containers" that are structured to collect and store information so users can retrieve, add, update or remove such information in an automatic fashion. Database programs are designed for users so that they can add or delete any information needed. The structure of a database is tabular, consisting of rows and columns of information.
Online Transaction Processing systems (OLTP) often use a "row oriented" or an "object oriented" data store architecture, whereas data-warehouse and other retrieval focused applications like Google's BigTable, or bibliographic database (library catalog) systems may use a Column oriented DBMS architecture.
Document-Oriented, XML, knowledgebases, as well as frame databases and RDF-stores (also known as triple stores), may also use a combination of these architectures in their implementation.
Not all databases have or need a database schema ("schema-less databases").
Over many years[update] general-purpose database systems have dominated the database industry. These offer a wide range of functions, applicable to many, if not most circumstances in modern data processing. These have been enhanced with extensible datatypes (pioneered in the PostgreSQL project) to allow development of a very wide range of applications.
There are also other types of databases which cannot be classified as relational databases. Most notable is the object database management system, which stores language objects natively without using a separate data definition language and without translating into a separate storage schema. Unlike relational systems, these object databases store the relationship between complex data types as part of their storage model in a way that does not require runtime calculation of related data using relational algebra execution algorithms.

 

 

Database management systems

A database management system (DBMS) consists of software that organizes the storage of data. A DBMS controls the creation, maintenance, and use of the database storage structures of social organizations and of their users. It allows organizations to place control of organization wide database development in the hands of Database Administrators (DBAs) and other specialists. In large systems, a DBMS allows users and other software to store and retrieve data in a structured way.
Database management systems are usually categorized according to the database model that they support, such as the network, relational or object model. The model tends to determine the query languages that are available to access the database. One commonly used query language for the relational database is SQL, although SQL syntax and function can vary from one DBMS to another. A common query language for the object database is OQL, although not all vendors of object databases implement this, majority of them do implement this method. A great deal of the internal engineering of a DBMS is independent of the data model, and is concerned with managing factors such as performance, concurrency, integrity, and recovery from hardware failures. In these areas there are large differences between the products.
A relational database management system (RDBMS) implements features of the relational model. In this context, Date's "Information Principle" states: "the entire information content of the database is represented in one and only one way. Namely as explicit values in column positions (attributes) and rows in relations (tuples). Therefore, there are no explicit pointers between related tables." This contrasts with the object database management system (ODBMS), which does store explicit pointers between related types.

Components of DBMS

According to the wikibooks open-content textbooks, "Design of Main Memory Database System/Overview of DBMS", most DBMS as of 2009[update] implement a relational model. Other less-used DBMS systems, such as the object DBMS, generally operate in areas of application-specific data management where performance and scalability take higher priority than the flexibility of ad hoc query capabilities provided via the relational-algebra execution algorithms of a relational DBMS.

RDBMS components

  • Interface drivers - A user or application program initiates either schema modification or content modification. These drivers[which?] are built on top of SQL. They provide methods to prepare statements, execute statements, fetch results, etc. Examples include DDL, DCL, DML, ODBC, and JDBC. Some vendors provide language-specific proprietary interfaces. For example MySQL provides drivers for PHP, Python, etc.
  • SQL engine - This component interprets and executes the SQL query. It comprises three major components (compiler, optimizer, and execution engine).
  • Transaction engine - Transactions are sequences of operations that read or write database elements, which are grouped together.
  • Relational engine - Relational objects such as Table, Index, and Referential integrity constraints are implemented in this component.
  • Storage engine - This component stores and retrieves data records. It also provides a mechanism to store metadata and control information such as undo logs, redo logs, lock tables, etc.

ODBMS components

  • Language drivers - A user or application program initiates either schema modification or content modification via the chosen programming language. The drivers then provide the mechanism to manage object lifecycle coupling of the application memory space with the underlying persistent storage. Examples include C++, Java, .NET, and Ruby.
  • Query engine - This component interprets and executes language-specific query commands in the form of OQL, LINQ, JDOQL, JPAQL, others. The query engine returns language specific collections of objects which satisfy a query predicate expressed as logical operators e.g. >, <, >=, <=, AND, OR, NOT, GroupBY, etc.
  • Transaction engine - Transactions are sequences of operations that read or write database elements, which are grouped together. The transaction engine is concerned with such things as data isolation and consistency in the driver cache and data volumes by coordinating with the storage engine.
  • Storage engine - This component stores and retrieves objects in an arbitrarily complex model. It also provides a mechanism to manage and store metadata and control information such as undo logs, redo logs, lock graphs,

Primary tasks of DBMS packages

  • Database Development: used to define and organize the content, relationships, and structure of the data needed to build a database.
  • Database Interrogation: can access the data in a database for information retrieval and report generation. End users can selectively retrieve and display information and produce printed reports and documents.
  • Database Maintenance: used to add, delete, update, correct, and protect the data in a database.
  • Application Development: used to develop prototypes of data entry screens, queries, forms, reports, tables, and labels for a prototyped application. Or use 4GL or 4th Generation Language or application generator to develop program codes.
almost in simple DBMS is a software

Types

Operational database

These databases store detailed data needed to support the operations of an entire organization. They are also called subject-area databases (SADB), transaction databases, and production databases. For example:
  • customer databases
  • personal databases
  • inventory databases
  • accounting databases

Analytical database

These databases store data and information extracted from selected operational and external databases. They consist of summarized data and information most needed by an organization's management and other[which?] end-users. Some people refer to analytical databases as multidimensional databases, management databases, or information databases.

Data warehouse

A data warehouse stores data from current and previous years — data extracted from the various operational databases of an organization. It becomes the central source of data that has been screened, edited, standardized and integrated so that it can be used by managers and other end-user professionals throughout an organization. Data warehouses are characterized by being slow to insert into but fast to retrieve from. Recent developments in data warehousing have led to the use of a Shared nothing architecture to facilitate extreme scaling.

Distributed database

These are databases of local work-groups and departments at regional offices, branch offices, manufacturing plants and other work sites. These databases can include segments of both common operational and common user databases, as well as data generated and used only at a user’s own site.

End-user database

These databases consist of a variety of data files developed by end-users at their workstations. Examples of these are collections of documents in spreadsheets, word processing and even downloaded files.

External database

These databases provide access to external, privately-owned data online — available for a fee to end-users and organizations from commercial services. Access to a wealth of information from external database is available for a fee from commercial online services and with or without charge from many sources in the Internet.

Hypermedia databases on the web

These are a set of interconnected multimedia pages at a web-site. They consist of a home page and other hyperlinked pages[citation needed] of multimedia or mixed media such as text, graphic, photographic images, video clips, audio etc.

 

 

Navigational database

In navigational databases, queries find objects primarily by following references from other objects. Traditionally navigational interfaces are procedural, though one could characterize some modern systems like XPath as being simultaneously navigational and declarative.

In-memory databases

In-memory databases primarily rely on main memory for computer data storage. This contrasts with database management systems which employ a disk-based storage mechanism. Main memory databases are faster than disk-optimized databases since[citation needed] the internal optimization algorithms are simpler and execute fewer CPU instructions. Accessing data in memory provides faster and more predictable performance than disk. In applications where response time is critical, such as telecommunications network equipment that operates emergency systems, main memory databases are often used.

Document-oriented databases

Document-oriented databases are computer programs designed for document-oriented applications. These systems may be implemented as a layer above a relational database or an object database. As opposed to relational databases, document-based databases do not store data in tables with uniform sized fields for each record. Instead, they store each record as a document that has certain characteristics. Any number of fields of any length can be added to a document. Fields can also contain multiple pieces of data.

Real-time databases

A real-time database is a processing system designed to handle workloads whose state may change constantly. This differs from traditional databases containing persistent data, mostly unaffected by time. For example, a stock market changes rapidly and dynamically. Real-time processing means that a transaction is processed fast enough for the result to come back and be acted on right away. Real-time databases are useful for accounting, banking, law, medical records, multi-media, process control, reservation systems, and scientific data analysis. As computers increase in power and can store more data, real-time databases become integrated into society and are employed in many applications.

Relational Database

The standard of business computing as of 2009[update], relational databases are the most commonly used database today[citation needed]. It uses the table to structure information so that it can be readily and easily searched through.

 

 

 

Models

 Post-relational database models
Products offering a more general data model than the relational model are sometimes classified[by whom?] as post-relational. The data model in such products incorporates relations but is not constrained by the Information Principle, which requires the representation of all information by data values in relation to it.
Some of these extensions to the relational model actually integrate concepts from technologies that pre-date the relational model. For example, they allow representation of a directed graph with trees on the nodes.
Some products implementing such models do so by extending relational database systems with non-relational features. Others, however, have arrived in much the same place by adding relational features to pre-relational systems. Paradoxically, this allows products that are historically pre-relational, such as PICK and MUMPS, to make a plausible claim to be post-relational in their current architecture.

Object database models

In recent years[update], the object-oriented paradigm has been applied[by whom?] to database technology, creating various kinds of new programming models known as object databases. These databases attempt to bring the database world and the application-programming world closer together, in particular by ensuring that the database uses the same type system as the application program. This aims to avoid the overhead (sometimes referred to as the impedance mismatch) of converting information between its representation in the database (for example as rows in tables) and its representation in the application program (typically as objects). At the same time, object databases attempt to introduce key ideas of object programming, such as encapsulation and polymorphism, into the world of databases.
A variety of these ways have been tried[by whom?] for storing objects in a database. Some products have approached the problem from the application-programming side, by making the objects manipulated by the program persistent. This also typically requires the addition of some kind of query language, since conventional programming languages do not provide language-level functionality for finding objects based on their information content. Others[which?] have attacked the problem from the database end, by defining an object-oriented data model for the database, and defining a database programming language that allows full programming capabilities as well as traditional query facilities.
Storage structures
Databases may store relational tables/indexes in memory or on hard disk in one of many forms:
These have various advantages and disadvantages - discussed further in the articles on each topic. The most commonly used[citation needed] are B+ trees and ISAM.
Object databases use a range of storage mechanisms. Some use virtual memory-mapped files to make the native language (C++, Java etc.) objects persistent. This can be highly efficient but it can make multi-language access more difficult. Others break the objects down into fixed- and varying-length components that are then clustered tightly together in fixed sized blocks on disk and reassembled into the appropriate format either for the client or in the client address space. Another popular technique involves storing the objects in tuples (much like a relational database) which the database server then reassembles for the client.
Other important design choices relate to the clustering of data by category (such as grouping data by month, or location), creating pre-computed views known as materialized views, partitioning data by range or hash. Memory management and storage topology can be important design choices for database designers as well. Just as normalization is used to reduce storage requirements and improve the extensibility of the database, conversely denormalization is often used to reduce join complexity and reduce execution time for queries.[1]

Indexing

All of these databases can take advantage of indexing to increase their speed. This technology has advanced tremendously since its early uses in the 1960s and 1970s. The most common[citation needed] kind of index uses a sorted list of the contents of some particular table column, with pointers to the row associated with the value. An index allows a set of table rows matching some criterion to be quickly located. Typically, indexes are also stored in the various forms of data-structure mentioned above (such as B-trees, hashes, and linked lists). Usually, a database designer selects specific techniques to increase efficiency in the particular case of the type of index required.
Most relational DBMSs and some object DBMSs have the advantage that indexes can be created or dropped without changing existing applications making use of them, The database chooses between many different strategies based on which one it estimates will run the fastest. In other words, indexes act transparently to the application or end-user querying the database; while they affect performance, any SQL command will run with or without indexes to compute the result of an SQL statement. The RDBMS will produce a query plan of how to execute the query: often generated by analyzing the run times of the different algorithms and select the quickest process. Some of the key algorithms that deal with joins are nested loop join, sort-merge join and hash join. Which of these an RDBMS selects may depend on whether an index exists, what type it is, and its cardinality.
An index speeds up access to data, but it has disadvantages as well. First, every index increases the amount of storage used on the hard drive which is also necessary for the database file, and second, the index must be updated each time the data are altered, and this costs time. (Thus an index saves time in the reading of data, but it costs time in entering and altering data. It thus depends on the use to which the data are to be put whether an index is overall a net plus or minus in the quest for efficiency.)
A special case of an index is a primary index based on a primary key: a primary index must ensure a unique reference to a record. Often, for this purpose one simply uses a running index-number (ID number). Primary indexes play a significant role in relational databases, and they can speed up access to data considerably.

Transactions and concurrency

In addition to their data model, most practical databases ("transactional databases") attempt to enforce database transactions. Ideally, the database software should enforce the ACID rules, summarized here:
  • Atomicity: Either all the tasks in a transaction must happen, or none of them. The transaction must be completed, or else it must be undone (rolled back).
  • Consistency: Every transaction must preserve the integrity constraints — the declared consistency rules — of the database. It cannot leave the data in a contradictory state.
  • Isolation: Two simultaneous transactions cannot interfere with one another. Intermediate results within a transaction must remain invisible to other transactions.
  • Durability: Completed transactions cannot be aborted later or their results discarded. They must persist through (for instance) restarts of the DBMS after crashes.
In practice, many DBMSs allow the selective relaxation of most of these rules — for better performance.
Concurrency control ensures that transactions execute in a safe manner and follow the ACID rules. The DBMS must be able to ensure that only serializable, recoverable schedules are allowed, and that no actions of committed transactions are lost while undoing aborted transactions.

Replication

Replication of databases often relates closely to transactions. If a database can log its individual actions, one can create a duplicate of the data in real time. DBAs can use the duplicate to improve performance and/or the availability of the whole database system.
Common replication concepts include:
  • master/slave Replication: All write-requests are performed on the master and then replicated to the slave(s)
  • quorum: The result of Read and Write requests are calculated by querying a "majority" of replicas
  • multimaster: Two or more replicas sync each other via a transaction identifier
Parallel synchronous replication of databases enables the replication of transactions on multiple servers simultaneously, which provides a method for backup and security as well as data availability. This is commonly referred to as "database clustering".[2] [3]

Security

Database security denotes the system, processes, and procedures that protect a database from unintended activity. Enforcing security is one of the major tasks of the DBA.
DBMSs usually enforce security through access control, auditing, and encryption:
  • Access control ensures and restricts who can connect and what they can do to the database.
  • Auditing logs what action or change has been performed, when and by whom.
  • Encryption: many commercial databases include built-in encryption mechanisms to encode data natively into tables and to decipher information "on the fly" when a query comes in. DBAs can also secure and encrypt connections if required using DSA, MD5, SSL or legacy encryption standards.
In the United Kingdom, legislation protecting the public from unauthorized disclosure of personal information held on databases falls under the Office of the Information Commissioner. Organizations based in the United Kingdom and holding personal data in electronic format (databases for example) must register with the Data Commissioner.[4]
Locking
Databases handle multiple concurrent operations with locking. This is how concurrency and some form of basic integrity are managed within the database system. Such locks can be applied on a row level, or on other levels like page (a basic data block), extent (multiple array of pages) or even an entire table. This helps maintain the integrity of the data by ensuring that only one process at a time can modify the same data.
In basic filesystem files or folders, only one lock at a time can be set, restricting the usage to one process only. Databases, on the other hand, can set and hold mutiple locks at the same time on the different levels of the physical data structure. The database engine locking scheme determines how to set and maintain locks based on the submitted SQL or transactions by the users. Generally speaking, any activity on the database should involve some or extensive locking.
As of 2009[update] most DBMS systems use shared and exclusive locks. Exclusive locks mean that no other lock can acquire the current data object as long as the exclusive lock lasts. DBMSs usually set exclusive locks when the database needs to change data, as during an UPDATE or DELETE operation.
Shared locks can take ownership one from the other of the current data structure.[5] Shared locks are usually used while the database is reading data (during a SELECT operation). The number, nature of locks and time the lock holds a data block can have a huge impact on the database performances. Bad locking can lead to disastrous performance response (usually the result of poor SQL requests, or inadequate database physical structure)
The isolation level of the data server enforces default locking behavior. Changing the isolation level will affect how shared or exclusive locks must be set on the data for the entire database system. Default isolation is generally 1, where data can not be read while it is modified, forbidding the return of "ghost data" to end users.
At some point intensive or inappropriate exclusive locking can lead to a "deadlock" situation between two locks, where none of the locks can be released because they try to acquire resources mutually from each other. The database should have a fail-safe mechanism which will automatically "sacrifice" one of the locks, thus releasing the resource. Processes or transactions involved in the "deadlock" get rolled back.
Databases can also be locked for other reasons, like access restrictions for given levels of user. Some DBAs also lock databases for routine maintenance, which prevents changes being made during the maintenance. See "Locking tables and databases" (section in some documentation / explanation from IBM) for more detail.) However, many modern databases do not lock the database during routine maintenance. e.g. "Routine Database Maintenance" for PostgreSQL.

Applications

Databases function in many applications, spanning virtually the entire range of computer software. Databases have become the preferred method of storage for large multiuser applications, where coordination between many users is needed. Even individual users find them convenient, and many electronic mail programs and personal organizers are based on standard database technology. Software database drivers are available for most database platforms so that application software can use a common API to retrieve the information stored in a database. Commonly used database APIs include JDBC and ODBC.

Descriptive Programming in QTP



Descriptive Programming in QTP













What is Descriptive Programming?
Providing Objects information directly into the Test Script, instead of storing objects information in the Object Repository.
Descriptive Programming is a method of performing operation on the object which is not there in Object Repository. We can also use programmatic descriptions to perform the same operation on several objects with certain identical properties, or to perform an operation on an object whose properties match a description that we determine dynamically during the run session.
Tests using Descriptive programming are faster than Tests using Object Repository
Benefits of Descriptive Programming

If the AUT (Application Under Test) is having Dynamic Objects, then it is better to use descriptive programming. Incase of object repository, it is Difficult to handle dynamic Objects.

When we have more objects to perform operations, in performance point of view descriptive programming is better than object repository method. If we use object repository for generating huge tests, then QTP performance will be decreased.
         
Descriptive Programming is useful if the AUT is having objects that are adding in the Run Time. We can’t add Objects to Object Repository in run time.
         
If we need to start Test Automation process before the AUT is ready   

Descriptive Programming is useful, if the AUT is having similar type of objects or similar name objects. Incase of Object Repository, It will create multiple objects with same description unnecessarily.

Shared Object Repository is not changeable by multiple persons at a time.
Maintenance becomes harder if all the team members have created their own object repositories. In this situation Descriptive Programming is very flexible.
 
Tests using Descriptive Programming can be executed in any version of QTP without any changes.



Code Portability: Just code is enough to run Tests. We can copy and paste in other scripts for any other required requirement.



Reusing of Properties: We can assign properties to a global variable and reuse it for same type of objects.



Plug & Play: Any time Tests will be in ready to run state. No need to worry about any other settings or files.



Just Maintenance of variables: We can store the object properties in the form of variables in a txt / vbs file which will be placed in central location. In this case we just need to maintain that file.
Types of Programmatic Descriptions (Descriptive Programming)
1) Static: - We enter the set of properties and values that describe the object directly in a VBScript statement.
a) Direct specification of description in script



Browser(“micclass:=Browser”).Page(micclass:=page”).Link(“name:=gcreddy”).Click



b) Assigning description to the variables and use that variables in script



g_MainBrowser    =“micclass:=Browser”

g_MainPage         =“micclass:=Page”

g_Lnk_Login        =“name:=Login”



Browser(g_MainBrowser).Page(g_MainPage).Link(g_Lnk_Login).Click
2. Dynamic: - We add a collection of properties and values to a Description object, and then enter the Description object name in the statement.
            Set oBrowser = Description.create

            oBrowser (“micclass”).value=”Browser”

            oBrowser (“name”).value= “Google”



            Set oPage = Description.create

            oPage (“micclass”).value=”Page”

            oPage (“name”).value= “Google”



            Set oLink = Description.create

            oLink (“name”).value= “Login”

            oLink (“index”).value= 1



Browser(oBrowser).Page(oPage).Link(oLink).click
Using the Static type to enter programmatic descriptions directly into your statements may be easier for basic object description needs. However, in most cases, using the Dynamic type provides more power, efficiency, and flexibility.
Handling Runtime added objects / Dynamic Objects / Same Description Objects
Dynamic objects               : Property values are getting changed regularly.



Same Description Objects  : Property values are same for multiple objects.



Runtime Added Object       : Object is not there in recording time but it might be add in runtime.



Ex: Always the job links in Naukri and Monster sites will get update. 
Child object method is very useful to get control on Runtime added objects or dynamic objects or same description objects which are there application.
Ex1: If there are multiple signin links on the page, using child objects method we can click on any signin link.
Descriptive Programming Examples:
 
Dim oLinkDescription

Dim oLinks

Dim lnkCount



Set oLinkDescription=Description.Create

oLinkDescription("name").value="signin"



set oLinks=browser("micclass:=Browser").page("micclass:=Page").ChildObjects(oLinkDescription)



if oLinks.count <>0 then



oLinks(0).click



End If

 ‘***********************************************************
This code will click on the first signin link. To click on second signin link replace ‘oLinks(0).click to oLinks(1).click in ‘if’ condition. In the same manner if any object properties are changed we can get index of the object using childobjects method.
Ex2: If there is a login page having username, password, signin button fields. Think that the signin button property is getting changed frequently from signin to login or enter. Then we can use child objects method to get the buttons count from the page, and then using index we click on the button which we want.
Set oButtonDescription=Description.Create

oButtonDescription ("micclass").value="Button"

set oButtons=browser("micclass:=Browser").page("micclass:=Page").ChildObjects(oButtonDescription)



for cnt=0 to oButtons.count-1

oButtons(cnt).highlight

Next
The above code will highlight all buttons in the page. This will make easy to identify the index of the button. Using index we can easily click on the button.
What method do we need to follow... Static or Dynamic?
There is no rule that we have to use static or dynamic. But based on situation we have to decide whether we need to use static or dynamic. If a single property is enough for an object then go for static. And go for Dynamic if multiple properties need to specify for an object. EX:

‘Static
Public const LoginPage_Edit_UserName        = “name:=UserName”



Public const LoginPage_Edit_PassWord         = “name:=Password”



Public const LoginPage_Button_Login = “name:=Login”
To use these constants in your script always it’s a good practice to follow is Keep these constants in a vbs file and associate to your QTP Test.
‘Dynamic
If you’re going for dynamic the only problem is repetitive code. Every time we need use description.create which leads to more maintenance. There are three objects and if we want to use multiple properties for those objects we need to write description.create for three times.
Solution:



Public const LoginPage_Edit_UserName        = “name:=UserName”



Public const LoginPage_Edit_PassWord         = “name:=Password”



Set LoginPage_Button_Login            = CreateObjectDescription(“name:=Login,type:=submit”)



‘******************************************************************

Function CreateObjectDescription(StrProperties)

          Dim objDescription

          Dim ObjArr

          Dim PropCount

          Dim ObjProperty

          

          Set objDescription=Description.Create



          ObjArr=split(StrProperties,",")

          

          For PropCount=0 to ubound(ObjArr)

                    ObjProperty=split(ObjArr(PropCount),":=")

                    objDescription(ObjProperty(0)).value=ObjProperty(1)

          Next

          

  Set CreateObjectDescription=objDescription

End Function

‘******************************************************************
This function gives a way to use multiple properties for any number of objects with less code maintenance. But the only one rule is we need follow is ‘set’ statement. Because the return value of the function CreateObjectDescription is a description object. To store any object in a variable we need to use ‘Set” statement.
The parameter which you pass to the function should be in string format.
EX: Set LoginPage_Button_Login                 = CreateObjectDescription(“name:=Login,type:=submit”)

Can I Use the combination of Object Repository and Descriptive programming in a statement?
Yes. But the hierarchy must be in Test Object to Descriptive.
Ex:‘Acceptable





Browser(OR LogicalName).Page(OR LogicalName).Link(“name:Login”).click
Or
Browser(OR LogicalName).Page(“micclass:Page”).Link(“name:Login”).click
Here the hierarchy is Test Object to Descriptive. Browser and page are representing Object Repository names and the link is taking description.
‘Not acceptable



Browser(“micclass:=Browser”).Page(OR LogicalName).Link(“name:Login”).click

                               Or       

Browser(“micclass:=Browser”).Page(“micclass:=Page”).).Link(OR LogicalName).click
This means that from the point where you have started giving description to the objects in a statement, you must continue giving description to the total objects in that hierarchy.
Using Regular Expressions
You can directly use regular expressions in the properties.



Ex1:

Public const LoginPage_Edit_UserName        = “name:=UserName.*”



Ex2:

Browser(“micclass:=Browser”).Page(micclass:=page”).Link(“name:=Login.*”).Click



Ex3:

Set oLink = Description.create

oLink (“name”).value= “Login.*”

oLink (“index”).value= 1



Browser(“micclass:=Browser”).Page(micclass:=page”).Link(oLink).click



By default regular expressions for description object is enable. To disable Regular expressions for description object



Set oLink = Description.create

oLink (“name”).value= “Login.*”

oLink (“name”).RegularExpression=False

oLink (“index”).value= 1

In continuation of my old post Descriptive Programming in QTP, I prepared this sample script for the beginners of Descriptive Programming.

'This is a sample script on Flight Reservation Application using Descriptive Programming
'Script Flow :- Open Flight Reservation Application --> Login --> Insert Order --> Open Order --> Delete Order
'Object Descriptions created in the script by using CreateObjectDescription Function.
'If object is using only one property then i have created a constant for it.

'*******************************************************************************
'Input Variables
'*******************************************************************************
Dim ApplicationPath
ApplicationPath=Environment("ProductDir")&"\samples\flight\app\flight4a.exe"

'*******************************************************************************
'Object Description Constants
'*******************************************************************************
'Login

Public Const Login_Dialog="text:=Login"

Set Login_Edit_AgentName=CreateObjectDescription("nativeclass:=Edit,attached text:=Agent Name:")
Set Login_Edit_Password=CreateObjectDescription("nativeclass:=Edit,attached text:=Password:")
Set Login_Btn_OK=CreateObjectDescription("nativeclass:=Button,text:=OK")

'Flight Reservation Window

Public Const FlightReservation_Window="text:=Flight Reservation"
Public Const FlightReservation_Menu= "menuobjtype:=2"
Public Const FlightReservation_OpenOrder_Menu="File;Open Order..."
Public Const FlightReservation_NewOrder_Menu="File;New Order"

Set FlightReservation_Obj_DateOfFlight= CreateObjectDescription("nativeclass:=MSMaskWndClass,attached text:=Date of Flight:")
Set FlightReservation_Cmb_FlyFrom= CreateObjectDescription("nativeclass:=ComboBox,attached text:=Fly From:")
Set FlightReservation_Cmb_FlyTo= CreateObjectDescription("nativeclass:=ComboBox,attached text:=Fly To:")
Set FlightReservation_Btn_Flight= CreateObjectDescription("nativeclass:=Button,text:=FLIGHT")
Set FlightReservation_Edit_Name=CreateObjectDescription("nativeclass:=Edit,attached text:=Name:")
Set FlightReservation_Edit_Tickets=CreateObjectDescription("nativeclass:=Edit,attached text:=Tickets:")
Set FlightReservation_Rdb_Class=CreateObjectDescription("nativeclass:=Button,text:=First")
Set FlightReservation_Btn_InsertOrder= CreateObjectDescription("nativeclass:=Button,text:=&Insert Order")
Set FlightReservation_Btn_UpdateOrder= CreateObjectDescription("nativeclass:=Button,text:=&Update Order")
Set FlightReservation_Btn_DeleteOrder= CreateObjectDescription("nativeclass:=Button,text:=&Delete Order")
Set FlightReservation_Edit_OrderNo=CreateObjectDescription("nativeclass:=Edit,attached text:=Order No:")

'Select Flights Dialog

Public Const FlightReservation_Dialog_FlightsTable= "text:=Flights Table"

Set FlightsTable_Lst_FlightList= CreateObjectDescription("nativeclass:=ListBox,attached text:=From")
Set FlightsTable_Btn_OK= CreateObjectDescription("nativeclass:=Button,text:=OK")

'Open Order Dialog

Public Const FlightReservation_Dialog_OpenOrder="text:=Open Order"

Set OpenOrder_ChkBtn_OrderNo=CreateObjectDescription("nativeclass:=Button,text:=&Order No.")
Set OpenOrder_Btn_OK=CreateObjectDescription("nativeclass:=Button,text:=OK")
Set OpenOrder_Edit_OrderNo=CreateObjectDescription("nativeclass:=Edit,window id:=1016")

'Flight Reservation Popup Dialog
Public Const FlightReservations_PopupDialog="text:=Flight Reservations"
Set FlightReservations_Btn_YES= CreateObjectDescription("nativeclass:=Button,text:=&Yes")

''*******************************************************************************
'Object Description Constants End
'*******************************************************************************

'#############################################################################
'Main Script Start
'#############################################################################
'Open Application
Call OpenApplication (ApplicationPath)

'Login
Call Login("Sudhakar","Mercury")

'Insert an Order
OrderInserted=InsertOrder()

'Open Inserted Order
Call OpenOrder(OrderInserted)

'Delete Inserted Order
Call DeleteOrder (OrderInserted)

'Close Application
Call CloseApplication()

'#############################################################################
'Main Script End
'#############################################################################

'Functions Start
'*******************************************************************************
Function OpenApplication(AppPath)
    InvokeApplication AppPath
End Function
'*******************************************************************************
'*******************************************************************************
Function Login(iUserName,iPassword)

Dialog(Login_Dialog).WinEdit(Login_Edit_AgentName).Set iUserName
Dialog(Login_Dialog).WinEdit(Login_Edit_Password).Set iPassword
Dialog(Login_Dialog).WinButton(Login_Btn_OK).Click

If err.Description="" Then
    Reporter.ReportEvent micPass,"Login","Login Successful"
Else
    Reporter.ReportEvent micFail,"Login","Login Failed"
End If
End Function
'*******************************************************************************
'*******************************************************************************
Function InsertOrder()

Window(FlightReservation_Window).WinMenu(FlightReservation_Menu).Select FlightReservation_NewOrder_Menu
Window(FlightReservation_Window).WinObject(FlightReservation_Obj_DateOfFlight).Type "111111"
Window(FlightReservation_Window).WinComboBox(FlightReservation_Cmb_FlyFrom).Select "Denver"
Window(FlightReservation_Window).WinComboBox(FlightReservation_Cmb_FlyTo).Select "Frankfurt"
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_Flight).Click
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_FlightsTable).WinList(FlightsTable_Lst_FlightList).Select 0
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_FlightsTable).WinButton(FlightsTable_Btn_OK).Click
Window(FlightReservation_Window).WinEdit(FlightReservation_Edit_Name).Set "sudhakar kakunuri"
Window(FlightReservation_Window).WinEdit(FlightReservation_Edit_Tickets).Set 10
Window(FlightReservation_Window).WinRadioButton(FlightReservation_Rdb_Class).Set
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_InsertOrder).Click
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_DeleteOrder).WaitProperty "enabled",true,10000
InsertOrder=Window(FlightReservation_Window).WinEdit(FlightReservation_Edit_OrderNo).GetROProperty("text")

If err.Description="" Then
    Reporter.ReportEvent micPass,"Insert Order","Order Inserted Successfully"
Else
    Reporter.ReportEvent micFail,"Insert Order","Failed in Inserting an Order"
End If

End Function

'*******************************************************************************
'*******************************************************************************
Function OpenOrder(OrderNumber)

Window(FlightReservation_Window).WinMenu(FlightReservation_Menu).Select FlightReservation_OpenOrder_Menu
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_OpenOrder).WinCheckBox(OpenOrder_ChkBtn_OrderNo).Set "ON"
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_OpenOrder).WinEdit(OpenOrder_Edit_OrderNo).Set OrderNumber
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_OpenOrder).WinButton(OpenOrder_Btn_OK).Click

If err.Description="" Then
    Reporter.ReportEvent micPass,"Open Order","Order Opened Successfully"
Else
    Reporter.ReportEvent micFail,"Open Order","Failed in Opening an Order"
End If

End Function
'*******************************************************************************
'*******************************************************************************
Function DeleteOrder(OrderNumber)

Call OpenOrder(OrderNumber)

Window(FlightReservation_Window).WinButton(FlightReservation_Btn_DeleteOrder).Click
Window(FlightReservation_Window).Dialog(FlightReservations_PopupDialog).WinButton(FlightReservations_Btn_YES).Click

If err.Description="" Then
    Reporter.ReportEvent micPass,"Delete Order","Order Deleted Successfully"
Else
    Reporter.ReportEvent micFail,"Delete Order","Failed in Deleting an Order"
End If

End Function
'*******************************************************************************
'*******************************************************************************

Function CloseApplication()
    Window(FlightReservation_Window).Close
    If err.Description="" Then
        Reporter.ReportEvent micPass,"Close Application","Application Closed Successfully"
    Else
        Reporter.ReportEvent micFail,"Close Application","Failed in Closing the Application"
    End If
End Function

'*******************************************************************************
'*******************************************************************************
Function CreateObjectDescription(StrProperties)

    Dim objDescription
    Dim ObjArr
    Dim PropCount
    Dim ObjProperty
   
    Set objDescription=Description.Create

    ObjArr=split(StrProperties,",")
   
    For PropCount=0 to ubound(ObjArr)
        ObjProperty=split(ObjArr(PropCount),":=")
        objDescription(ObjProperty(0)).value=ObjProperty(1)
    Next
   
  Set CreateObjectDescription=objDescription

End Function

'*******************************************************************************
'Functions End


Friday, 22 June 2012

Recording Modes in qtp

Three types of recording modes
1.Standard Recording(Default)
2.Analog recording
3.Low level recording
Standard recording
Records the test in terms of GUI objects
Records the objects in your application and the operation performed on them
This mode is the default and taken full advantage of qt test object model

Navigation:Automation->Record
or
Select Record option on automation tool bar
or
Short cut key F3

Analog Recording

Enables you to record the exact mouse and keyboard operation you perform in relation to either the screen or the application window
 Navigation:Keep Tool under Recording mode

Automation->Analog Record
or
Short cut key SHIFT+ALT+F3
VBSCRIPT stmt
window(“Microsoft Internet”).RunAnalog “Track1”
The  track file called by the run analog method contains all your analog data and is stored with the action

Low Level Recording
This mode record at the object level and records all runtime objects as window(Generally Multimedia Purpose)
 Navigation:Keep Tool under Recording mode

Automation->Low Level Recording
or
Short cut key CTRL+SHIFT+F3
 
Disadvantages of recording
1.It occupies a lot of memory space(due to duplicate objects),so QTP performance will be reduced
2.No Centralized Maintenance mechanism, So Modifications are very difficult
3.User may not have command on the Recorded Script, So locating errors is difficult
4.Recorded scripts are QTP internal files, they may corrupt

Advantages
1.It is used for analyzing the AUT in the initial stage to find out weather the Qtp tool is recognizing all of our application objects or not

2.It is easy to create/test scripts
3.It is used for frequently changing UI
4.It takes less time to create tests