Showing posts with label Certification. Show all posts
Showing posts with label Certification. Show all posts

Sunday, June 15, 2008

QTP Tutorials 10 - Checkpoint Return Value

We will use the Standard Checkpoint which we did in tutorial 4.


Open that test that contains the standard Checkpoint.
In the expert view of the test you will see only one line i.e.


Window("Flight Reservation").WinButton("FLIGHT").Check CheckPoint("FLIGHT")


Now we will make some changes in this one line so that it can return some value.


NOTE: Checkpoint always returns a value, it depends on us whether we capture it or not.


Lets now capture it.
Declare a variable and catch the return value in that variable:


Dim return
return = Window("Flight Reservation").WinButton("FLIGHT").Check CheckPoint("FLIGHT")
msgbox (return)


One thing more we need to do here is that we have to enclose Checkpoint ("FLIGHT") in brackets. So the final version looks like this:


Dim return
return = Window("Flight Reservation").WinButton("FLIGHT").Check (CheckPoint("FLIGHT"))

msgbox (return)


It can return either true or false i.e. a boolean value. If it passes, it will return true else it will return false

QTP Tutorials 11 - Actions

In this tutorial we will see how to use more than one action in a test and how to call one action from another with in the same test.


Open a blank test. By default it will have Action1 in it (make sure you are in the keyboard view).


Make sure that Action1 is selected/highlighted and click on the Expert View tab.


In the Expert View type:
msgbox ("my action 1")


Again when you go to keyword View and expand Action1 it will show you function call under it.


In that keyword View itself go to Insert (Menu) ->Call to New Action. 'Insert Call to New Action' Dialog box opens with Action2 as a default name of a new action. By default it will be added at the end of the test as this radio button is selected in the location area.


Click ok.


It will add Action2 to your test.


Make sure that Action2 is selected and click on the Expert View tab.


In the Expert View type:
msgbox ("my action 2")


Similarly insert a third Action.


After third action is added, select Action1(keyword view), right click on it and choose 'Action Properties'.


In the Action properties window that opens, check the 'Reusable action' checkbox at the bottom.


Click ok.


Now again highlight Action3 right click on it and choose 'Insert Call to Existing action'.


'Select action' dialog box appears. In this dialog box in the 'action' dropdown box it will have Action1 by default since we made only that action as reusable.

Just click ok.


In the keyword View where you can see all the three actions, make sure against Action3 it shows "Call to Action1 action" under Documentation.


Run the test. Three message boxes appear in succession showing 'my action 1', 'my action 2', and again 'my action 1'.


QTP Tutorials 12 - Script to create file

Now lets do some kind of processing with file system e.g. working with text, excel, word etc files from within the QTP.

For this tutorial you need to know VBScript FSO (File System Object).


The main purpose of the FSO is to access the file system of the computer.


File System Object model is:


Drive
|
Folder
|
File
|
Textstream

or some people make it like this:

Drive
|
Folder
|
Folders
|
File
|
Files
|
Textstream

These above objects have methods and properties. With these above objects you can obtain and work with the information about drives, folders, files etc like creating a new file, opening a file, writing into a file and much more.


Here we will see a very simple example how to create a text file from within QTP.


Dim fso, new_file
Set fso = createobject("scripting.filesystemobject") // an instance of filesystemobject is being created here. After an instance (fso) is created then we can use the methods (like createtextfile, CreateFolder etc) with that objects instance.

Set new_file = fso.createtextfile("c:\testfile.txt", True) //createtextfile is a
method to create a file and after creating a file it returns a TextStream object
that can be used to read from or write to the file.
new_file.writeline("hello world!")
new_file.close

Just write the above text in the expert view of a new blank test and run it. A new text file (testfile.txt) will be created with "hello world!" written in it.


Try to change the extention of testfile.txt to testfile.doc and see what happens.


Much more to come, keep on reading guyz!!!

QTP Tutorials 13 - Regular Expression

Objects and text strings with varying (changeable) values or we can say dynamic values can be identified by QuickTest using Regular expressions.


Regular expressions can be used:

  • To define property values of an object.
  • To parameterize a step.
  • To create a checkpoint with changeable values.

Important points regarding Regular expressions:


You can use regular expressions only for values of type string.


When any special character in a regular expression is preceded by a backslash (\), QuickTest searches for the literal character.


You can define a regular expression for a constant value, a Data Table parameter value, an Environment parameter value, or a property value in a programmatic description.


For more common options to create Regular Expressions, see QTP User Guide.


Instead of writing more about QTP regular expressions, lets quickly jump to examples.


Below you will find examples.


QTP Regular Expression Example 1



[This is just an example using Yahoo mail inbox. Your inbox unread mails may differ from the one shown in this example]


1. Launch QTP and open a new test.
2. Open Internet Explorer.
[Now we have QTP with a blank test and Google open.]
3. Click on Record in order to start recording.
4. Copy and paste this URL (http://mail.yahoo.com) in the browser's address bar to open Yahoo mail login.
5. Type your user name and password to login to Yahoo mail.
6. When Yahoo mail is open, click on the Inbox link as shown in the screenshot below.[ Note: The Inbox can contain any number of mails. At any given point of time, Inbox(5) means 5 unread mails]
7. Click on Stop in order to stop recording. Then my recorded code looks like this:


Browser("Browser").Page("Page").Sync
Browser("Browser").Navigate "https://login.yahoo.com/config/login_verify2?&.src=ym"
Browser("Browser").Page("Yahoo! Mail: The best").WebEdit("login").Set "piyush
Browser("Browser").Page("Yahoo! Mail: The best").WebEdit("passwd").SetSecure "4801a2cbf793b46aad67194b5cbc961c091f"
Browser("Browser").Page("Yahoo! Mail: The best").WebButton("Sign In").Click
Browser("Browser").Page("Yahoo! Mail - piyush@yahoo.com").Link("Inbox (6)").Click


Now if you don't check any mail in your inbox and log out and then again run this code it will work fine.


But if you check any mail like if I check one mail in my inbox then it will be Inbox(5), then if I run this code it will fail because the link has changed from Inbox(6) to Inbox(5) and shows the below mentioned error.


"Cannot identify the object Inbox(6) (of class Link). Verify that this object`s properties match an object currently displayed in your application."


Now we will change the above code with the help of regular expression so that it will work even if there is only one unread mail.


In QTP go to Resources (menu) ->Object Repository.


Object Repository window will open. Select the object "Inbox(6)". Click on the label Inbox(6) inside Value column and then click on "<=>" button which will appear.


When you click on the button, it will open 'Value Configuration Options' window. On this window click on Regular Expression check box. When you click on checkbox it will show warning . Just click on Yes.


Now in the Constant text box inside the displayed window( what I have entered "Inbox \([5-6]\)" and click Ok and close Object Repository window.


This Regular Expression setting which we have done works for inbox unread mails between 5 and 6 e.g. if your inbox says inbox(5) or inbox(6).


Run the test. It passes for me because I had 5 unread mails in my inbox (inbox(5)).


You can do this setting according to your convenience e.g. [1-5] for unread mails between 1 and 5 and so on.