Custom Search

Thursday, October 21, 2010

Suppose I’m having a string wipro123xyz45 I need to get the value 12345 only from the string and the string could be changed randomly

Function RegExpTest(patrn, strng)
        Dim regEx, Match, Matches ' Create variable.
        Set regEx = New RegExp ' Create a regular expression.
        regEx.Pattern = patrn ' Set pattern.
        regEx.Global = True ' Set global applicability.
        Set Matches = regEx.Execute(strng) ' Execute search.
        For Each Match in Matches ' Iterate Matches collection.
              RetStr = RetStr & Match.Value' & vbCRLF
        Next
        RegExpTest = RetStr
End Function
a=(RegExpTest("[0-9]", "wipro123xyz45"))
msgbox(a)

Wednesday, October 20, 2010

Regular expression for date formate (mm/dd/yy)

[1-9]|1[0-2]/[1-9]|[1-2][0-9]|3[0-1]/[0-9][0-9] ------12/10/99

^([1-9]|1[0-2])[-/.]([1-9][1-2][0-9]3[0-1])/[-/.](19[0-9][0-9]|20[0-9][0-9])$ ----- 12(-/.)10(-/.)1999
|  Indicates a choice between two items.

how to compare two excell sheets by using vbscript??

Set objExcel = CreateObject("Excel.application")
objExcel.Visible = True
Set objWorkbook1 = objExcel.workbooks.Open("C:\First.xls")
Set objWorkbook2 = objExcel.workbooks.Open("C:\Second.xls")
Set objWorksheet1 = objWorkbook1.worksheets(1)
Set objWorksheet2 = objWorkbook2.worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
msgbox "value is different"
Else
msgbox "value is same"
End If
Next
objWorkbook1.close
objWorkbook2.close
objExcel.quit
set objExcel=nothing

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

Sunday, March 7, 2010

New Features in QTP 10.o


  • Centrally Manage and Share Testing Assets, Dependencies, and Versions in Quality Center 10.00

  • System Monitoring While Running Your Tests

  • Improve Portability by Saving Copies of Tests Together with Their Resource Files

  • Call Actions Dynamically During the Test Run

  • Develop Your Own Bitmap Checkpoint Comparison Algorithm

  • Centrally Manage Your Work Items and ToDo Tasks in the To Do Pane

  • Improve Test Results Analysis with New Reporting Functionality
  • Test Standard and Custom Delphi Objects Using the Delphi Add-in and Delphi Add-in Extensibility
  1. Centrally Manage and Share Testing Assets, Dependencies, and Versions in Quality Center 10.00
QTP 10 has a powerful set of new Quality Center 10.00 integration capabilities for QuickTest assets.*



These integration capabilities include:
1.New resources and dependencies model for storing and managing shared assets.
2.Support for asset versioning and baselines.
3.Asset Comparison Tool for comparing versions of individual QuickTest assets and Asset Viewer for           viewing an earlier version of a QuickTest asset.
4.A special tool for Quality Center administrators that upgrades all QuickTest assets to use these new features.

* QTP assets include tests, components, application areas, and the resources associated with them, such as shared object repositories, function libraries, recovery scenarios, and external data tables.

2. System Monitoring While Running Your Tests.

  • The new local system monitoring feature in QTP (File > Settings > Local System Monitor) enables you to monitor the local (client-side) computer resources used by the application instance you are testing during a run session.
  • You can monitor a number of different system counters to view the effects your application has on the system. You can also define upper limits for the counters. If any of the specified counters exceed these limits, the test run will fail.
  • Additionally, you can export the data from the System Monitor tab to a variety of file types.
  • The results generated for the counters you monitor are displayed as a line chart in a special System Monitor tab in the Test Results window.
 
3. Improve Portability by Saving Copies of Tests Together with Their Resource Files
 

  • Tests and their resource files are often stored on a network drive or in Quality Center. However, you may need to open or run a test when you do not have access to the network drive or QC. For example, you may need to create a portable copy of a test for use when traveling to other sites.
  • You can save a standalone copy of your test and its resource files to a local drive or to another storage device using the File > Save Test with Resources command. When you save a test in this manner, QTP a copy of your test, all associated resource files, and any called actions.

4. Call Actions Dynamically During the Test Run

  • Generally, when you insert a call to an external action, the action call becomes part of the test, and the called action is loaded each time you open the test.
  • In some situations, you may want to take advantage of the new LoadAndRunAction statement to load an action only when the step runs, and then run that action.
  • This is useful, for example, if you use many conditional statements that call external actions, and you do not want to load all of these actions each time you open the test, since these actions may not be necessary during the run session.

5. Develop Your Own Bitmap Checkpoint Comparison Algorithm

  • You (or a third party) can now develop custom comparers for bitmap checkpoints. A custom comparer is a COM object that performs the bitmap comparison for the checkpoint according to your testing requirements. For example, you could define a custom comparer that allows a bitmap checkpoint to pass even if the image in the application shifts by an amount specified when the checkpoint is defined.
  • After you install and register a custom comparer on the QTP computer, your comparer is available for selection in the Bitmap Checkpoint Properties dialog box. The dialog box provides space for specifying additional configuration preferences expected by your comparer.
  • When QTP a bitmap checkpoint that uses a custom comparer, it supplies the expected and actual bitmaps to the custom comparer object. It then receives and reports the results that the custom compares returns.

