Custom Search

Tuesday, September 21, 2010

Diff B/w Actions and Functions

1.Action is a specific to QTP while functions are a generic thing which is a feature of VB Scripting. 
2.Action have a object repository, Data table etc associated with it while a function can't. 
3.A function is just lines of code with some/none parameters and a single return value while an action can 
have more than one input/output parameters. 

Open a Google page without using systemUtil.Run command?

Dim wsh
Set Wsh = CreateObject("Wscript.Shell")
Wsh.run "iexplore google.com"

Monday, September 20, 2010

write the code to reverse a string without using Strrev built in function.

Dim i
Dim iStrLen
Dim strOut
Dim strTmp
Dim strMyString
strString=("Please enter the string to be reversed:")
iStrLen = Len(strString)
For i = 0 To Len(strString) - 1
         strOut = Mid(strString, iStrLen - i, 1)
         strTmp = strTmp & strOut
Next
strMyString = strTmp
msgbox strMyString
--------------------Second Scenario-----------
MyStr = inputbox("Enter the String:")
nCnt = Len(MyStr)
For i = 1 to nCnt
   RevStr = Mid(MyStr,i,1)&RevStr
Next
Msgbox RevStr
-------------Third Scenario---------------
Dim yourstr,r,letter,result
yourstr="Automation"
Set r=new regexp
r.pattern="[a-z 0-9 A-Z]"
r.global=true
set s=r.execute(yourstr)
For each i in s
    result= i.value&result
Next
msgbox result

what is the script to select 2 or more than 2 options from a listbox.

Browser().Page.().weblist().Select " "
Browser().Page.().weblist().Extendselect " "
by using extendselect method we can select more than one at a time from list box.

How do you return two values from a function

result=example(2,3)
function example(a,b)
      dim myarray(2)
      myarray(0) = a+b
      myarray(1)=a*b
      example=myarray
end function
msgbox result(0)
msgbox result(1)

How do you return a value from a function

msgbox "returned value =" &example(2,3)
function example(a,b)
     example = a+b
end function

How to handle Dynamic Arrays?

Declaring an array with empty parentheses(without dimension subscripts) is called Dynamic arrays.
Ex: Public\Private\Dim ArrayName ( )
The ReDim statement is used to size or resize a dynamic array.
Using ReDim statement You can change the number of elements and dimensions in an array repeatedly.
Ex: 1 )  Dim  X(10) 
            ReDim X(15)
Ex :2 ). Dim X(10, 10) 
            ReDim  X(10, 15) 
            Here if your array has two or more dimensions, you can change the size of only the last dimension   only.

NOTE: If you are using ReDim for changing the size or Dimensions of Dynamic array, it's erasing an existing data contained in the array. to avoid this you should use Preserve Keyword before the array name.

Ex: Dim X(10)
       ReDim Preserve X(15)

What is the Difference Between Wait and Sync?

Wait is like forcing the qtp to wait for specified amount of time,whereas sychronization is not forced wait.
If the webpage gets loaded before the specifed time,it moves to next step in case of synchronization.
If the webpage wait time is 10 sec and the page loaded in 2 sec,it waits for the remaining 7 sec in case of wait statement given.

what are the environment variables,how do you use them. give an example.

Environment Variables are variable whose value is fixed for its usage everywhere.
There are two types.
1.Built in-which are already existing in QTP which we can directly use in out script.
ex:ActionName,ActionIteration
2.User-defined
which user has to define and use those variables anywhere in the action.
Ex:File path-Suppose you are reffering a data file in ur script then store the location of your file path in environment variable and use it across the actions.

IF there are seven browsers with same name open. I want to close one particular browser thru QTP. how can i do this?

If you want close 1 browser you can using below code.
browser("CreationTime:=0").close
because creation time starts from 0

How to Map network drive(Server) as a Drive in your local PC

Dim WshNetwork

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "E:", "\\Server\Public"

Sunday, September 19, 2010

How can i Save the snapshots in a specified folders

dialog("Login").WinEdit("Agent Name:").CaptureBitmap"C:\sample.bmp",true

The string is like KAMESWARARAO , write a script for this how to find out the number of "A" in the string ?

str="KAMESWARARAO"
counter=0
For i=1 to len(str)
       strChar=mid(str,i,1)
       If strChar="A" Then
              counter=counter+1
       End If
Next
msgbox counter

===========Second Method========
msgbox Len(str)-Len(Replace(str,"A",""))

What is the difference between Systemutil.run , invokeapplication and Navigate.

Navigate: Opens a specified URL in the browser.
The InvokeApplication method can open only executable files
Run any application from a specified location using a SystemUtil.Run statement

what is Option Explicit in QTP

Option Explicit statement to force explicit declaration of variables.

Defference between pass byVal and ByRef

ByVal : Indicates that the argument is passed by value.

ByRef : Indicates that the argument is passed by reference.

While passing the value using by reference then, if anything (value) is changed, it’s effected to original value.

While passing the value using by valuee then, if anything (value) is changed, it’s not effected to original value it’s only changed in that particular place.

I have given u a application to automate it what are the things will u consider

1. Consider functional requirements.
2. As per requirement identify how much automation testing required.
3. which part of the application need to automation testing.
4. Automation tool
5. Framework
6. Most important test plan which contains every details about every activity of testing.
7.Cost and licence of tool
8.availablity of technical experts and assistance of tool support
9.timelines

There are some links on the web page,write a script to count and click those links and check the text on the page displayed on clicking the links.

Set obj=Description.Create()
obj("micclass").value="Link"
Set links=Browser("Gmail: Email from Google").Page("Gmail: Email from Google").ChildObjects(obj)
countLinks=links.Count
msgbox "Num of links"& links.Count
For i=0 to countLinks-1
        text= links(i).GetROProperty("Text")
        If text="Link Name" Then
              links(i).click
         End If
next