Custom Search

Monday, May 28, 2012

How to change characters horizontal to vertical in one string using vb script


str=inputbox("Enter String","")
dim strArray()
For i = 1 to len(str)
   ReDim preserve strArray(i)
   strArray(i)=mid(str,i,1)
Next
For i = 1 to len(str)
   strmsg=strmsg& strArray(i) & vbNewLine
                     OR
   'strmsg=strmsg& strArray(i) & vbcrlf
Next
msgbox strmsg

Wednesday, May 23, 2012

How many types of actions in qtp

Reusable action: An action that can be called multiple times by the test with which it is stored (the local test), as well as by other tests.

Non-reusable action: An action that can be called only in the test with which it is stored, and can be called only once.

External action: A reusable action stored with another test. External actions are read-only in the calling test, but you can choose to use a local, editable copy of the Data Table information for the external action.

How to get Caps and small charecters count or seperate caps and small in one string

str= "KAMESwararao"
For i=1 to len(str)
a=mid(str,i,1)
If ASC(a)>=65 AND ASC(a)<=90 Then
strRes=strRes &a
else
strRes2=strRes2 &a
End If
Next
CapLen=len(strRes)
SmallLen=Len(strRes2)
msgbox "Your Result is- Caps : " &strRes &" - Small : "& strRes2
msgbox "Len of Caps : " & CapLen & "- Len of Small : " & SmallLen

OTherWay:
Dim myarray(),caps,small
mystring = "sAnKeTh"
For i=1 to len(mystring)
ReDim myarray(i)
myarray(i-1) =mid(mystring,i,1)
If myarray(i-1) = Ucase(myarray(i-1)) Then
caps = caps&myarray(i-1)
else
small = small&myarray(i-1)
End If
Next
msgbox caps
msgbox small

Friday, May 18, 2012

Creating Random string with required no of charecters

 Call GenerateRandomString(9)
Function GenerateRandomString(StrLen)
        Dim myStr
        Const MainStr= "abcdefghijklmnopqrstuvwxyz"
        For i = 1 to StrLen
          myStr=myStr & Mid(MainStr,RandomNumber(1, Len(MainStr)),1)
        Next
        GenerateRandomString = myStr
    End Function

Friday, May 4, 2012

Get the all Object class count in one web page


Using below code we get all the Object class count in one web page.
NOTE : It will not get the Webelements count in a page.

Set obj= description.Create
obj("class").value=".*"
set chobj=Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").ChildObjects(obj)
msgbox chobj.count
linkCount=0
editboxCount=0
checkboxCount=0
imageCount=0
listCount=0
For i=0 to chobj.count -1
                 Obj= chobj(i).tostring
                 ObjCla=Split(Obj,"] ")
                Select Case ObjCla(1)
                                Case "link"
                                                linkCount=linkCount+1
                                Case "edit box"
                                                editboxCount=editboxCount+1
                                Case "check box"
                                                checkboxCount=checkboxCount+1
                                Case "image"
                                                imageCount=imageCount+1
                                Case "list"
                                                listCount=listCount+1   
                End Select

Next

Print "No of Link in a page : " & linkCount
Print "No of editbox  in a page : " & editboxCount
Print "No of checkbox in a page : " & checkboxCount
Print "No of image in a page : " & imageCount
Print "No of listbox in a page : " & listCount

We have 5 actions in one test, i want to run only second action?

1.Go to the particular action(2) from actions drop down in QTP
2. Select "Run Current Action" from Automation menu. see below Image.


How to Create Dictionary object as Reserved Dictionary object and how to use that Reserved Object in one test

When you want to share data between different actions/Compare Large Data in a test, dictionary object can be used. To do this you should create a reserved test object for the Dictionary object. Here is a process to set up a reserved dictionary object.

  1. Open Window’s registry by opening a Run window and entering regedit.
  2. Navigate to HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects.
  3. Create a new key (folder) named GlobalDictionary by right-clicking on the ReservedObjects key and selecting New -> Key.
  4. Under the new key, create a String value named ProgID by right-clicking on GlobalDictionary and selecting New -> String Value.
  5. Assign “Scripting.Dictionary” to the new ProgID string value by right-clicking on ProgID and selecting “Modify.”
  6. If QTP window is already open you need to close and restart it.
  7. Now to check whether dictionary object was installed successfully in registry, simple write GlobalDictionary. (don’t forget the dot) and you should see a drop-down containing all methods and properties associated with dictionary object.
  8. This Reserved Object is the System Specific, so we need to the above setup in another system where we run Reserved Object code. without setup it won't work that code.

Thursday, May 3, 2012

If in VbScript we are not using ByRef and ByVal keyword, what is the methos to pass variables by val?

ByRef (its default)

Functions present in liabray file in QTP are public or private?

public (if you dont specify any thing in declaration)

Difference between Array and Dictionary object?

Array has only index(the index can be ONLY numeric), but Dictionary object has both key and item. Items can be any form of data, each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string.

How to Execute program on remote computer?


Using below windows calss we can execute any program on remote machine.

1.Win32_Process Class
2.Win32_ScheduledJob Class

1. Win32_Process

strComputer = "10.76.10.202" ' here you should ahnge with your remote machine name
strCommand = "Iexplore.exe"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
If errReturn = 0 Then
   Wscript.Echo "notepad.exe was started with a process ID: " & intProcessID
   Else
   Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If

2.Win32_ScheduledJob

strComputer = "10.76.10.202"
strCommand = "iexplore.exe"
Const INTERVAL = "n"
Const MINUTES = 1
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)
If errReturn = 0 Then
Wscript.Echo "notepad.exe was started with a process ID: " & intJobID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If