Sunday, September 28, 2008

Children objects has negative co-ordinates in Browserchild

Last year, one web based product has been revamped with our own reporting modules. Lot of javascripts used for this reporting. Silktest is able to identify the HtmlTable and HtmlColumn objects properly. But the co-ordinates are shown wrong. Each click action is done in different point instead of expected point. Only X-Axis position got changed. See the RECT info below.

BrowserChild (Parent) rect: {195, 175, 827, 538}
Htmltable rect: {-77, 323, 818, 574}


It is varying for different kind of reports. Testcases need to do left-mouse click and right-mouse clicks. I have set few variables for position changes. I have written the code like below. In the Runtime, XAxis changes (ixGridInc) are calculated dynamically. I have given the code below:

4Test code - To set the Table position dynamically


[-] void SetGridTablePosChanges (Window wTable)
[ ] // To set xAxis and YAxis increments (changes)
[ ] // Position changes.
[ ] Window wParent
[ ] Boolean bxGetPos = FALSE
[ ] String sWinTag, sMainFrameTag
[ ]
[ ] RECT rtTblCell = wTable.GetRect (TRUE)
[ ] Print ("table rect: {rtTblCell}")
[ ]
[-] if (ixGridInc == -1)
[ ] Print ("Grid xAxis increment is going to set.")
[ ] ixGridPos = rtTblCell.xPos
[ ] // iyGridPos = rtTblCell.yPos
[ ] bxGetPos = TRUE
[-] else if (ixGridPos != rtTblCell.xPos)
[ ] bxGetPos = TRUE
[ ] ixGridPos = rtTblCell.xPos
[ ] // iyGridPos = rtTblCell.yPos
[-] else
[ ] Print ("Already Grid xAxis increment is available.")
[ ]
[-] if (bxGetPos)
[ ]
[ ] sMainFrameTag = WindowTag (wTable)
[ ] sWinTag = GetField (sMainFrameTag,"[BrowserChild]",3)
[ ] Print ("Whole Table tag: {sMainFrameTag}")
[ ] Print ("Parent tag: {sWinTag}")
[-] if (MatchStr ("*[6]*",sWinTag) || MatchStr ("*mainFram*",sWinTag))
[ ] wParent = MyReportPage
[ ] RECT rtTblCell2 = wParent.GetRect (TRUE)
[ ] Print ("Parent rect: {rtTblCell2}")
[ ]
[-] if ((rtTblCell.xPos < (rtTblCell2.xPos + XAXIS_TABLE_DIFF)) )
[ ] ixGridInc = rtTblCell2.xPos - (rtTblCell.xPos) + XAXIS_TABLE_DIFF
[ ] Print ("X Axis changed Position: {ixGridInc}")
[-] else
[ ] Print ("Parent{wParent} is not expected one.")

Tuesday, September 16, 2008

Automating Windows/Unix/Linux Server calls by w3Sockets

Earlier I have written a post Expect-Automating Command line tools for Expect utility. Now we can access any server machines by using VBScript. Dimac Development has implemented a COM interface to connect through Telnet and made as freeware. You need to download w3Sockets Dll and register it using SocketReg.exe included in a zip file. It is similar to expect utility. You can verify each command and can change the execution flow based on console output. It is much useful for automated testing as well as server administration. Below I have given a sample code to start windows services.

w3Sockets Reference
w3Sockets - Download Page

To start servers on Windows/Unix/Linux Systems



'To start servers on Windows/Unix/Linux server
Dim w3sock

Set w3sock = CreateObject("socket.tcp")
With w3sock
.timeout = 5000
.DoTelnetEmulation = True
.TelnetEmulation = "TTY"
.Host = "myserver:23"
.Open
.WaitFor "login:"
WScript.Echo .Buffer
.SendLine "myloginid"
.WaitFor "password:"
.SendLine "Password12"
.WaitFor ">"
.SendLine "net start ""MyServer Manager"""
.WaitFor ">"
WScript.Echo .Buffer
.SendLine "net start ""MYDB Repository"""
.WaitFor ">"
WScript.Echo .Buffer
.Close
End With
Set w3sock = Nothing

Saturday, September 13, 2008

