Saturday, March 25, 2017

Tools learning for testing

Many times folks used to ask, what tools would be good for testing career. Used to advice to learn popular tools (mostly commercial tools) based on their coding skills and interest. But this scenario is changed in last few years. Testers should be ready to handle the automation based on business needs, rather than just toolsmiths. Also mindset change should be there, instead of sticking with just one tool and one scripting language

Read an article recently in this line and few excerpts..

It’s important to ask yourself, why do you want to learn about a specific tool or set of tools? They are an integral part of software testing, supporting what we do on a daily basis. However, having knowledge of a set of tools is less important than knowing when and where to use the right tool. An effective tester will also have the skill to know when and where to use the right tool because the problem requires it, not because the job market determines it desirable. Using the wrong tool at the wrong time can have adverse effects on your day-to-day work, potentially slowing you down, or worse, giving you biased or flat out false information. That’s not to say you shouldn’t explore new tools, but always remember:

Problem first, tools second
With this concept in mind, let’s explore different categories of tools. Some examples will be offered but they are by no means an exhaustive list. I encourage you to build up a toolbox or reference list of tools you have used in the past.

Original Article - What Tools Should I Learn?

Sunday, March 19, 2017

Handling multi-dimensional array in vbscript

Was trying to build excel data provider, which can be used for Test Complete and QTP scripts. Created a VBScript to keep all excel contents into a multi-dimensional array.

Declared array with lower limits and then used ReDim to fix with right count. But I was able to retrieve the data only upto the initial array size.

Tried different ways. Then declared array without any size as given in below code.

'------------------------------------------------------------------------- ' File : ExcelReadByArrays.vbs ' Author : PalaniSelvam Thillaiappan ' Purpose : To read the given sheet contents . '------------------------------------------------------------------------- '' Usage '' cscript D:\MyCode\qtp_uft\ExcelReadByArrays.vbs '' test data: D:\MyCode\qtp_uft\testMyApp_1.xlsx '******** Variables Declaration Dim gsExcelFile, giStartRow, giStartCol, giEndRow, giEndCol, giSheetIndex Dim gsLogFile Dim arrExcelData() 'as all Rows data '''Dim arrExcelData(5, 5) 'as all Rows data giSheetIndex = 1 gsExcelFile = "D:\MyCode\qtp_uft\testMyApp_1.xlsx" '' Working fine, but array size should be given properly ExcelDataRead gsExcelFile, giSheetIndex, arrExcelData PrintArrays arrExcelData '-------------------------------------- ' Method : ExcelDataRead ' Author : PalaniSelvam Thillaiappan ' 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 '-------------------------------------- Sub ExcelDataRead(sExcelFile, iSheetIndex, ByRef arrExcel) 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 Dim arrColList 'As Array - Column Name If (sExcelFile = "") Then sExcelPath = "D:\MyCode\qtp_uft\testMyApp_1.xlsx" Else sExcelPath = sExcelFile End If If (iSheetIndex = "") Then iSheetIndex = 2 End If Set objExcel = CreateObject("Excel.Application") objExcel.Workbooks.Open sExcelPath, False, True On Error Resume Next WorkSheetCount = objExcel.Worksheets.Count Set objXLWorkbook = objExcel.ActiveWorkbook 'objXLWorkbook.RunAutoMacros 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 CurrentWorkSheet.UsedRange.Columns.AutoFit() ' Cells object CurrentWorkSheet.Cells.Activate ReDim Preserve arrExcel(iUsedRowsCount, iUsedColsCount) ''ReDim arrColList(iUsedColsCount) For iRow = iTop To iUsedRowsCount '(iUsedRowsCount - 1) 'Read All Columns For iCol = iLeft To iUsedColsCount '(iUsedColsCount - 1) sResult = "" Set objCurrentCell = CurrentWorkSheet.Cells(iRow, iCol) sCellText = objCurrentCell.Text sResult = "Reading Cell {" & CStr(iRow) & ", " & CStr(iCol) & "}^" & sCellText & "^" WScript.echo sResult Set objCurrentCell = Nothing arrExcel (iRow-1, iCol-1) = sCellText Next Next ' 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 '' To display given array Sub PrintArrays( arrList) '' To Print all list items Dim aValue 'array item ==> dictionary Dim aItem 'dictionaly item ==> key-pair value Dim iRow Dim iCol WScript.echo "Array Rows Count: ",UBound (arrList, 1) '' First Array WScript.echo "Array Columns Count: ",UBound (arrList, 2) ''Second Array For iRow =LBound(arrList) to UBound (arrList)-1 For iCol=LBound(arrList,2) to UBound (arrList,2)-1 aValue = arrList(iRow, iCol) WScript.echo iRow, iCol, " Value:", aValue Next Next End Sub

