Saturday, August 30, 2008

Converting Bitmap to GIF/JPG image

Earlier I have written a post about Automation Basics - Capturing Failures . Almost all the GUI testing tools are providing built-in functions to take the snapshot of screen. Snapshot can be taken for given screen co-ordinates or entire object.

Mostly these snapshots are stored as bitmap (*.bmp) files. Bitmap files are occupying more hard-disk space. It is difficult to maintain all the snapshots for each build in release-wise. IrfanView is a windows graphic viewer and it is a freeware utility. It has many command-line options for image related actions. You can just copy the executable file to another machine and can open or use immediately.

Syntax to Convert one image to another image format:
/convert=filename - convert input file to 'filename' and close IrfanView

Below I have given the way to implement in Silktest. This can be done for any testing tool.

[ ] //convert the image
[ ] SYS_Execute ("D:\autostuff\i_view32.exe {sBmpImage} /silent /convert={sGifImage}")

Wednesday, August 27, 2008

Restart Silktest Agent at Runtime

Last few months, I faced one issue and solved it by restarting silktest Agent.
We have a silktest suite for our Excel AddIn. It is developed by DotNet Framework. Silktest DotNet extension goes off after running 75-200 tests. Also facing this issue differently for both Excel 2003 and Excel 2007. Already I raised one post 'Application not responding" for this.

[ ] *** Error: Application is not responding
[ ] Occurred in Exists
[ ] Called from MSExcelAddIns at
[ ] Called from ASCS_EAIBaseState at
[ ] Called from SymmetricReport at
[ ] Called from TestcaseEnter at
[ ] Called from PreservingFunctions_ReplaceWithUpper at PreservingFunctions.t(238)
[ ] Error E_APP_NOT_RESPONDING) raised. Closing all applications
[ ] *** Error: Application is not responding
[ ] Occurred in Exists
[ ] Called from KillExcelApp at
[ ] Called from CloseAllApps at

Later selected cases are executed fine, If I close silktest agent and re-run few cases. I am able to figure out, where/when it is not able to identify. Then I tried to restart the agent in that machine, while scripts are executing continuously.

4Test code: To restart Silktest Agent

[-] void RestartSilkAgent ()
[ ] // To Restart Silktest Agent
[ ]
[ ] STRING sAgent
[ ]
[ ]
[ ] sAgent = GetMachineName ()
[ ] Print ("Agent name: {sAgent}")
[ ] Print (Desktop.GetActive ())
[ ] Disconnect (sAgent)
[ ]
[ ] Print ("**** Restarting Silktest Agent ...")
[ ] SYS_Execute ("D:\SampleDotNet\RestartAgent.bat")
[ ] Print ("**** Restarted Silktest Agent @@@@@@")
[ ]
[ ] Connect (sAgent)
[ ] Print (Desktop.GetActive ())
[ ]
[ ]

Friday, August 22, 2008

VBA - Extract Pictures from Excel

Last month, I have written Excel Automation Using VBScript. Today this post is to extract Pictures from Excel. Generally We can not use Export method for pictures. But we can use for Excel charts. I tried to extract our SVG chart image by macro and I succeed on it. I got help from Export pictures from Excel Below I've given the VBA Macro code.

VBA Macro - To extract Picture from Excel

