Wednesday 27 November 2013

Calling multipe QTP scripts using VB file:

Well, Sometimes there comes a situation where we have to call multiple test files at a glance.
It would be cumbersome to call/open test one by one and run. Yet there are many alternative methods to achieve the same, but i love the way using array collection.
To make fully automated code/script you could even write a function to call all the tests from your test folder into the array collection dynamically and then executing the following code.Here, although, i have manually inserted every test into the array.

Function LoadNrun()
arrColl = Array(“C:\filename1″, “C:\filename2″,”C:\filename3″)
For each arrTest in arrColl
qtApp.Open arrTest
set qtTest = qtApp.Test
set objResultsOptions = CreateObject(“QuickTest.RunResultsOptions”) objResultsOptions.ResultsLocation = arrTest & “\Res1″ qtTest.Run objResultsOptions qtTest.Close
Next
End Function




*************************************************
How to close QTP Application through Code/Script/Descriptive Programming?
*************************************************

Close QTP Application:
Well,Question is simple but answer is little bit  complex. Here you need to search the desired application process on Win32_Process list.Microsoft MSDN has a good source of information on this topic. I am going to show the code without giving much explanation; Hope the code itself serves as a source of explanation
Please have a quick look on the above topic:
The Win32_Process:Win32 classes, such as Win32_NetworkAdapter or Win32_Process, monitor and manage system hardware and features. Generally, these classes are located in the root\cimv2 WMI namespace. The following table lists the Win32 class categories.WMI class represents a process on an operating system.
Source: http://msdn.microsoft.com/en-us/library/aa394084(v=VS.85).aspx

Code:
Function ClosemyApp()
Dim iCount iCount=0
Set oMyobj=GetObject(“winmgmts:\\.\root\CIMV2″)Set sCollectedProcess=oMyobj.ExecQuery(“select * from Win32_Process
where name=’QTPro.exe’ “)
For each iCount in sCollectedProcess iCount.Terminate()Next
Set sCollectedProcess=NothingSet oMyobj=Nothingmsgbox “Hurray!”
End Function


Wednesday 20 November 2013

Managing automated build dependencies with Maven and Hudson!!

One of the tricky parts of setting up a Continuous Integration build server is managing dependencies between build jobs. Many organisations have projects made up of tens or hundreds of different, interrelated modules, with complex dependencies between them. So when you change a module somewhere, you may need to rebuild and retest other modules that depend on this module.

One of the great features of Maven is the way it handles dependency management. Maven detractors may moan and groan about black magic and not being able to see what happens under the hood, but for me, declarative, transitive dependency management is a real life-saver.

Now, when you add Maven dependency management to Hudson automated builds, the result is nothing short of miraculous. Well, maybe I'm exagerating slightly, but it's certainly very cool. In short, if you use "Maven" build jobs in Hudson instead of the more frequently-used "free-style" build jobs, Hudson will figure out the correct build order all by itself - and rebuild all the other projects directly or indirectly affected by your changes.

Let's look at an example. Suppose my team is working on a Maven project called "core-api". We've already released one version of the core-api (version 1.0.0), which is available on the Maven enterprise repository for other teams. However, we are currently busy adding new features in the 1.0.1-SNAPSHOT version.

Now suppose we also have an application called "super-web-app", which we are building in conjunction with the core-api module. Now these two modules are essentially part of the same project, so we make the super-web-app depend on a snapshot release of core-api (1.0.1-SNAPSHOT). That way, I can make any changes in the core-api immediately available in the super-web-app application.

We are using Hudson as our CI server, using the "Maven" build jobs in Hudson to automatically build both these projects whenever a change goes to Subversion. Since they are intimately related, we would like the super-web-app build job to kick off whenever the core-api changes. Traditionally, you would do this by creating a post-build goal in your core-api build job to kick of the super-web-app job. But what if there are twenty other modules that depend, directly or indirectly, on the core-api? Do you have to add (and maintain) all of these post-build triggers by hand? And what if some of these other modules depend on older versions of my API, and don't give a hoot if I release a new snapshot version?

For example, across the hall, some colleages are working on the killer-web-app project. Their application still depends on core-api version 1.0.0. They are free to upgrade their version of the core-api when they need to, but it's pretty much up to them as to when they do so. So, as long as their dependency is on core-api version 1.0.0, the rebuilds of core-api-1.0.1-SNAPSHOT on Hudson should not trigger a build of their project.