Sunday, July 10, 2016

Comparison of C# and Java for testers

was talking with few test professionals for C# automation. Team is reluctant to change from Java background to C# technologies. I have used many scripting and programming languages. There is not much variation between Java & C# at core langulage level.

Differences and similarities

Program Entry Pointmain(String ...args) Main() or Main(string [] args)
Smallest Deployment UnitJarEXE/DLL, Private Assembly, Shared Assembly
SigningJar SigningAssembly Signing
Namespacepackage namespace
Including Classesimportusing
Inheritanceclass (extends), interface (implements)class and interface (:)
Visibilityprivate, package,protected, publicprivate, protected, internal,internal protected, public
Abstract Classabstract class X { ... }abstract class X { ... }
Non-Extensible Classfinal class X { ... }sealed class X { ... }
Non-Writable Fieldfinalreadonly
Non-Extensible Methodfinalsealed
Constantstatic finalconst
Checking Instance Typeinstanceofis
Enumsenum, can have fields, methods and implement interfaces and are typesafeenum, cannot have methods,fields or implement interfaces, not typesafe
for-each constructfor (item : collection)
{ ... }
foreach(item in collection)
{ ... }
Switch-Casenumeric types (int,float...) enums, and now strings (in Java 7)numeric types, enums and strings
Method ParametersObject References are passed by Value onlyObject reference are passedby Value(default), ref & out
Variable Argumentsmethod(type... args)Method(params type[] args)
Catching Exceptionstry { ... } catch (Exception ex) {...}try { ... } catch (Exception ex) {...}
Meta TypeClass klass = X.class;Type type = typeof(X);
Meta Information@Annotation[Attribute]
Static classSimulated by private Ctor and static methodsStatic class and ctor with static methods
PropertiesgetProperty(),setProperty()Property { get; set; } compiler generated get_Property() and set_Property() methods

Selenium script on Java & C#
Developed a sample selenium scripting using Java and ported to C#.

Reference Links

Moving to C# for Java Developers
Java Vs C#

Thursday, July 16, 2015

Dynamics AX Performance Testing by using Coded UI tests

Recently we have completed Dynamics AX performance testing by using functional test automation scripts, which were developer by using Visual Studio - Coded UI. Dynamics AX thick client performance testing was time consuming using X++ code approach - Benchmark Toolkit. I'm into Test Automation for many years and had few challenges to implement functional test scripts as performance Testing. Used Microsoft Terminal servers to simulate multiple users RDP sessions. Prepared the list of factors, which are considered as helpful in this methodology.