Lightweight Directory Access Protocol

Last few months, I'm trying to put a post for LDAP. Now LDAP is widely used in many companies. LDAP Testing is bit different from (native mode) user authentication. Again It is divided as single domain and multi-domain LDAP. Test team is treating LDAP as a another environment/stack to certify any product.

LDAP - Lightweight Directory Access Protocol. LDAP has become a mandatory in IT Projects. It is a set of protocols for accessing information directories. LDAP is based on the standards contained within the X.500 standard, but is significantly simpler. Also unlike X.500, LDAP supports TCP/IP, which is necessary for any type of Internet access.

The LDAP Interchange Format (LDIF), defined in RFC 2849, is a standard text file format for storing LDAP configuration information and directory contents. The dn attribute uniquely identifies the DN of the entry. In its most basic form, an LDIF file is:

  • A collection of entries separated from each other by blank lines

  • A mapping of attribute names to values

  • A collection of directives that instruct the parser how to process the information


Descriptions for commonly used abbreviations:
  • cn - Common Name

  • ou - Organizational Unit

  • dc - Domain Component

  • dn - Distinguished Name

  • rdn - Relative Distinguished Name

  • upn - User Principal Name


Sample LDAP configuration:
Principal : cn=admin,cn=Users,DC=rmdomain,DC=com
Users baseDN : DC=rmdomain,DC=com
Group baseDN : DC=rmdomain,DC=com
Bind User DN : cn=admin,cn=users,dc=rmdomain,dc=com

To know more about LDAP

Wiki - Lightweight Directory Access Protocol
LDAP Concepts & Overview
LDAP Authentication

Saturday, September 6, 2008

Saving Clipboard contents as Image

Scenario 1:
Earlier I had a challenging task to automate SVG charts. There are two issues. Major issue is, Silktest does not identify SVG Chart as any object (custom/HtmlImage). Second one is taking Bitmap image for the chart. SVG chart gives the flexibility by 'Copy SVG' feature. Using this we can copy the chart image. It can be saved as text or Image file.

Scenario 2:
Last month, I have posted VBA - Extract Pictures from Excel . It works fine, if this VBA code is executed as Excel Macro. But the same code does not extract the image with the right quality, after running as VB Script. I got the problem, while saving/pasting the clipboard copy. I was forced to find a way to implement a method, to save clipboard image as a image file.

Solution:
IrfanView is a windows graphic viewer and it is a freeware utility. It can be used command-line utility. It has a command-line option to save the clipboard image as image file. You can save the image in many different formats.

Syntax to Convert clipboard image as image file:
/clippaste - paste image from the clipboard.

Below I have given the way to implement in VBScript and Silktest.
Silktest code:


[ ] // To save the image
[ ] SYS_Execute ("D:\autostuff\i_view32.exe /silent /clippaste /convert=D:\my_scripts\testdata\zsvg1.bmp")


VB Script code:

'-------------------------------------------------------------------------
' Method : CreateImageFromClipBoard
' Author : Palani Selvam
' Purpose : It gets the clipboard image and convert as a image file.
' Parameters: FileName - String, contains the BMP file name
' iIndex - Integer, contains the Worksheet index
' Returns : String. The replaced file name it gives.
' Caller : - Nil
' Calls : - Nil
'-------------------------------------------------------------------------
Sub CreateImageFromClipBoard(sFileName)

Dim wshShell,ShellReturnCode, sCmdExec

Set WshShell = WScript.CreateObject("WScript.Shell")
sCmdExec = "D:\autostuff\i_view32.exe /silent /clippaste /convert="& sFileName

ShellReturnCode = WshShell.Run(sCmdExec, 1, True)

End Sub


Modified VB Script code for VBA - Extract Pictures from Excel
Note: Few function calls are from my vbscript library.

'--------------------------------------
' Method : ReadExcel
' Author : T. Palani Selvam
' Purpose : Read all the contents from Excel sheet and write into log file
' Parameters: sExcelFile - String, contains the Excel file
' : iSheetIndex - Integer, Value for Sheet Index
' Returns : - Nil
' Caller : - Nil
' Calls : - Nil
'--------------------------------------
Sub ReadExcel(sExcelFile, iSheetIndex)
Dim sExcelPath 'As Variant 'Excel file
'********** Excel object declaration **********'
' Excel Application object
Dim objExcel 'As Excel.Application
Dim objXLWorkbooks 'As Excel.Workbooks
Dim objXLWorkbook 'As Excel.Workbook

