Thursday, January 29, 2009

To SET date and time format settings programatically.

I came up with this unique requirement of having to SET date and time format settings programatically. It is a bit tricky to do this using vbscript.
I googled a bit to find a snippet which really works :)
It is possible to play with it here and there to get the required format.

'=======================
Private Const LOCALE_SDATE = &H1F
Private Const LOCALE_STIMEFORMAT = &H1003
Private Const WM_SETTINGCHANGE = &H1A
Private Const HWND_BROADCAST = &HFFFF&

Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long

Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

Public Function SetDateTime() As Boolean
Dim dwLCID As LongdwLCID = GetSystemDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SDATE, "dd/MM/yyyy") = False Then
SetDateTime = False
Exit Function
End If
If SetLocaleInfo(dwLCID, LOCALE_STIMEFORMAT, "HH:mm:ss") = False Then
SetDateTime = False
Exit Function
End If
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
SetDateTime = True
End Function
'=======================
Change the LOCALE_SDATE variable value to get the desired results for Date format and LOCALE_STIMEFORMAT variable value for Time format.

Friday, January 2, 2009

Advanced scripting using OTA.

As we saw in OTA basics we were able to connect to any QC project in a matter of time. now once we have established connection with QC we can perform a variety of tasks. Before going for a long project let us divide it in smaller projects.
Think of normal everyday tasks in any software development organization using Quality Center for quality processes management. The day-to-day activities include daily builds, running basic tests, publishing reports.
We will take a large project called "AutoGenerator" which would perform following actions:
1) Verify build availability (assuming a build mail is received on build completion)
2) Kick start basic build verification tests (assuming the build is successful)
3) Execute the required tests (based on TestSets mentioned in QC)
4) Generate report (based on execution results)
5) Mail report

This is a long process which takes most of the time of any build engineer in any software organization and there are many dependencies due to which work may get delayed.
In simple words the project would work in minimizing these daily tasks by automating them.
The project would do wonders for both Dev and QA organizations as the test results would be available as the first thing in the morning and they can take approprite steps to cater it if anything goes wrong.

There are a lot of assumptions made while designing this project which are as follows:
1) The organization has a build process in place.
2) The build process also involves receival of mail using Outlook to intended recipents.
3) The organization uses QC for QA processes.
4) The organization uses QTP for automating their tests and scripts are saved in QC for execution.
5) Basic tests for verifying build are automated.
6) Reports are generated in Excel and published by mail.

Now let us divide this project in parts and have a look at one of them
Part 1 : Execute the required tests
Following is the code for same:
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
QCConnection.InitConnectionEx
QCConnection.login ,
QCConnection.Connect ,
Set TestSetFact = QCConnection.TestSetFactory
Set tsTreeMgr = QCConnection.TestSetTreeManager
Set tSetFolder = tsTreeMgr.NodeByPath()
Set TestSetsList = tSetFolder.FindTestSets()
Set theTestSet = TestSetsList.Item(1)
Set gettestlist = theTestSet.TSTestFactory
Set TestSetlist = gettestlist.NewList("")
For Each gettest In TestSetlist
gettest.HostName =
gettest.Post
Next
Set TestSetlist = Nothing
Set Scheduler = theTestSet.StartExecution("")
Scheduler.Run
Set execStatus = Scheduler.ExecutionStatus
Dim RunFinished, ExecEventInfoObj, TestExecStatusObj
RunFinished = execStatus.Finished
While RunFinished = False
Sleep 300000
execStatus.RefreshExecStatusInfo "all", True
RunFinished = execStatus.Finished
Wend
Set execStatus = Nothing
Set Scheduler = Nothing
Set TestSetlist = Nothing
QCConnection.Logout
QCConnection.Disconnect
Set QCConnection = Nothing

The code above assumes that you are running the suit on some specific Host machine which will need to be replaced at the mentioned location.
We will have a look at other part in the next section.