Best practices for coding
  • Don't open the AX thick client for each iteration. For example, Sales Order creation should be executed for 15 times per user. Open AX thick client only once per user and then create 15 Sales order without re-starting AX client
  • Open AX client from windows path. Don't use shortcuts to open. Also keep the same path should be available in all terminal servers.
  • Methods to log Start Time and End Time for particular transaction
  • Don't use too much descriptive OR heavy programs to find the controls. Keep in mind that Testing tool also will consume CPU and memory
  • Don't keep control identifying calls within the time measuring statements. There is a major difference on purpose of functional script and performance script.
  • You can use UI Map (Object Repository) OR Page object model
  • Try to use short-cut keys. It would simplify your script as well as increase the execution speed
  • Introduce the loop within the test method. Don't call test method multiple times
  • Use data sources to provide different test data for each user. Try to read once and then use, whenever it required
  • Implement time logging only at essential code. Also consider that Automation tool would take few seconds to identify particular screen/UI object
  • Run with few users and validate once the script/ scenario is complete
  • Avoid left click navigation by entering module directily in address bar
  • Use Sleep between transactions, but do not include in transaction timings
  • Refine the steps, wherever possible
  • Follow naming conventions for transaction name, which should be simple and ease of use

Best practices for Performanc Testing related
  • Transaction timings can be logged as XML, TXT, DB records etc. I would prefer to keep in Database. SO that you can save the data multiple times and also use queries to collect different kind of metrics like Average Response time, 90th Percentile response time, Minium Response time, Maximum Response time etc.
  • Create couple of methods to log start and end timings for each transaction
  • Capture the script errors as well as AX exceptions
  • Update the information for
  • Implement test method to be executed for the given time using config file. For example, the scripts have to be executed 60/90/120 minutes
  • Implement user frequency. For exmple, if Sales Order should be created 15 times per user, then script should be stopped after creating 15 Sales order for each user
  • Capture screenshots if test is failed for any user. Keep the images in shared path. Also create less size image.
  • Modify the script, which is creating more transactions than expected
  • Validate each transaction time as whether only applicaiton time OR included Coded UI time as well
  • Keep data files in the shared path for ease of use and maintenance
  • Use Visual Studio Load test to collect performance counters from various servers like AOS servers, AX Batch servers, AX Integration servers, Terminal servers etc

Batch files to execute CodedUI Tests
Always create DLLs in Release mode instead of Debug mode. It will improve system's resource utilization.
echo on set logfile=C:\AX_PerformanceTest\ExecSmallSO.log echo "%date% - %time%- MediumSO started" cd\ cd "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow" vstest.console.exe "C:\AX_PerformanceTest\DLL\AX_PerformanceTest.dll" /Tests:CreateSmallSaleOrder pause

Sample Coded UI methods
Scenarios should be carefully implemented as it is for performance testing.
public void clickSellTab() { axAppWindow.SetFocus(); myutils.ClickButton(axAppWindow, "SellTab"); } public void ClickBookMenu(ref Logger.Logger LogObj) { try { axAppWindow.SetFocus(); WinMenuItem item = new WinMenuItem(axAppWindow); item.SearchProperties[WinMenuItem.PropertyNames.Name] = "Book"; UITestControlCollection ab = item.FindMatchingControls(); LogObj.TransactionStart("BookingOrder"); Mouse.Click(item); Thread.Sleep(1000); this.clickSellTab(); // axAppWindow.WaitForControlEnabled(50000); axAppWindow.SetFocus(); item.WaitForControlReady(50000); LogObj.TransactionEnd("BookingOrder"); } catch (Exception ex) { LogObj.LogException(LogObj.ScenarioName, ex.ToString()); } }

Few links related to Coded UI Tests

Friday, May 22, 2015

Sharepoint Test automation using CSOM

Microsoft has provided Client Side Object Model (CSOM) to interact with Sharepoint objects easily. This CSOM objects can be interacted through Powershell and C#. Many developers are also using this to do CRUD[Create, Read, Update and Delete] operations. Testers can use CSOM to validate site columns, various content types and content data. Also it can be used to create test data for various content types.

I have used this library - SharePoint Test Automation using Client Side Object Model (CSOM) for my sharepoint projects. Used to validate site columns, available sites content types and content fields.

Follow the steps to begin your automation. Also it is API-based automation, no need to worry about UI changes...

Step 1: Download and Install Client Components from SharePoint Test Automation using Client Side Object Model (CSOM)

Step 2: Once installed, Add the following references in the package.
- Microsoft.SharePoint.Client
- Microsoft.SharePoint.Client.Runtime

Step 3: Develop code for Test Initialize like below.
using System; using System.Configuration; using System.Text; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Test.Automation.SharePointCOM.Verification; using Test.Automation.SharePointCOM.Helpers; using System.Net; using Microsoft.GD.Test.Logging; using System.IO; using Microsoft.SharePoint.Client; using AutomationFramework.TestScripts; namespace AutomationFramework.TestScripts { [TestClass] public class SpAppVerify { SPVerification VerifyCO; LogFile TestResults = new LogFile(); private TestContext testContextInstance; public static string sURL = ""; public static string sUsrId = "svc-spfarm"; public static string sUsrPwd = "SpAppdev#123@"; public static string sUsrDomain = "devSpAppnai"; private String sTestLogFile = ConfigurationManager.AppSettings["ResultsLog"]; public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } [TestInitialize] public void Setup() { // The below two lines help to access HTTPS site System.Net.WebClient client = new System.Net.WebClient(); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; VerifyCO = new SPVerification(); testContextInstance.WriteLine("==============Starting the Set Up====================="); Assert.IsTrue(VerifyCO.SetSiteUnderTest(sURL, sUsrId, sUsrPwd, sUsrDomain, testContextInstance)); testContextInstance.WriteLine("==============Ending the Setup====================="); }

Step 4: Site Column validation
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", @"C:\Automation\SpApp_Tests\CoreLibrary\TestData\sitecolumns.csv", "sitecolumns#csv", DataAccessMethod.Sequential), TestMethod] //[TestMethod] public void VerifyCOSiteColumns() { TestStartMessages(testContextInstance); VerifyCO = new SPVerification(); String ColumnName = testContextInstance.DataRow["SitecolumnName"].ToString(); VerifyCO.SetSiteUnderTest(sURL, sUsrId, sUsrPwd, sUsrDomain, testContextInstance); TestResults.LogMessage(testContextInstance.TestName + " SitecolumnName : " + ColumnName); TestResults.LogAssert(VerifyCO.VerifySiteColumns(ColumnName, testContextInstance, "SitecolumnName", "SpApp Site Columns")); }

Step 5: Content Type fields validation
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", @"C:\Automation\SpApp_Tests\CoreLibrary\TestData\ContentTypes\SpApp Web Page ", "SpApp Web Page#csv", DataAccessMethod.Sequential), TestMethod] public void SpApp_Web_Page() { TestStartMessages(testContextInstance); VerifyCO = new SPVerification(); VerifyCO.SetSiteUnderTest(sURL, sUsrId, sUsrPwd, sUsrDomain, testContextInstance); String TypeName = testContextInstance.DataRow["ContentTypeName"].ToString(); String ColumnName = testContextInstance.DataRow["ColumnName"].ToString(); String Field = testContextInstance.DataRow["Type"].ToString(); // Assert.IsTrue(VerifyCO.VerifyContentTypeField(TypeName, ColumnName, Field, testContextInstance)); TestResults.LogMessage(testContextInstance.TestName + " : " + TypeName + " : " + ColumnName + " : " + Field); TestResults.LogAssert(VerifyCO.VerifyContentTypeField(TypeName, ColumnName, Field, testContextInstance)); }

Step 6: Bonus code - To get all fields of content types in the given site.
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", @"C:\Automation\SpApp_Tests\CoreLibrary\TestData\AllContentTypes.csv", "AllContentTypes#csv", DataAccessMethod.Sequential), TestMethod] public void Get_All_ContentTypes() { bool result = false; String sContentInfo; FieldCollection Fields; TestStartMessages(testContextInstance); VerifyCO = new SPVerification(); VerifyCO.SetSiteUnderTest(sURL, sUsrId, sUsrPwd, sUsrDomain, testContextInstance); // SharePointHelper spSharePointHelper = new SharePointHelper(sURL, sUsrId, sUsrPwd, sUsrDomain); String TypeName = testContextInstance.DataRow["ContentTypeName"].ToString(); Fields = VerifyCO.GetAllContentTypes(TypeName); if (Fields != null) { TestContext.WriteLine("Found the Content Type : " + TypeName); TestResults.LogMessage("Found the Content Type : " + TypeName); // FieldCollection Fields = spSharePointHelper.GetFieldsOfContentType(TypeName); foreach (Field fieldItem in Fields) { sContentInfo = "Title: " + fieldItem.Title; sContentInfo += " DisplayName: " + fieldItem.TypeDisplayName; sContentInfo += " Description: " + fieldItem.Description; sContentInfo += " Default Value: " + fieldItem.DefaultValue; sContentInfo += " Required: " + fieldItem.Required.ToString(); //sContentInfo += "DisplayName: " + fieldItem.TypeDisplayName; TestResults.LogMessage(sContentInfo); } } else { TestResults.LogMessage("Not Found Content Type : " + TypeName); TestResults.LogMessage(" "); } }

Links For Sample code

Using the C# CSOM to interact with SharePoint Online

Use C# CSOM ClientContext to download file from SharePoint document library or OneDrive for Business

Saturday, March 7, 2015

CodedUI Useful links

In recent yearts, CodedUI has been improved lot. Using latest version of VS, we can automate windows apps and windows phone apps. Below links are giving more info and how to use Coded UI for different applications.

CodedUI Resources
Verifying Code by Using UI Automation
Hand Coding a CodedUI test
How To: Automating Custom controls through CodedUI

Wednesday, February 4, 2015

Copy all comments from MS Word document

I tried today only and it worked. Go to your first comment and select all the text. Press SHIFT key and DOWN arrow key simultaneously up-to reaching the last comment. Then Copy (CTRL+C) and Paste (CTRL+V) in any text editor. All the comments would be available. Saving Time..

Saturday, January 10, 2015

Logging utility in C#

While doing Sharepoint CSOM Automation, I have written a simple utility to create test logs. Usually CodedUI results are not stored and this utility used to capture for each run. Also trying to extend the Assert function for capturing exceptions.

namespace AutomationFramework.TestScripts { class LogFile { private String sLogFile = ConfigurationManager.AppSettings["LogResultsFile"]; public void LogMessage(String sMsg = " ") { // Create a writer and open the file: StreamWriter log; if (!File.Exists(sLogFile)) { log = new StreamWriter(sLogFile); } else { log = File.AppendText(sLogFile); } // Write to the file: log.WriteLine(DateTime.Now + " : "+ sMsg); // Close the stream: log.Close(); } public void LogAssert(bool bCondition, String sMsg=null) { bool bResult = false; try { Assert.IsTrue(bCondition,sMsg); bResult = true; } catch (Exception ex) { LogMessage("Exception: " + ex.Message); Assert.Fail("Test FAILED"); } finally { if (bResult) { LogMessage("PASS "); } } } }

Wednesday, July 2, 2014

Unable to run javascript in internet explorer 11

Recently I was facing a peculiar issue. Unable to open the links, which are calling javascript functions directly. Those sites are working well on only internet explorer. I was changing Document mode and User Agent String.

Then I did uncheck the Popup Blocker and [CTRL + ALT + Click] combination. Not successful.
I was trying another option --> Tools > Compatibility View Settings > Check 'Display intranet sites in compatibility view'. Got success... Links were executing the required javascript functions.

Unable to open javascript links in ie 11
Internet Explorer 11’s Many User-Agent Strings

Monday, June 30, 2014

Microsoft Services openings

Are you ready to take BIG challenges and passion about Microsoft Technologies? Microsoft Services Global Delivery is looking for software professionals in following disciplines..