Dim WorkSheetCount 'As Variant 'Work sheets count in a excel
Dim CurrentWorkSheet 'As Excel.Worksheet ' Current worksheet
Dim objCells 'As Excel.Range
Dim objCurrentCell 'As Variant
Dim objFont 'As Variant

' Result contents
Dim sCellText 'As Variant
Dim sFontName 'As Variant
Dim sFontStyle 'As Variant
Dim iFontSize 'As Variant
Dim iCellTextColorIndex 'As Variant
Dim iCellInteriorColorIndex 'As Variant
Dim sResult 'As Variant
Dim sChartFile 'As String


' Row and Col integer variables
Dim iUsedRowsCount 'As Integer
Dim iUsedColsCount 'As Integer
Dim iTop, iLeft 'As Integer
Dim iRow 'As Integer 'Row item
Dim iCol 'As Integer 'Col item
Dim iCurRow 'As Integer
Dim iCurCol 'As Integer


If (sExcelFile = "") Then
sExcelPath = "D:\my_scripts\Basic Wks.xls"
Else
sExcelPath = sExcelFile
End If

If (iSheetIndex = "") Then
iSheetIndex = 2
End If


Call FileDeleteAndCreate (gsLogFile)

'XL file check
If (FileExists(sExcelPath) <> 0) Then
Call LogWrite (gsLogFile, "The Excel file " & Chr(34) & sExcelPath & Chr(34) & " does not exit!")
Exit sub
End If

Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open sExcelPath, False, True

On Error Resume Next

Set objXLWorkbook = objExcel.ActiveWorkbook
'objXLWorkbook.RunAutoMacros

WorkSheetCount = objXLWorkbook.Worksheets.Count

Set CurrentWorkSheet = objExcel.ActiveWorkbook.Worksheets(iSheetIndex) 'iSheetIndex worksheet

iUsedRowsCount = CurrentWorkSheet.UsedRange.Rows.Count
iUsedColsCount = CurrentWorkSheet.UsedRange.Columns.Count
iTop = CurrentWorkSheet.UsedRange.Row
iLeft = CurrentWorkSheet.UsedRange.Column

' Cells object
CurrentWorkSheet.Cells.Activate


For iRow = iTop To iUsedRowsCount-1 '(iUsedRowsCount - 1)
'Read All rows
For iCol = iLeft To iUsedColsCount '(iUsedColsCount - 1)

sResult = ""
Set objCurrentCell = CurrentWorkSheet.Cells(iRow, iCol)
sCellText = objCurrentCell.Text


If ((sCellText = Empty)) Then


sResult = "Reading Cell {" & CStr(iRow) & ", " & CStr(iCol) & "}^" &" "& "^" & " " & "^" & " " & "^" & " " & "^" & " " & "^" & " "

Call LogWrite (gsLogFile, sResult)

Else
Set objFont = objCurrentCell.Font
sFontName = objFont.Name
sFontStyle = objFont.FontStyle
iFontSize = objFont.Size
iCellTextColorIndex = objFont.Color
iCellInteriorColorIndex = objCurrentCell.Interior.ColorIndex



If (sFontName = Empty) Then
sFontName = "empty"
End If
If (sFontStyle = Empty) Then
sFontStyle = "empty"
End If
If (iFontSize = Empty) Then
iFontSize = "-99999999"
End If
If (iCellTextColorIndex = Empty) Then
iCellTextColorIndex = "99999999"
End If
If (iCellInteriorColorIndex = Empty) Then
iCellInteriorColorIndex = "99999999"
End If


sResult = "Reading Cell {" & CStr(iRow) & ", " & CStr(iCol) & "}^" & sCellText & "^" & CStr(iCellInteriorColorIndex) & "^" & sFontName & "^" & CStr(sFontStyle) & "^" & CStr(iFontSize) & "^" & CStr(iCellTextColorIndex)

