Hi, this is my technical blog to share my programming experience,tools which I have developed, new findings and innovative stuff related to QA Automation Tools, Agile Process, Bug Reporting / Defect Tracking Tools, Test Case Management, Excel Macros etc.
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
- The Selenium Server is needed in order to run either Selenium RC style scripts or Remote Selenium Webdriver ones
- You can download the Selenium RC server from following location. http://selenium.googlecode.com/files/selenium-server-standalone-2.25.0.jar
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
- This can be simply done by using the jxl library which is available in the internet. [ http://sourceforge.net/projects/jxl/ ]
- You may refer how to read and write from excel file using jxl from following article http://www.andykhan.com/jexcelapi/tutorial.html
- Following is a sample Selenium script which uses jxl for reading values http://itsmyselenium.blogspot.com/2012/04/simple-datadriven-example.html
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.
- http://www.javacodegeeks.com/2011/10/testing-gwt-apps-with-selenium-or.html
- http://drglennn.blogspot.com/2010/01/selenium-testing-gwt-upgrading-to-gwt.html
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.
Following links provide some useful information related to xpath and how we can use in Selenium.
- http://www.w3schools.com/xpath/xpath_syntax.asp
- http://www.theautomatedtester.co.uk/tutorials/selenium/selenium_xpath.htm
- https://addons.mozilla.org/en-US/firefox/addon/firepath/ ( If you have firebug installed please use the plugin fire path to generate the xpath of any element you want )
- If you need to give more prefrence to resolve elements using xpath please change the order or resolving elements via selenium IDE. Load Selenium IDE > options > go to Build Locators, change the order as you wish by drag and drop
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.
- http://codeformatter.blogspot.com/
- http://timbroder.com/2007/07/howto-post-code.html
- http://pleasemakeanote.blogspot.com/2008/06/posting-source-code-in-blogger.html
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
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
Subscribe to:
Posts (Atom)