The Hudson Maven projects handle this sort of build depencency management beautifully. When you kick off a build for a Maven project, it will automatically look at the other Maven build jobs on your server. If any of these depend on the Maven project currently being built, they in turn will be scheduled to be rebuilt. Note that Hudson takes into account the version number in the dependency - if core-api 1.0.1-SNAPSHOT is rebuilt, then only the modules depending on core-api-1.0.1-SNAPSHOT will be scheduled to be rebuilt - the modules depending on the older core-api-1.0.0 version will be left alone.


Note that this also works transitively, as you would imagine - if a change in project A causes Hudson to rebuild project B, and project C depends on project B, then project C will be rebuilt as well. This is a very elegent solution to a quite complex problem, and one that requires no specific configuration or maintenance in the Hudson build jobs - it relies entirely on the Maven dependencies to get the job done.

Sunday 3 November 2013

Small Example for Data Driven(Reading data from xl files)In QT P !!!!!!!!!!!!!!!!!!

Step 1) Lets Create these functions First(These functions are independent we can use these functions  for any application)

Function No1:-getRowCount
Function getRowCount(filePath,sheetName)
          '  all the cells for all the cols are empty
          ' know total cols in the sheet
Dim cols,isRowPresent,rows,isLastRow
cols = getColumnCount(filePath,sheetName)
rows=1 '  assuming there is one row
isRowPresent = true
isLastRow= false
     While isRowPresent
' check to see if all the cells are empty or not
Dim colNum
For colNum=1 to cols
If  readData(filePath,sheetName,rows,colNum) <> ""  Then
' this is not the last row
rows=rows+1
Exit for
End If
'    if you have just read the last cell
If  colNum = cols Then
' this is the last row
isLastRow = true
Exit for
End If
Next

' check if  its the last row
If  isLastRow Then
isRowPresent=false
End If
Wend

getRowCount=  (rows-2)

End Function

Function No2:- getColumnCount

'return total cols in a sheet
Function getColumnCount(filePath,sheetName)
Dim colCount
colCount=0 '  assume no cols
While trim(readData(filePath,sheetName,1,(colCount+1))) <> ""
colCount = colCount+1
Wend
getColumnCount= colCount


End Function

Function No3 :readData

Function readData(filePath, sheetName, row,col)
   Set objXls = createobject("Excel.application")  '' microsoft  xl
   objXls.Visible= false
   objXls.DisplayAlerts=false
   ' exit the function if file is not present
If NOT isFilePresent(filePath) Then
msgbox "FILE NOT PRESENT " & filePath
Exit function
End If

Set myXls = objXls.Workbooks.Open (filePath)
Set sheet = myXls.Sheets(sheetName)
readData = sheet.cells(row,col).value
' close everything
    myXls.Close
objXls.Quit

' destroy object
  Set objXls=nothing
  Set myXls=nothing
  Set sheet=nothing
End Function

Function No4:closeAllBrowsers

Function closeAllBrowsers
Dim desc,allBrowsers,i
   Set desc = description.Create
desc("micclass").value="Browser"
Set allBrowsers = desktop.ChildObjects(desc)
For i=0 to allBrowsers.count-1
   Browser("creationtime:="&i).close
Next

Set desc=Nothing
Set allBrowsers =Nothing
End Function


Function No5: isFilePresent

' function returns true if  file is present and false if not present
Function isFilePresent(filePath)
Set fso = createobject("Scripting.FileSystemObject")
If  fso.FileExists(filePath)  Then
isFilePresent = true
else
       isFilePresent=false
End If
' destroy object
Set fso= nothing

End Function



Step 2)Add these functions into your Action

Step 3)And follows The script 

Dim Login,Pwd,cnt
cnt=getRowCount("c:\abc.xls","Login")
'c:\abc.xls=path of your xls file 
'Login=sheet name 
msgbox cnt
For i=2 to cnt+1
closeAllBrowsers
Systemutil.Run  "http://www.salesforce.com","firefox"
set a=Browser("title:=.*").Page("title:=.*")
'a.Sync
a.link("name:=Login").Click
Login=readData ("c:\abc.xls","Login",i,1)
'msgbox Login
pwd=readData ("c:\abc.xls","Login",i,2)
'msgbox pwd
a.webedit("name:=username").Set Login
a.webedit("name:=pw").Set Pwd
a.webbutton("name:=Log in to Salesforce").Click
a.Sync
next

*******************************************************