Call LogWrite (gsLogFile, sResult)

End If

Set objCurrentCell = Nothing


Next

Next
'Get the Chart now
'sChartFile = Replace (sExcelFile,".xls",".png")
sChartFile = Replace (sExcelFile,".xls",".bmp")

'*****************************
' Place for Chart creation
objExcel.ScreenUpdating = False

Dim iIndex,iPictureHeight,iPictureWidth,iShapeCount
Dim aShape, aChart, aShapeChart, aChart1
Dim sPictureShape, sChartName, sCurrentSheet


'Set aWorkSheet = ActiveWorkbook.ActiveSheet

sCurrentSheet = CurrentWorkSheet.Name

For iIndex = 1 To CurrentWorkSheet.Shapes.Count

Set aShape = CurrentWorkSheet.Shapes(iIndex)
sPictureShape = aShape.Name
'Picture 1 Name, 13

If Left(aShape.Name, 7) = "Picture" Then
aShape.CopyPicture
Call CreateImageFromClipBoard (sChartFile)

''objExcel.ScreenUpdating = True
Exit For

End If
Next

if FileExists(sChartFile)=0 Then
Call LogWrite (gsLogFile, "Chart Image: " & sChartFile)
End If

' This will prevent Excel from prompting us to save the workbook.
objExcel.ActiveWorkbook.Saved = True
Set CurrentWorkSheet = Nothing

'objExcel.Worksbooks.Close
objExcel.Quit

''Set CurrentWorkSheet = Nothing
Set objExcel = Nothing

'MsgBox "Read Completed.", vbOKOnly, "Exec Over"
Exit Sub

ErrorHandler1:
'MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description
'Err.Clear ' Clear the error.
End Sub

Wednesday, September 3, 2008

Convert failed testcases as a testplan

We have few silktest automation projects. One project is used to execute by suite. Another one is ran by batch (*.bat) file, which has few sub-plans. I am not able to run the failed cases from all results at one shot. I was looking an utility, similar to 'Mark failures in Plan' in the results menu. I thought to implement a 4test script to convert failed testcases as a testplan and I did it.

4Test code - Create testplan for failed cases only