6. Centrally Manage Your Work Items and ToDo Tasks in the To Do Pane

  • The new To Do pane that is now available in the QTP, enables you to create and manage self-defined tasks, and to view a compiled set of the TODO comments from your tests, components, and associated function libraries.
  • For example, you can use the Tasks tab to provide instructions to someone else during a handover, or to create reminders for yourself. The Tasks tab provides check boxes in which you can mark off each task as you complete it. In the Comments tab, you can view and sort all your TODO comments. You can also jump directly to a selected TODO comment in the testing document.
  • If you use the Maintenance Run Wizard to detect updates needed to your steps or object repository, then you can use the To Do pane to track and manage the TODO comments added during the maintenance run session.
  • You can also export your tasks and TODO comments from the To Do pane to an XLS (Excel), CSV (comma separated), or XML file.

7. Improve Test Results Analysis with New Reporting Functionality

QuickTest 10.00 includes a powerful set of new reporting options that help you analyze and manage your run results more thoroughly and efficiently. These include:
  • Jump to step. When you want to know more about a particular node in the Test Results window, right-click it and select Jump to Step in QuickTest. The QuickTest main window comes into focus, and the cursor jumps to the relevant step. For more information, see Jumping to a Step.
  • Export Test Results to Microsoft Word or PDF Formats. In addition to HTML format, you can now select to save your QuickTest run results in Microsoft Word or PDF formats. You can then share this information, together with any local system monitoring data, with your developers and performance testing teams. For more information, see Exporting Test Results.

New Image Reporting Options:

  • Add Images to the Test Results. When you use the Reporter.ReportEvent method to add information to the run results, you can now specify an image file as the fourth argument. When you view the results, the image is displayed in the Result Details tab of the Test Results window. For example, you can include an image returned by a CaptureBitmap step in the run results. For more information, see ReportEvent Method in the Utility section .
  • View Bitmaps Differences in Bitmap Checkpoints. In addition to the expected and actual bitmaps that are displayed in the Test Results window, you can also select to view the differences between the two. The difference bitmap is a black-and-white image that contains one black pixel for every pixel that is different between the two images. For more information, see Analyzing Bitmap Checkpoint Results.
  • Include Images in Exported and Printed Test Results. When you choose the Detailed option for printing or exporting, the document now includes all images. These include screen captures of steps, expected, actual, and difference bitmaps for bitmap checkpoints, and any images sent to the run results using the ReportEvent method. For more information, see Printing Test Results.
  • Additional Quality Center Details. The run results for tests and components that are run as part of a Quality Center test set now include the Quality Center server and project nam
8. Test Standard and Custom Delphi Objects Using the Delphi Add-in and Delphi Add-in Extensibility
  • Test Standard and Custom Delphi Objects Using the Delphi Add-in and Delphi Add-in Extensibility
  • The new Delphi Add-in enables you to test Delphi controls that were created in the Delphi IDE and are based on the Win32 VCL library.
  • QTP Delphi Add-in Extensibility is an SDK (Software Development Kit) package that enables you to develop support for applications that use third-party and custom Delphi controls that are not supported out-of-the-box by the QTP Professional Delphi Add-in.

Wednesday, March 3, 2010

Write a Multiplication table in notepad

SystemUtil.Run"notepad"
Window("text:=Untitled - Notepad").Active
for i= 1 to 10
x=5*i
Window("text:=Untitled - Notepad").type "5*' & i & "=" &x
Window(text:=Untitled - Notepad").type micReturn
Next

Close all the opened web pages in one time

SystemUtil.CloseProcessByName("iexplore.exe")

get the number of the pages are closed

CloseCount=SystemUtil.CloseProcessByName("iexplore.exe")
Msgbox CloseCount

Descriptive programming in QTP

Type I:

Dialog("text:=Login").Winedit("attached text:=Agent Name:").set "UserName"
Dialog("text:=Login").Winedit("attached text:=Password:").set "Password"
Dialof("text:=Login").WinButton("text:=OK").click

In Above Example : - you will get the object properties name and Values from application using Object Repository OR Object Spy, you can use more than one property value for one object.

text is name of the object and Login is valu of the object.

Type II :

Set ObjDesc1=Desscription.create
ObjDesc1("text").value="Login"
Set ObjDessc2=Description.create
Objdesc2("attached text").value="Agent Name"
Set ObjDesc3=Description.create
ObjDesc3("attached text").value="Password"
Set ObjDesc4=description.Create
ObjDesc4("text").value="OK"
Dialog(ObjDesc1).Winedit(ObjDesc2).set "User Name"
Dialog(ObjDesc1).Winedit(ObjDesc3).set "Password"
Dialog(ObjDesc1).WinButton(ObjDesc4).click

In above example:- you can use more than one property value for one object.

Friday, February 12, 2010

how to create and run schedule task through vbscript and QTP

strJobDelete = "SCHTASKS /Delete /TN ""TaskName"" /F"
strJob = "schtasks /create /sc once /ru NetworkUsername(if u are in network) /rp Network Password /tn ""TaskName"" /tr ""filepath"" /st "time

Dim oShell
Set oShell = CreateObject ("WSCript.shell")
oShell.run "cmd /K cd/ & "& strJobDelete &"&"& strJob &"& exit"
Set oShell = Nothing

DOS -commands and it's help from command prompt

Above are the commands which are using from dos- prompt.
Below is the example for how to use and how to get help for those commands.
1. Help for Shut Down:
2. Help for Schedule task: