Tuesday, October 9, 2012

How to Compare Two Data Sets using Excel



I think it would be very useful to know how we can compare two data sets easily using Ms Excel by using a simple Excel Macro. This can be modified as you wish based on your requirement.
I usually use this simple macro to compare large data sets with in few seconds.

This sample macro is extracted from Microsoft Support web site

Method


  • Start Excel.
  • Press ALT+F11 to start the Visual Basic editor.
  • On the Insert menu, click Module.
  • Enter the following code in a module sheet:
Sub Find_Matches()
    Dim CompareRange As Variant, x As Variant, y As Variant
    ' Set CompareRange equal to the range to which you will
    ' compare the selection.
    Set CompareRange = Range("C1:C5")
    ' NOTE: If the compare range is located on another workbook
    ' or worksheet, use the following syntax.
    ' Set CompareRange = Workbooks("Book2"). _
    '   Worksheets("Sheet2").Range("C1:C5")
    '
    ' Loop through each cell in the selection and compare it to
    ' each cell in CompareRange.
    For Each x In Selection
        For Each y In CompareRange
            If x = y Then x.Offset(0, 1) = x
        Next y
    Next x
End Sub
     




  • Press ALT+F11 to return to Excel.
  • Enter the following data (leave column B empty):
A1: 1   B1:     C1: 3
A2: 2   B2:     C2: 5
A3: 3   B3:     C3: 8
A4: 4   B4:     C4: 2
A5: 5   B5:     C5: 0



  • Select the range A1:A5.
  • In Excel 2003 and in earlier versions of Excel, point to Macro on the Tools menu, and then click Macros.
  • In Excel 2007, click the Developer tab, and then click Macro in the Code group.
  • Click Find_Matches, and then click Run.
  • The duplicate numbers are displayed in column B. The matching numbers will be put next to the first column, as illustrated here:



   A1: 1   B1:     C1: 3
   A2: 2   B2: 2   C2: 5
   A3: 3   B3: 3   C3: 8
   A4: 4   B4:     C4: 2
   A5: 5   B5: 5   C5: 0
    



Tuesday, September 25, 2012

How to handle c/c++ memory leaks and access violation issues


Currently I'm working on my M.Sc  Research and I'm implementing my research tools using C++ ( together with  Qt, OpenCV, Boost and Intel TBB libraries). One of the biggest challenges is to overcome the run time exceptions coming due to memory leaks and access violation issues due to threads and poor memory management. Hence I though of posting my personal experience as this would be very helpful to the c/c++ programmers.


Following are the well-known tools that you can use to investigate memory leaks, uninitialized variables, and other run time issues.


and may more you can find via this link


If you are using windows and using Visual Studio then my recommendation is go for VLD ( Visual Leak Detector )

http://vld.codeplex.com/wikipage?title=Using%20Visual%20Leak%20Detector&referringTitle=Documentation

Monday, September 10, 2012

How to setup the slow mode in Selenium RC using Java


How to setup the slow mode in Selenium RC using Java ?

I came across this issue several times when automating test scripts using Selenium RC & Java. In many instances you need to use the slow mode (especially when dealing with the dynamic components) in-order to run your script smoothly.

Following method can be used to set the selenium slow mode by pausing each and every step by limiting in to a specific time period (in milliseconds)


 //define a public string with the time limit you need to pause every step in milliseconds  
 public String timeout="6000";  
 //Add the initial steps to start selenium  
  RemoteControlConfiguration rc = new RemoteControlConfiguration();  
  seleniumserver = new SeleniumServer(rc);  
  selenium = new DefaultSelenium("localhost", 4444, browser, "http://");  
  seleniumserver.start();  
  selenium.start();  
 //Once the server is started then set the default timeout period ( in-order to emulate the slow mode )  
 selenium.setSpeed(timeout);  

Wednesday, August 8, 2012

How to Import Data from Web to an Excel Sheet


In order to import data from web and maintain an excel sheet you can simply use the feature of "Web Query" in the Data Tab in MS Excel.