[ ] LIST OF STRING glsFailedScripts = {} [ ] [+] testcase ConvertTestPlan_SingleFile () appstate none [ ] [ ] STRING sResFile = "D:\Auto_Scripts\Results\MyStuff_MasterPlan.res " [ ] STRING sRexFile = "D:\Auto_Scripts\Results\MyStuff_MasterPlan1.rex " [ ] STRING sMyPlanFile = "D:\Auto_Scripts\Results\zSingleFailed.pln " [ ] [ ] glsFailedScripts = {} [ ] CreateFileFromTemplate(sPlanTemplate,sMyPlanFile) [ ] ResExport (sResFile,sRexFile) [ ] ProcessSingleREXFile (sRexFile,sMyPlanFile) [ ] [ ] Agent.DisplayMessage ("test","Completed.") [ ] [-] // functions [+] Boolean GetFailedTestInfo (STRING sRexLine, out LIST OF STRING lsPlanInfo) [ ] [ ] // Title [ ] //TestPlan Script TestCase TestData ErrorCount ErrorText DateTime Elapsed [ ] [ ] // Samples [ ] // "D:\Auto_Scripts\PlanFiles\MyStuff_MasterPlan.pln","D:\Auto_Scripts\Scripts\FamilyFunctions.t","FamilyFunctions_DimensionFunctions_5", [ ] // "Verify user sees a proper error message by clicking OK button.",0,"","2008-08-18 21.52.06","0:00:00" [ ] [ ] STRING sScript [ ] STRING sTestCase [ ] STRING sTestData,sFormattedData [ ] STRING sTestTime [ ] STRING sErrCount, sErrCount1 [ ] INTEGER iPos [ ] [ ] // Initialization [ ] STRING sIndentation = " " [ ] STRING sIndentation1 = "[+] " // Level1 [ ] STRING sIndentation2 = " [ ] " // Level2 [ ] [ ] STRING sSeperator = """,""" [ ] STRING sErrSeperator = ",""" //",""***" [ ] STRING sDataSeperator = """,0,""" [ ] STRING sErrSeperator1 = """" [ ] Boolean bResult = FALSE [ ] lsPlanInfo = {} [ ] [ ] sErrCount1 = GetField (sRexLine,sSeperator,4) [ ] sErrCount = GetField (sRexLine,sDataSeperator, 2) [ ] //if ((Trim(sErrCount) != "") && (Val(sErrCount) > 0)) [+] if ((Trim(sErrCount) == "") && (Trim(sErrCount1) != "") ) [ ] Print ("Considering line: {sRexLine}") [ ] bResult = TRUE [ ] sScript = GetField (sRexLine,sSeperator,2) [ ] sTestCase = GetField (sRexLine,sSeperator,3) [ ] sTestTime = GetField (sRexLine,sSeperator,6) [ ] Print ("Elapsed: {sTestTime}") [+] if (sTestTime == "") [+] sFormattedData = "" [ ] iPos = StrPos (sErrSeperator, sTestCase,TRUE) [+] if (iPos > 0) [ ] Print ("sTestCase:{sTestCase}: iPos:{iPos}") [ ] sTestCase = SubStr (sTestCase, 1,iPos - 4) [ ] Print ("Before formatting, sTestCase:{sTestCase}") [ ] //sTestCase = StrTran (sTestCase,"\","") [ ] Print ("After formatting, sTestCase:{sTestCase}") [ ] [+] else [ ] sTestData = GetField (sRexLine,sSeperator,4) [+] if (MatchStr ("*,?,""*",sTestData)) [ ] iPos = StrPos (sErrSeperator, sTestData,TRUE) [+] if (iPos > 0) [ ] Print ("TestData:{sTestData}: iPos:{iPos}") [ ] sTestData = SubStr (sTestData, 1,iPos - 4) [ ] Print ("Before formatting, TestData:{sTestData}") [ ] sFormattedData = StrTran (sTestData,"\","") [ ] Print ("After formatting, TestData:{sTestData}") [ ] [ ] Print ("TestCase: {sTestCase}") [ ] Print ("TestData: {sFormattedData}") [ ] [+] if ( (glsFailedScripts == {}) || (glsFailedScripts[ListCount(glsFailedScripts)] != sScript) ) [ ] ListAppend (glsFailedScripts,sScript) [ ] ListAppend (lsPlanInfo,"{sIndentation1}#script: {sScript}") [+] // if (Trim (sTestData) != "") [ ] // ListAppend (lsPlanInfo,"{sIndentation2}#testdata: {sFormattedData}") [ ] ListAppend (lsPlanInfo,"{sIndentation2}#testcase: {sTestCase}({sFormattedData})") [ ] [+] else [ ] Print ("Not Considering line: {sRexLine}") [ ] [ ] return bResult [+] public void TestPlanWrite(STRING sPlanFile, ANYTYPE aMsg) [ ] // To write content into log file [ ] HFILE hFile [ ] STRING sItem [ ] [ ] hFile = FileOpen (sPlanFile, FM_APPEND) [+] switch TypeOf (aMsg) [+] case STRING [ ] FileWriteLine(hFile,"{aMsg}") [+] case LIST OF STRING [+] for each sItem in aMsg [ ] FileWriteLine(hFile,"{sItem}") [+] default [ ] Print ("Non supported element for TestPlanWrite: {TypeOf (aMsg)}") [ ] FileWriteLine(hFile,"{aMsg}") [ ] [ ] FileClose (hFile) [ ] [ ] [+] VOID ProcessSingleREXFile (String sRexFile, STRING sPlanFile) [ ] // To create a testplan [ ] // Implemented for Auto Scripts [ ] // It will read the text file [ ] [+] // Parsing REX file and then writing into plan file [ ] HFILE hInFile [ ] STRING sLine [ ] LIST OF STRING lsPlan [ ] [ ] hInFile = FileOpen (sRexFile,FM_READ) [ ] [+] while (FileReadLine (hInFile, sLine)) [+] if (GetFailedTestInfo (sLine,lsPlan)) [ ] TestPlanWrite (sPlanFile,lsPlan) [ ] [ ] FileClose (hInFile)