Sub GetFirstPicture() Dim sCurrPath As String Dim aWorkSheet As Excel.Worksheet Dim aShape As Excel.Shape Dim aShapeChart As Excel.Shape Dim aPicture As Variant Dim aChart As Excel.Chart Dim sCurrentSheet As String Dim aImage As Variant Dim iIndex As Integer Dim iShapeCount As Integer Dim MyChart As String, MyPicture As String Dim PicWidth As Long, PicHeight As Long Dim sChartJpg As String Dim sChartGif As String Dim sChartBmp As String 'On Error GoTo ErrHandler On Error Resume Next Application.ScreenUpdating = False sCurrPath = "D:\VB\MyTrials\ChartExpFromXL" sChartJpg = "D:\VB\MyTrials\ChartExpFromXL.jpg" sChartGif = "D:\VB\MyTrials\ChartExpFromXL.gif" sChartBmp = "D:\VB\MyTrials\ChartExpFromXL.bmp" Set aWorkSheet = ActiveWorkbook.ActiveSheet sCurrentSheet = aWorkSheet.Name 'MsgBox CStr(msoTrue) + " value for MsoTrue" ' MsoTrue equals to -1 MsgBox "Shapes count " + CStr(aWorkSheet.Shapes.Count) For iIndex = 1 To aWorkSheet.Shapes.Count Set aShape = aWorkSheet.Shapes(iIndex) MyPicture = aShape.Name MsgBox aShape.Name + " Name, " + Str(aShape.Type) 'Picture 1 Name, 13 If Left(aShape.Name, 7) = "Picture" Then With aShape PicHeight = .Height PicWidth = .Width End With 'Set aChart = aWorkSheet.ChartObjects(1) Set aChart = ActiveWorkbook.Charts.Add ActiveWorkbook.ActiveChart.Location Where:=xlLocationAsObject, Name:=sCurrentSheet iShapeCount = aWorkSheet.Shapes.Count Set aShapeChart = aWorkSheet.Shapes(iShapeCount) MyChart = aShapeChart.Name '"Chart " & Str(aWorkSheet.Shapes.Count) aShapeChart.Width = PicWidth aShapeChart.Height = PicHeight With aWorkSheet aShape.Copy With ActiveChart 'aChart .ChartArea.Select .Paste End With .ChartObjects(1).Chart.Export Filename:=sChartJpg, FilterName:="jpg", Interactive:=True .ChartObjects(1).Chart.Export Filename:=sChartGif .ChartObjects(1).Chart.Export Filename:=sCurrPath & ".png" 'Not working .ChartObjects(1).Chart.Export Filename:=sChartBmp, FilterName:="bmp" aShapeChart.Cut End With Application.ScreenUpdating = True MsgBox "Completed." Exit Sub End If Next MsgBox "Completed." Exit Sub ErrHandler: MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description & " " & Err.Source Err.Clear ' Clear the error. End Sub

Sunday, August 17, 2008

Comparison between 4Test and C language Keywords

Few months back, I was going through 4Test Language Reference (Silktest 5.01) PDF document. There I have seen the comparison of C Language and 4Test. Then I searched the same table in Silktest8.5 Help documentation. It is available under 4Test Reference -> About the 4Test Language -> Comparison of 4Test and C.

Comparison Table: 4Test and C language Keywords

Data type / Feature

C Language

4Test Script

Any type: Stores data of any typeNo datatype available.ANYTYPE aName
Array int ai[10];
  • array [10] of integer ai
  • integer ai[10]
  • Arrays in 4Test can be dynamically resized.
Boolean: Stores either TRUE or FALSEint b;boolean b
Characterchar c;string c. 4Test has no seperate data type for single character.
Enumeratedenum COLOR{red, white, blue};type COLOR is enum red white blue
Floating-point float f; double d;
  • real f
  • real d
Integerint i; long, short, unsignedinteger i
ListSimilar datatype is not available.list of integer li. 4Test has dynamic lists.
NumericSimilar datatype is not available.number n.4Test NUMBER type stores either integers or floating point numbers.
Pointerchar *p; 4Test does not have pointers; however, data can be indirectly referenced using the @ operator.
Pointer to function int (*func) (); @(sFunc) ()
Stringchar s[5]; STRING s. 4Test strings are dynamically allocated; you do not need to declare their lengths.
Structure struct Person { char name[8]; int age; } type Person is record { string name integer age}
User-defined type typedef struct Person PERSON_INFO;type PERSON_INFO is Person
Type cast operator (typename) expression [typename] expression
Equality (==) operator differences if ((i=5) == TRUE) --> This code compiles in C if ((i=5) == TRUE) --> Ths code does not compile in 4Test:This difference is intentional. Because this construct can lead to unreadable code, 4Test does not allow it.

Friday, August 15, 2008

SilkTest - Convert String to List of String

Last month, my friend asked a silktest function similar to Split in QTP. Silktest does not have any built-in function. I thought to develop a function for this need. See the 4test code below:

4Test Code - Convert STRING contents as List of STRING