Steps
1. Create a New Excel File
2. Go to Data > Web Query
3. Enter the URL of the Web Site you need to import data from
4. Then it will indicate the possible fields that you can extract data from using Yellow Arrows
5. Select the fields you want
6. Click on Import
7. Select the Sheet or cell range you need to populate the data
8. Ok

When ever you need to update your data, click on Refresh All which will Sync with the Web Site.

Reference: http://www.mrexcel.com/tip103.shtml



Friday, August 3, 2012

How To Automate Testing using Selenium


What is Selenium ?


"Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including C#, Java, Groovy, Perl, PHP, Python and Ruby. The tests can then be run against most modern web browsers. Selenium deploys on Windows, Linux, and Macintosh platforms"  [ Reference: http://en.wikipedia.org/wiki/Selenium_(software) ]

Further you may refer the main web site of Selenium for more details.  [ http://seleniumhq.org/ ]


Selenium IDE



  • As a starting point, it would be nice to first setup Selenium IDE in your Firefox browser ( you can find the xpi from following url :  http://release.seleniumhq.org/selenium-ide/1.9.0/selenium-ide-1.9.0.xpi )
  • Using Selenium IDE you can simply records the steps that you do in the web site and then you can play back them easily. 
  • You may refer this article as a starting guide:  http://seleniumhq.org/docs/02_selenium_ide.html
  • Further you can add assertions to your scripts and verify the values and enhance you scripts.
  • But still if you wish to automate complex work flows in web sites using values from files, xml etc, it is recommended to move to Selenium RC using Java or any language you prefer to write test cases. But still Selenium IDE can used to record the basic flow and then Export to Java (or any supporting language) and then modify them and add more functionality using Java (or the supporting language)

Selenium RC

How to Start Test Automation using Java & Selenium RC

  • Make sure you have downloaded the Selenium Server jar file from above link
  • Record the script using Selenium IDE and export it to Java ( JUNIT )
  • Add the java file to your project
  • Add the Selenium Server jar file to your project as well 
  • Start the selenium server using the command line 
    • Go to the path of the jar file and type  java -jar <selenium server jar name>
  • Run the test case from your Java IDE (eg: inteliJ Idea, Eclipse )
  • You may refer this article for more details http://seleniumhq.org/docs/05_selenium_rc.html
In order to automate a data driven test case using files you may use different techniques to read files from java and then set the values to the relevant places. 

Example: How to read values from Excel files and use in Selenium Test Cases

Selenium Tips
Please refer following links for more tips 







Tuesday, July 31, 2012

Selenium Test Automation for GWT Websites


Hi,

GWT is one of the latest technologies used to develop nice web sites and applications. When it comes to test automation for GWT based web sites / systems we need to know what we can do and what we cannot do. Therefore I thought of sharing this post with what I could found recently and I will keep updating this post with my latest findings. Visitors are welcome to share their experience related to Selenium with GWT under this post.


Following are couple of good articles I came across and looks interesting.

When dealing with different types of elements we may need to use xpath to access some elements in GWT. In that case it is good to have an idea about xpaths and how we can find the xpath and how we can use them  with Selenium.

Following links provide some useful information related to xpath and how we can use in Selenium.



Further I came across following plugins which would be very useful when recording scripts via Selenium IDE

Selenium useful Plugins:
  • Selenium Expert
  • Highlight Elements
  • Implicit Wait

Wednesday, July 25, 2012

How to Generate an Index of Excel Sheets Dynamically



This post is about "How to Generate an Index of Excel Sheets Dynamically" which is very helpful when you are dealing with Large excel files with lots of sheets/tabs.

Step 1. Create a New Sheet called "Index"
Step 2. Right click on the sheet and go to View Code ( It will open VB Editor )
Step 3. Copy the following VB Script there


 Private Sub Worksheet_Activate()
 Dim wSheet As Worksheet
 Dim l As Long
 l = 1
   With Me
     .Columns(1).ClearContents
     .Cells(1, 1) = "INDEX"
     .Cells(1, 1).Name = "Index"
   End With
   For Each wSheet In Worksheets
     If wSheet.Name <> Me.Name Then
       l = l + 1
         With wSheet
           .Range("A1").Name = "Start_" & wSheet.Index
           .Hyperlinks.Add Anchor:=.Range("C1"), Address:="", _
           SubAddress:="Index", TextToDisplay:="Back to Index"
         End With
         Me.Hyperlinks.Add Anchor:=Me.Cells(l, 1), Address:="", _
         SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name
     End If
   Next wSheet
 End Sub


Step 4. Now save and close the VB Editor
Step 5. Go to a different sheet and come back to Index Sheet
Step 6. Now you can see that the Index has been generated along with the list of sheets with links
Step 7. when you go to a sheet you can see another link to go back to index sheet as well.

Thursday, July 19, 2012

How to Format Code Blocks in your Blog



I thought it would be interesting to know how we can publish code blocks with proper formatting which is convenient for the reader to read or copy.

I found couple of interesting articles which can be used to do this task. I thought of sharing this links rather than explaining the same thing by my self.







Wednesday, July 18, 2012

Test Automation - integrating to Jenkins

Test Automation - integrating to Jenkins/Hudson


Currently test driven development is the latest trend in the software industry due to the Agile Process. Hence it is really important to utilize test automation tools in the QA process to automate possible test cases. This allows to save time and utilize the resources very well. In this post I would like to discus about how we can integrate test automation scripts to Jenkins (Continuous Integration Tool / Build Tool) and generate test results.

There are lot of approaches to do this task and it depends on the tools that is used by your company for test Automation.

Here are few suggestions I can given and you may further refer following links to integrate you test scripts to Jenkins/Hudson

Marathon vs Jenkins

  • If your using Marathon as the test automation tool then you can create a simple build.xml with the test scripts. Test Scripts can be groups in to several ant targets. 
  • You can create a Jenkins job and setup the build.xml and invoke the relevant ant target.
  • Further you need to mention the marathon home path in the build xml and the project paths of the test automation projects.
  • Further you can setup "Publish JUnit test result report" with the JUnit report generation path of your test automation project
  • Then you may execute these Jenkins jobs as you wish
  • This will execute your test scripts using Marathon, and generate JUnit test reports and it will display under test results of the Jenkins Job.
TestLink vs Jenkins

Further you can integrate Testlink with Jenkins and you may refer following article for more details.


Wednesday, April 18, 2012

How to import test cases to TestLink


Hi,

I think those who are using TestLink to write test cases, it is a pain that it has lot of mouse clicks & navigations involved when writing test cases.

To resolve that I used to follow a simple technique of writing all my test cases in excel and then import them to TestLink at once.

TestLink allows you to import test cases as XML, hence we need to convert our test cases written in excel to XML, using a simple macro.




Then simply copy paste the following macro in to your excel file.





 Sub genReqnTcArr()  
 Dim lRow, lCol As Long  
 Dim duplicate As Boolean  
 Dim oneCell, onesMerged, tsRange, tcRange, reqRange As Range  
 Dim tsColCount, tcColCount, reqColCount, tcCFCount, arrRow, temp As Integer  
 Dim arrReq(), arrTS(), arrTc(), arrReqTc(), arrTcCF() As Variant  
 Dim strTemp, xmlStr, xlsFileName, xmlTcFileName, xmlReqFileName As String  
 'Initializing Counts  
 tsColCount = 0  
 tcColCount = 0  
 reqColCount = 0  
 tcCFCount = 0  
 'Obtaining File Names  
 'Get the name of the excel file in which the requirements and testcases have been stored  
 'and store it as the XML Requirments File name and XML Test Case File Name  
 xlsFileName = ActiveWorkbook.FullName  
 xmlStr = Left(xlsFileName, InStr(xlsFileName, "."))  
 xmlReqFileName = Left(xlsFileName, Len(xlsFileName) - 4) & "_Req.xml"  
 xmlTcFileName = Left(xlsFileName, Len(xlsFileName) - 4) & "_Tc.xml"  
 'Get the last row and last column in the list  
 lRow = lastRow()  
 arrRow = lRow - 2  
 lCol = lastColumn()  
 'Count the columns for test suite, test cases and requirements and identify if any custom fields are present  
 'Custom fields import for other than test cases is NOT supported in TestLink  
 With Sheets(1)  
   For Each oneCell In Range(Cells(1, 1), Cells(1, lCol))  
     If oneCell.MergeCells Then  
       If oneCell.Text = "Test Suite" Then  
        Set tsRange = oneCell.MergeArea  
        tsColCount = oneCell.MergeArea.Count  
       ElseIf oneCell.Text = "Test Case" Then  
        Set tcRange = oneCell.MergeArea  
        tcColCount = oneCell.MergeArea.Count  
       ElseIf oneCell.Text = "Requirements" Then  
        Set reqRange = oneCell.MergeArea  
        reqColCount = oneCell.MergeArea.Count  
       End If  
     Else  
      If oneCell.Text = "Test Suite" Then  
        tsColCount = 1  
       ElseIf oneCell.Text = "Test Case" Then  
        tcColCount = 1  
       ElseIf oneCell.Text = "Requirements" Then  
        reqColCount = 1  
       End If  
     End If  
   Next oneCell  
 End With  
 'Define array sizes to store the contents  
 If reqColCount <> 0 Then  
  ReDim Preserve arrReq(0 To arrRow, 1 To reqColCount) As Variant  
 End If  
 If tsColCount <> 0 And tcColCount <> 0 Then  
  ReDim Preserve arrTS(0 To arrRow, 1 To tsColCount) As Variant  
 End If  
 If tcColCount <> 0 Then  
  ReDim Preserve arrTc(0 To arrRow, 1 To tcColCount) As Variant  
 End If  
 If tcColCount <> 0 And reqColCount <> 0 Then  
  ReDim Preserve arrReqTc(0 To arrRow, 1 To reqColCount) As Variant  
 End If  
 'Collect the Requirements associated with Test Cases in an Array  
 If reqColCount <> 0 And tcColCount <> 0 Then  
  With Sheets(1)  
   For Each oneCell In reqRange  
    Select Case oneCell.Offset(1, 0).Text  
    Case "Spec Title"  
     arrReqTc(0, 1) = "Spec Title"  
     For iRow = 2 To lRow - 1  
      arrReqTc(iRow - 1, 1) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case "Document ID"  
     arrReqTc(0, 2) = "Document ID"  
     For iRow = 2 To lRow - 1  
      arrReqTc(iRow - 1, 2) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case "Req Title"  
     arrReqTc(0, 3) = "Req Title"  
     For iRow = 2 To lRow - 1  
      arrReqTc(iRow - 1, 3) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case "Description"  
     arrReqTc(0, 4) = "Description"  
     For iRow = 2 To lRow - 1  
      arrReqTc(iRow - 1, 4) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    End Select  
   Next oneCell  
  End With  
 End If  
 'Collect the Test Suite in an Array  
 If tsColCount <> 0 Then  
  With Sheets(1)  
   For Each oneCell In tsRange  
    Select Case oneCell.Offset(1, 0).Text  
    Case "Name"  
     arrTS(0, 1) = "Name"  
     For iRow = 2 To lRow - 1  
      arrTS(iRow - 1, 1) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case "Details"  
     arrTS(0, 2) = "Details"  
     For iRow = 2 To lRow - 1  
      arrTS(iRow - 1, 2) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    End Select  
   Next oneCell  
  End With  
 End If  
 'Collect the Test Cases in an Array  
 If tcColCount <> 0 Then  
  With Sheets(1)  
   For Each oneCell In tcRange  
    Select Case oneCell.Offset(1, 0).Text  
    Case "TC#"  
     arrTc(0, 2) = "TC#"  
     For iRow = 2 To lRow - 1  
      arrTc(iRow - 1, 2) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case "Name"  
     arrTc(0, 1) = "Name"  
     For iRow = 2 To lRow - 1  
      arrTc(iRow - 1, 1) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case "Summary"  
     arrTc(0, 3) = "Summary"  
     For iRow = 2 To lRow - 1  
      arrTc(iRow - 1, 3) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case "Steps"  
     arrTc(0, 4) = "Steps"  
     For iRow = 2 To lRow - 1  
      arrTc(iRow - 1, 4) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case "Expected Results"  
     arrTc(0, 5) = "Expected Results"  
     For iRow = 2 To lRow - 1  
      arrTc(iRow - 1, 5) = oneCell.Offset(iRow, 0).Text  
     Next iRow  
    Case Else  
     'Count the number of custom fields to import  
     tcCFCount = tcCFCount + 1  
    End Select  
   Next oneCell  
  End With  
  ReDim Preserve arrTc(0 To arrRow, 1 To tcColCount - tcCFCount) As Variant  
  'Collect the Custom fields for Test Cases in an Array  
  If tcCFCount <> 0 Then  
   temp = arrRow * tcCFCount  
   ReDim Preserve arrTcCF(0 To temp, 1 To 3) As Variant  
   arrTcCF(0, 1) = "TC#"  
   arrTcCF(0, 2) = "Name"  
   arrTcCF(0, 3) = "Value"  
   temp = 0  
   With Sheets(1)  
    For Each oneCell In tcRange  
     Select Case oneCell.Offset(1, 0).Text  
      Case "TC#"  
       For i = 1 To tcCFCount  
        For iRow = 2 To lRow - 1  
         arrTcCF(iRow - 1 + temp, 1) = oneCell.Offset(iRow, 0).Text  
        Next iRow  
        temp = temp + lRow - 2  
       Next i  
       temp = 0  
      Case "Name"  
       'Do Nothing  
      Case "Summary"  
       'Do Nothing  
      Case "Steps"  
       'Do Nothing  
      Case "Expected Results"  
       'Do Nothing  
      Case Else  
       For iRow = 2 To lRow - 1  
        arrTcCF(iRow - 1 + temp, 2) = oneCell.Offset(1, 0).Text  
        arrTcCF(iRow - 1 + temp, 3) = oneCell.Offset(iRow, 0).Text  
       Next iRow  
       temp = temp + lRow - 2  
      End Select  
    Next oneCell  
   End With  
  End If  
 End If  
 'Remove the duplicate listings of requirements and store the unique listings in an array  
 If reqColCount <> 0 Then  
  If tcColCount <> 0 Then  
   temp = 0  
   For iRow = 0 To arrRow  
    duplicate = False  
    For jRow = 0 To iRow  
     If arrReqTc(iRow, 2) = arrReq(jRow, 2) Then  
      duplicate = True  
      Exit For  
     End If  
    Next jRow  
    If duplicate = False Then  
     arrReq(temp, 1) = arrReqTc(iRow, 1)  
     arrReq(temp, 2) = arrReqTc(iRow, 2)  
     If reqColCount > 2 Then  
      arrReq(temp, 3) = arrReqTc(iRow, 3)  
     End If  
     If reqColCount > 3 Then  
      arrReq(temp, 4) = arrReqTc(iRow, 4)  
     End If  
     temp = temp + 1  
    End If  
   Next iRow  
  Else  
   With Sheets(1)  
    For Each oneCell In reqRange  
     Select Case oneCell.Offset(1, 0).Text  
     Case "Spec Title"  
      arrReq(0, 1) = "Spec Title"  
      For iRow = 2 To lRow - 1  
       arrReq(iRow - 1, 1) = oneCell.Offset(iRow, 0).Text  
      Next iRow  
     Case "Document ID"  
      arrReq(0, 2) = "Document ID"  
      For iRow = 2 To lRow - 1  
       arrReq(iRow - 1, 2) = oneCell.Offset(iRow, 0).Text  
      Next iRow  
     Case "Req Title"  
      arrReq(0, 3) = "Req Title"  
      For iRow = 2 To lRow - 1  
       arrReq(iRow - 1, 3) = oneCell.Offset(iRow, 0).Text  
      Next iRow  
     Case "Description"  
      arrReq(0, 4) = "Description"  
      For iRow = 2 To lRow - 1  
       arrReq(iRow - 1, 4) = oneCell.Offset(iRow, 0).Text  
      Next iRow  
     End Select  
    Next oneCell  
  End With  
  End If  
 End If  
 'Create the Requirements XML file  
 If reqColCount <> 0 Then  
  Open xmlReqFileName For Output As #1  
  Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"  
  Print #1, "<requirements>"  
  For iRow = 1 To arrRow  
   temp = 0  
   For iCol = 1 To reqColCount  
    If arrReq(iRow, iCol) <> "" Then  
     Select Case arrReq(0, iCol)  
      Case "Spec Title"  
       'Do Nothing  
      Case "Document ID"  
       temp = 1  
       Print #1, "  <requirement>"  
       xmlStr = "    <docid><![CDATA[" & arrReq(iRow, iCol) & "]]></docid>"  
       Print #1, xmlStr  
      Case "Req Title"  
       xmlStr = "    <title><![CDATA[" & arrReq(iRow, iCol) & "]]></title>"  
       Print #1, xmlStr  
      Case "Description"  
       xmlStr = "    <description><![CDATA[" & arrReq(iRow, iCol) & "]]></description>"  
       Print #1, xmlStr  
      Case Else  
       'Do Nothing  
      End Select  
     End If  
   Next iCol  
   If temp <> 0 Then  
    Print #1, "  </requirement>"  
   End If  
  Next iRow  
  Print #1, "</requirements>"  
  Close #1  
 End If  
 'Create the Test Cases XML file  
 If tcColCount <> 0 Then  
  Open xmlTcFileName For Output As #2  
  Print #2, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"  
  If tsColCount <> 0 Then  
   Print #2, "<testsuite name=" & Chr(34) & Chr(34) & ">"  
   Print #2, "  <details><![CDATA[]]></details>"  
  Else  
   Print #2, "<testcases>"  
  End If  
  strTemp = ""  
  For iRow = 1 To arrRow  
   temp = 0  
   If tsColCount <> 0 Then  
    If arrTS(iRow, 1) <> "" Then  
     xmlStr = "  <testsuite name=" & Chr(34) & arrTS(iRow, 1) & Chr(34) & ">"  
     Print #2, xmlStr  
     xmlStr = "    <details><![CDATA[" & arrTS(iRow, 2) & "]]></details>"  
     Print #2, xmlStr  
     strTemp = "  "  
    End If  
   End If  
   For iCol = 1 To tcColCount - tcCFCount  
    If arrTc(iRow, iCol) <> "" Then  
     Select Case arrTc(0, iCol)  
      Case "Name"  
       xmlStr = strTemp & "  <testcase name=" & Chr(34) & arrTc(iRow, iCol) & Chr(34) & ">"  
       Print #2, xmlStr  
      Case "TC#"  
       xmlStr = strTemp & "    <node_order><![CDATA[" & arrTc(iRow, iCol) & "]]></node_order>"  
       Print #2, xmlStr  
      Case "Summary"  
       xmlStr = strTemp & "    <summary><![CDATA[" & arrTc(iRow, iCol) & "]]></summary>"  
       Print #2, xmlStr  
      Case "Steps"  
       xmlStr = strTemp & "    <steps><step><step_number><![CDATA[1]]></step_number><actions><![CDATA[" & arrTc(iRow, iCol) & "]]></actions>"  
       Print #2, xmlStr  
      Case "Expected Results"  
       xmlStr = strTemp & "    <expectedresults><![CDATA[" & arrTc(iRow, iCol) & "]]></expectedresults></step></steps>"  
       Print #2, xmlStr  
      End Select  
     End If  
   Next iCol  
   'Get the custom fields if any  
   temp = 0  
   If tcCFCount <> 0 Then  
    For i = 1 To arrRow * tcCFCount  
     If arrTc(iRow, 2) = arrTcCF(i, 1) Then  
      If arrTcCF(i, 2) <> "" And arrTcCF(i, 3) <> "" Then  
       If temp = 0 Then  
        xmlStr = strTemp & "    <custom_fields>"  
        Print #2, xmlStr  
        temp = 1  
       End If  
       xmlStr = strTemp & "      <custom_field>"  
       Print #2, xmlStr  
       xmlStr = strTemp & "        <name>" & arrTcCF(i, 2) & "</name>"  
       Print #2, xmlStr  
       xmlStr = strTemp & "        <value>" & arrTcCF(i, 3) & "</value>"  
       Print #2, xmlStr  
       xmlStr = strTemp & "      </custom_field>"  
       Print #2, xmlStr  
      End If  
     End If  
    Next i  
    If temp = 1 Then  
     xmlStr = strTemp & "    </custom_fields>"  
     Print #2, xmlStr  
     temp = 0  
    End If  
   End If  
   'Get the requirements associated with test cases  
   If reqColCount <> 0 Then  
    For i = 1 To arrRow  
     If arrTc(iRow, 2) = Trim(Str(i)) Then  
      If arrReqTc(i, 1) <> "" And arrReqTc(i, 2) <> "" Then  
       xmlStr = strTemp & "    <requirements>"  
       Print #2, xmlStr  
       xmlStr = strTemp & "      <requirement>"  
       Print #2, xmlStr  
       xmlStr = strTemp & "        <req_spec_title>" & arrReqTc(i, 1) & "</req_spec_title>"  
       Print #2, xmlStr  
       xmlStr = strTemp & "        <doc_id>" & arrReqTc(i, 2) & "</doc_id>"  
       Print #2, xmlStr  
       xmlStr = strTemp & "      </requirement>"  
       Print #2, xmlStr  
       xmlStr = strTemp & "    </requirements>"  
       Print #2, xmlStr  
      End If  
     End If  
    Next i  
   End If  
   xmlStr = strTemp & "  </testcase>"  
   Print #2, xmlStr  
   If tsColCount <> 0 Then  
    If iRow < arrRow Then  
     If arrTS(iRow + 1, 1) <> "" Then  
       Print #2, "  </testsuite>"  
     End If  
    Else  
     Print #2, "  </testsuite>"  
    End If  
   End If  
  Next iRow  
  If tsColCount <> 0 Then  
   Print #2, "</testsuite>"  
  Else  
   Print #2, "</testcases>"  
  End If  
  Close #2  
 End If  
 End Sub  
 Function lastRow() As Long  
  If WorksheetFunction.CountA(Cells) > 0 Then  
   'Search for any entry, by searching backwards by Rows.  
   lastRow = Cells.Find(What:="*", After:=[A1], _  
              SearchOrder:=xlByRows, _  
              SearchDirection:=xlPrevious).Row  
  End If  
 End Function  
 Function lastColumn() As Long  
  If WorksheetFunction.CountA(Cells) > 0 Then  
   'Search for any entry, by searching backwards by Columns.  
   lastColumn = Cells.Find(What:="*", After:=[A1], _  
               SearchOrder:=xlByColumns, _  
               SearchDirection:=xlPrevious).Column  
  End If  
 End Function  




Then run the macro to Generate the XML


Now you can go to TestLink --> Test Specification , select the root, and then click on Import , select the xml file and then upload.




Then check whether all your test cases imported successfully.


References:
http://testlink-import.blogspot.com/2009/11/test-link-import.html
http://testlink.sourceforge.net/docs/docs/print.php?page=all