Thursday, May 14, 2009

How to check broken links in a webpage?

Broken link: A broken link refers to any clickable text that should take you to a document or webpage, that actually results in "page not found", a time out or any other type of error.

How can we verify these links in our application?

We can check the broken links by manually using Page Checkpoint.
To do this:
Step1: Start recording
Step2: Goto Inser Menu -> checkpoint -> Standard Checkpoint or
Start recording -> simply press F12(which is shortcut to Sandard Checkpoint)
Step3: Point to any object in the application -> Point to the Page object in Object Selection dialog box and click on the ok button.


Page Checkpoint Properties dialog box opens.
Step4: Select the "Broken Links" checkbox in "All objects in page" and click on ok button.


Step5: Stop recording.
If you run the script, QTP identifies any broken links in your web application.

We can also check the broken links by setting Advance web options.
To do this:
Step1: Tools Menu -> Options
Step2: Select the web tab and click on Advanced button
Step3: In Advanced Web Options, select "Create a checkpoint for each Web page while recording" check box and choose "Broken Links" check box and click on ok button

And click on ok button to close the options dialog box.

If you want to check the broken links for your current host,choose
Step1: Tools Menu -> Options and click on Web tab



Step2: select the "Broken links - check only links to current host" check box, which instructs QuickTest to check only for broken links that are targeted to your current host.

Wednesday, May 13, 2009

How to call a function existing in a DLL file using QTP?

Generally we cannot directly open the DLL files in notepad or in some editors to check the functions in a DLL.
We can use Dependency Walker or PE Explorer to open the DLL files to check the functions.

Here is the method to call a function existing in a DLL file:
We can use Extern object which enables you to declare calls to external procedures from an external dynamic link library.
Once you use the Declare method for a method, you can use the Extern object to call the declared method.

Syntax:
Extern.Declare(RetType, MethodName, LibName, Alias [, ArgType(s)])

RetType - Data type of the value returned by the method.
MethodName - Any valid procedure name.
LibName - Name of the DLL or code resource that contains the declared procedure.
Alias - Name of the procedure in the DLL or code resource.
Note: DLL entry points are case sensitive.
Note: If Alias is an empty string, MethodName is used as the Alias.

Example:
The following example uses the Extern.Declare and Extern. methods to change the title of the Notepad window.
'Declare FindWindow method
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
'Get HWND of the Notepad window
hwnd = Extern.FindWindow("Notepad", vbNullString)
if hwnd = 0 then
MsgBox "Notepad window not found"
end if
'Change the title of the notepad window
res = Extern.SetWindowText(hwnd, "Uday")

To check the above code, open one blank notepad file.
Observe the title of the notepad window will change to Uday.

Wednesday, May 6, 2009

How to pass parameters(input & output) between actions?

Here i want to pass two values from Action1 to Action2. In Action2 i am defining input parameters and output parameters. I do some operation and return the value as output parameter.

1. Start a new test
2. Create a new action by choosing Insert Menu -> Call to New Action
3. Choose "Reusable action" checkbox for Action2 and click Ok.
4. Now you are in Action2, now choose Edit Menu -> Action -> Action Properties and click on parameter tab.
Add two inpur parameters. To do this click on "+" sign.
Give the first parameter name as "a" and type as number.
Add another parameter with name as "b" and type as number.
In the output parameter add a parameter name with "result" of type number and click on ok button.
If any warning message displayed click on Yes button.
5. Do whatever operation you want in Action2. Here i want to add these values and assign to output parameter value soI am adding one statement called
parameter("result")=Parameter("a")+Parameter("b")
6. Now in the Keyword view, if Action2 is displayed, then right click on that action and choose delete. Choose "Delete the selected call to the action" and click ok button.
7. Now swith to Expert view and choose Action1.
8. Include the following two statements in Action1.
RunAction "Action2",0,34,54,var '(Here 34 and 54 vare const values i am supplying as input parameters to action2 and the result i am saving in 'var' variable).
msgbox var