[+] List of STRING SplitToList (String sInput, String sDelimiter) [ ] List of STRING lsReturn = {} [ ] Integer iIndex =1 [ ] [+] while (GetField (sInput,sDelimiter,iIndex) != "") [ ] ListAppend (lsReturn, GetField (sInput,sDelimiter,iIndex)) [ ] iIndex++ [ ] [ ] return lsReturn

Sunday, August 10, 2008

Re-using VBS code

Last week, I wanted to call VBS file into another VBS file. I wanted similar way in other languages like below.
In C++ -> Header file -> include <*.h>
In VB -> Modules (*.bas)
In Java -> Packages -> import com.myLayer.*

Basically I wanted to make it as a library. I am writing the functions to get the data from Excel and PPT. I have to create separate VBS file for each requirement. Few functions are common for all the VBS files. I got a help from visualbasicscript site. Post: Include VBS file in other files

VBScript code - To Import VBS Library

' Method : ImportVBSLibrary
' Author : T. Palani Selvam
' Purpose : To import all vbs code from library file.
' Parameters: sFileName - String, contains the VBS functions
' Returns : VBS code
' Caller : - Nil
' Calls : - Nil
Function ImportVBSLibrary(sFileName)
Dim ObjFSO,ObjFile
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjFile=ObjFSO.OpenTextFile(sFilename,1)
Set ObjFile = Nothing
Set ObjFSO = Nothing
End Function

ExecuteGlobal ImportVBSLibrary("D:\myscripts\tools\pal_lib.vbs")

Friday, August 8, 2008

VBScript - Numbers as CmdLine Arguments

While I was preparing code for Excel Automation , I decided to pass the few integer values. Always the script got failed, if I pass the integer values through arguments. But the script went through fine, if I directly pass the parameters in that function call. While debugging the code, I was not able to find the reason for failure. I did Google search and unable to get the right solution.

Later I analyzed the code and put the simple conversion, while getting the arguments. The code worked as expected.

  1. To Convert String to Integer --> iStartRow = CInt (WScript.Arguments.Item(1))

  2. To Convert String to Double --> dExpVal = CDbl (WScript.Arguments.Item(2))

  3. To Convert String to Number --> nRowRange = Val (WScript.Arguments.Item (3))

To know more about the Command Line Arguments to VBScript, go through this post - Passing Command Line Arguments .

If you are unable to run any VBScript, See my old post - Unable to run VBScript / WScript / CScript in Windows XP .

Sunday, August 3, 2008

Silktest - Date Puzzle

I am always interested to participate in code competition. Recently I solved one puzzle like that.

Develop an algorithm to display the day of the week (Sunday to Saturday) for a given date. For example, if the date given is 07/07/2008 (8th July 2008, dd/mm/yyyy format), the algorithm would return Monday. Date 29/02/2008 will return Friday.

Solution - 4test code

[+] testcase Puzzle_4Test (STRING sGivenDate) appstate none [ ] // Puzzle: [ ] // Develop an alogrithm to display the day of the week (Sunday to Saturday) for a given date. [ ] // For example, if the date given is 07/07/2008 (8th July 2008, dd/mm/yyyy format), the algorithm would return Monday. [ ] // Date 29/02/2008 will return Friday. [ ] INTEGER iGivenYear, iGivenMonth, iGivenDay [ ] DATETIME dtFormat [ ] STRING sResult [ ] [ ] STRING sSeperator = "/" [ ] STRING sFormatRequired = "dddd" // To get the day in word [ ] [+] do [ ] [ ] iGivenDay = Val (GetField (sGivenDate,sSeperator,1)) [ ] iGivenMonth = Val (GetField (sGivenDate,sSeperator,2)) [ ] iGivenYear = Val (GetField (sGivenDate,sSeperator,3)) [ ] [ ] dtFormat = MakeDateTime (iGivenYear,iGivenMonth, iGivenDay) [ ] sResult = FormatDateTime (dtFormat,sFormatRequired) [ ] Print ("Puzzle1: Input - {sGivenDate}: Result - {sResult}") [+] except [ ] LogError ("Puzzle1: Input - {sGivenDate} is not in expected Format dd/mm/yyyy")