Showing posts with label automation. Show all posts
Showing posts with label automation. Show all posts

Sunday, June 10, 2018

Protractor - Getting browser log

Sometimes we need to get browser console information to validate tests. Protractor has ablity to retrieve the console info.

Need to add LoggingPrefs into config file and then you can access browser console info as per below code.

config:
'browserName': 'chrome', name: 'chrome-scripts', count: 1, loggingPrefs: { "driver": "INFO", "browser": "INFO" }



Code:
browser.manage().logs().get('browser').then(function(browserLog) { console.log('No of info from console:' + browserLog.length); browserLog.forEach(function(logInfo){ console.log('browser console info: ' + require('util').inspect(logInfo)); consoleInfo = require('util').inspect(logInfo); if (consoleInfo.indexOf('name:') !== -1) { expect(consoleInfo).toContain(fileToUpload); } else if (consoleInfo.indexOf('size:') !== -1) { expect(consoleInfo).toContain(fileSizeInBytes); } }); });



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 = "https://teams.SpApptest.com/sites/cthub"; 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

Thursday, May 29, 2014

Selenium WebDriver test in C#

I was trying simple C# test by using Selenium. It is very simple to use and noticed that few changes. You should have NUnit, Visual Studio 2013 and Selenium DLLs. You can go through the links, which are available at the end of post.

Bing Search - Selenium Test - C# Code

using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Support; using OpenQA.Selenium.IE; using NUnit.Framework; namespace BingSearch { [TestClass] public class SearchTests { public static IWebDriver WebDriver; [TestInitialize] public void setupAppTest() { try { System.Console.WriteLine("Test setup started..."); InternetExplorerOptions ieOptions = new InternetExplorerOptions(); ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true; ieOptions.IgnoreZoomLevel = true; WebDriver = new InternetExplorerDriver(ieOptions); } catch (Exception ex) { System.Console.WriteLine("Exception Occured in Init @ " + ex.Source); } } [TestMethod] public void testBingSearch() { //Navigate to the site WebDriver.Navigate().GoToUrl("http://www.bing.com"); // Get Search text field info IWebElement query = WebDriver.FindElement(By.Name("q")); // Enter Search String query.SendKeys("Selenium"); // Submit the form query.Submit(); // Sleep for 5 seconds System.Threading.Thread.Sleep(5000); //Get all the links from result page System.Collections.ObjectModel.ReadOnlyCollection links = WebDriver.FindElements(By.TagName("a")); //Print all the links foreach (IWebElement link in links) { System.Console.WriteLine(link.GetAttribute("href")); } //Assert the title text Assert.AreEqual("Selenium - Bing", WebDriver.Title); } [TestCleanup] public void testCleanup() { // Cleanup activites WebDriver.Quit(); WebDriver.Dispose(); System.Console.WriteLine("Test cleanedup & completed successfully.."); } } }


Below links might be useful to make setup to execute the Selenium tests.
How To - Setup C#, NUnit, Selenium
Capturning Screenshots

Wednesday, May 28, 2014

Top 5 Requirements for test automation tool

Recently there is an interesting discussion about top five requirements. Expectations are varied in group and few interesting thoughts...

Priorities for Advanced automation tool

  1. Robust Hybrid (Keyword driven+ Data Driven, etc) framework - None of the tool vendors are giving the libraries for Keyword driven Framework
  2. Language and OS independent - Should support multiple languages or libraries developed from multiple languages. Also tests should able to run in different type of OS. If I look test automation for past 15 years, tools are started to support multiple languages in last 6 years.
  3. Multi-browser and Multi-device support. For Mobile & Table support, tool should be lightweight app. Should use less storage for installation and less memory for execution.
  4. Ability to hook/hack custom object through programming or libraries
  5. Support for Continuous Integration tools - Automatically Should be able to deploy the build and then initiate the test suites and sent the report through email or SMS or any other devices.


To see few more experts answers - Discussion - What are the top five requirements for a test automation tool?

Wednesday, May 30, 2012

Open2test.org Free Automation Frameworks

Open2test.org team has developed many frameworks for different tools like QTP, Selenium, TestPartner, e-Tester, Silktest and OpenScript. Couple of years back, frameworks are available only for QTP & Selenium

Available frameworks

  • QTP for Web Framework
  • QTP for Windows Framework
  • QTP for .NET Framework
  • QTP for .NET Syncfusion Framework
  • QTP for JAVA Framework
  • QTP for SAP Framework
  • QTP for Oracle Apps Framework
  • QTP for Flex Framework
  • QTP for PowerBuilder Framework
  • QTP for Mainframe Framework
  • Selenium for Web Framework
  • Testpartner for Web Framework
  • Testpartner for .NET Framework
  • e-Tester for Web Framework
  • SilkTest for JAVA Framework
  • SilkTest for Web Framework
  • OpenScript for Web Framework

Monday, April 16, 2012

Robotframework with IronPython (CSharp)

RobotFramework Installation is a tricky task. Also installing for IronPython, is bit risky one. You may end up doing installation 3-4 times.

RobotFramework DotNet Support
How To: Use CSharp with Robot Framework

Robot Framework has given above page for DotNetSupport and Below I have given the instructions for Windows OS..

Tools installation
All RobotFramework related software can be the latest. The other software should be as the same version.

  1. Install Python (python-2.6.4.msi). Set installation directory as C:\Python26
  2. Install Robot Framework (robotframework-2.6win32.exe)
  3. Install Robot Selenium Library (robotframework-seleniumlibrary-2.7.win32.exe)
  4. Install Python Widgets (wxPython2.8-win32-unicode-2.8.11.0-py26.exe)
  5. Install Robot IDE (robotide-0.31.win32.exe)
  6. Install Python Win32 module (pywin32-214.win32-py2.6.exe)
  7. Install IronPython (IronPython_262.msi). Set installation directory as C:\IronPython
  8. Ensure .NET framework 4 should be available in current system

Environment variables Configuration
To execute RIDE and Pybot, environment variables should set properly.
  1. Create a system level environment variable & value as --> PYTHONHOME=C:\Python26
  2. Create a system level environment variable & value as --> PYTHONPATH=C:\Python26\Lib;C:\Python26\Scripts;C:\Python26\Lib\site-packages;C:\Python26\Lib\site-packages\SeleniumLibrary;C:\Python26\Lib\site-packages\robotide\;C:\Python26\Lib\site-packages\robot\;C:\Python26\Lib\site-packages\wx-2.8-msw-unicode;
  3. Also add to PATH variable --> % PYTHONHOME%;% PYTHONHOME%\Scripts;

For IronPython, environment variables should set properly.
  1. Create a system level environment variable & value as --> IRONPYTHONHOME=C:\IronPython
  2. Create a system level environment variable & value as --> IRONPYTHONPATH=%IRONPYTHONHOME%\Lib;%IRONPYTHONHOME%\Scripts;%IRONPYTHONHOME%\Lib\site-packages;%IRONPYTHONHOME%\Lib\site-packages\SeleniumLibrary;%IRONPYTHONHOME%\Lib\site-packages\robotide\;%IRONPYTHONHOME%\Lib\site-packages\robot;

Preparing ipybot.bat
To run with IronPython, you need to create a batch script. Copy below contents into a text editor and save it as ipybot.bat.
@echo off :: :: ipybot.bat - for IronPython :: IRONPYTHONHOME - Env variable set for IronPython home directory :: PYTHONHOME - Env variable set for CPython home directory :: :: Copyright 2008-2010 Nokia Siemens Networks Oyj :: :: Licensed under the Apache License, Version 2.0 (the "License"); :: you may not use this file except in compliance with the License. :: You may obtain a copy of the License at :: :: http://www.apache.org/licenses/LICENSE-2.0 :: :: Unless required by applicable law or agreed to in writing, software :: distributed under the License is distributed on an "AS IS" BASIS, :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. :: See the License for the specific language governing permissions and :: limitations under the License. :: :: pybot.bat -- Python start up script for Robot Framework on Windows :: :: Python executable to use. set pythonExec="%IRONPYTHONHOME%\ipy.exe" :: Path to robot\runner.py :: set runner="%PYTHONHOME%\Lib\site-packages\robot\runner.py" set runner="%IRONPYTHONHOME%\Lib\site-packages\robot\runner.py" :: Run Robot on Python interpreter %pythonExec% %runner% %*

Changes for Robot Framework
RobotFramework is developed by CPython. To support IronPython, we need to do few changes.
  1. 1. Copy folders %PYTHONHOME%\Lib\site-packages\SeleniumLibrary;%PYTHONHOME%\Lib\site-packages\robotide\;%PYTHONHOME%\Lib\site-packages\robot\;
    To
    %IRONPYTHONHOME%\Lib\site-packages
  2. Need to copy few files from Python installation. Few files should be downloaded over internet and copy into ironpython installation. Few files may not be required to copy for latest Robot framework. Create a following batch file with required files and execute the script to copy all of them.
:: Python Home directory. set pythonIns=%PYTHONHOME% set ironpythonIns=%IRONPYTHONHOME% :: Files to be copied :: Copy ipybot.bat from current directory to IronPython installed dir copy ipybot.bat "%ironpythonIns%\" /y :: Copy expatbuilder.py from under Python\Lib\xml\dom to IronPython\Lib\xml\dom copy "%pythonIns%\Lib\xml\dom\expatbuilder.py" "%ironpythonIns%\Lib\xml\dom\" /y :: Copy expat.py from under Python\Lib\xml\parsers to IronPython\Lib\xml\parsers copy "%pythonIns%\Lib\xml\parsers\expat.py" "%ironpythonIns%\Lib\xml\parsers\" /y :: copy fepy/trunk/lib/pyexpat.py from IronPython\Lib copy pyexpat.py "%ironpythonIns%\Lib\" /y :: copy fepy/trunk/lib/unicodedata.py from IronPython\Lib copy unicodedata.py "%ironpythonIns%\Lib\" /y :: Copy ElementTreePath.py from under Python\Lib\xml\etree to IronPython\Lib\xml\parsers copy "%pythonIns%\Lib\xml\etree\ElementTree.py" "%ironpythonIns%\Lib\xml\etree\" /y :: Copy a dummy signal.py from current dir



Steps for 64 Bit OS To enable Robot Framework for 64 bit OS, you should install 64 bit python setup in same directory. Also the command prompt should be invoked through setting ‘Run as a Administrator’ if OS is Vista or Windows 7 version.


Verify the Installation
Open new command prompt and type ‘pybot --version’ and output like --> Robot Framework 2.6.0 (Python 2.6.4 on win32) In Command prompt, type ‘ipy’ and output like ---> IronPython 2.6.2 (2.6.10920.0) on .NET 4.0.30319.1

Sunday, April 8, 2012

QTP New Version?

QTP did not release any updates for almost two years. Any guess, whether HP is going to come with any different release altogether or coming up with new tool...

See the release history below...

11.0 - Released in 2010
10.0 - Released in 2009
9.5 - Released in 2008
9.2 - Released in 2007
9.1 - Released in 2007
9.0 - Released in 2006
8.2 - Released in 2005
8.0 - Released in 2004
source: Wikipedia - QuickTest Professional

Sunday, March 25, 2012

Robot Framework - TypeKey Library

Implemented a library to simulate keyboard events. It can be used for upload and download operations along with Selenium.

TypeKeyLib - Library

# Author: Palani Selvam
#
# Purpose: Test library to simulate keyboard actions.
#

import time
import sys,os
import win32api, win32con
from win32com.client import Dispatch

from robot.errors import DataError
from robot import utils

__version__ = '0.1' # Developed by Palani

class TypeKeyLib:
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = __version__

def __init__(self):
""" TypeKeyLib Library can be imported with optional arguments
"""
self._result='Init'
# To do

def TypeKeys(self,sKey):
""" TypeKeys - used to simulate keyboard keys. Parameter sKey can be STRING or LIST
For Key representation, see at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthsendkeys.asp

"""
try:
self._result='TypeKeys method'
shell=Dispatch("WScript.Shell")

stype = type(sKey).__name__
#print 'Given type: ', stype

if (stype == 'list'):
# Execute multiple times
for key1 in sKey:
shell.SendKeys(key1)
time.sleep (0.5)
else:
# Execute only one time
shell.SendKeys (sKey)
time.sleep(1)
#shell=Nothing
self._result='pass'
except:
self._result='fail'
print '*INFO* Exception occurs: ', sys.exc_type , ":", sys.exc_value
raise
finally:
self._result+= ' done'
return self._result

def TypeKeys_Space(self):
""" TypeKeys_Space - used to simulate SPACE.
"""
self.TypeKeys (" ")

NOTE: It will work only with Windows OS...

Sunday, March 18, 2012

Robot Framework - Database Libraries

Robot framework already has two database libraries and both are implemented in different lanugauges.
Database Library - Java
Database Library - Python

I have developed two simple database libraries. One is for generic ODBC interface and another one is especially for Oracle. The second one can be used as thin client.
Database Library - ODBC interface

#
# Author: Palani Selvam
#
# NOTE: It is supported all type of Databases, which are having support to ODBC
# For ex, DB2, ORACLE, MS SQL SERVER, Sybase.
#
import pyodbc as DB
from robot.errors import DataError
from robot import utils

__version__ = '0.1' # Developed by Palani - 20101022

class DBLibrary:

ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = __version__

def __init__(self):
"""DBLibrary Library can be imported with optional arguments.

"""
self._connection = None
self._default_log_level = 'INFO'
self._bexception = False
#self._prompt = prompt

def make_connection(self, sDsn, sUid=None, sPwd=None):
""" make_connection method is used to create the connection object.
sDsn - DataSource Name
sUid - User Id to access the database
sPwd - Password to access the database
"""
sConn = None
try:
sConn = DB.connect(dsn=sDsn, uid=sUid, pwd=sPwd )

except Exception:
self._bexception = True
print 'Connection for database has failed', Exception
raise
finally:
self._connection = sConn

def execute_sql (self,sSql=None,iRows=None):
""" execute_sql method is used to execute the sql query to the given connection object.
sSql - Query to access the database
iRows - No of rows to be returned.
"""
sOut = None
sCursor = None
sConn = self._connection

if (sConn == None) :
return sOut
else:
try:
sCursor = sConn.cursor()
sCursor.execute(sSql )
# curs.execute("SELECT * FROM EmpTable WHERE SCOPE=3 ")
if (iRows <> None) :
iRows = int (iRows)
sOut = sCursor.fetchmany (iRows)
else :
sOut = sCursor.fetchall ()

except Exception:
self._bexception = True
print 'Query execution is failed. ', Exception
raise
finally:
if (sCursor <> None):
sCursor.close ()
return sOut

def execute_for_one_row (self,sSql=None):
""" execute_for_one_row method is used to execute the sql query and returns only first row.
sSql - Query to access the database
"""
sOut = None
sCursor = None
sConn = self._connection

if (sConn == None) :
return sOut
else:
try:
sCursor = sConn.cursor()
sCursor.execute(sSql )
rows = sCursor.fetchone ()
for sOut in rows:
break

except Exception:
self._bexception = True
print 'Query execution is failed. ', Exception
raise
finally:
if (sCursor <> None):
sCursor.close ()
return sOut

def disconnect_from_database (self,sConn=None):
""" disconnect_from_database method is used to disconnect from the given connection object.
sConn - Connected Object, which is got through make_connection method.
"""
if (sConn <> None):
sConn.close ()
else:
self._connection.close ()

Database Library - Oracle
#
# Author: Palani Selvam
#
#
# NOTE: It is supported only ORACLE Databases
# DSN is not required.
#
import cx_Oracle as DB
from robot.errors import DataError
from robot import utils

__version__ = '0.1' # Developed by Palani

class ORADBLibrary:

ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = __version__

def __init__(self):
"""DBLibrary Library can be imported with optional arguments.

"""
self._connection = None
self._default_log_level = 'INFO'
self._bexception = False
#self._prompt = prompt

def ora_make_connection(self, sConnString):
""" make_connection method is used to create the connection object.
sConnString - Connection String

Example:
'sqluser/welcome@127.0.0.1/orcl'
"""
sConn = None
try:
sConn = DB.connect(sConnString )

except Exception:
self._bexception = True
print 'Connection for database has failed', Exception, sConnString
raise
finally:
self._connection = sConn

def ora_execute_sql (self,sSql=None,iRows=None):
""" execute_sql method is used to execute the sql query to the given connection object.
sSql - Query to access the database
iRows - No of rows to be returned.
"""
sOut = None
sCursor = None
sConn = self._connection

if (sConn == None) :
return sOut
else:
try:
sCursor = sConn.cursor()
sCursor.execute(sSql )
# curs.execute("SELECT * FROM EMP_Table WHERE SCOPE=3 ")
if (iRows <> None) :
iRows = int (iRows)
sOut = sCursor.fetchmany (iRows)
else :
sOut = sCursor.fetchall ()

except Exception:
self._bexception = True
print 'Query execution is failed. ', Exception
raise
finally:
if (sCursor <> None):
sCursor.close ()
return sOut

def ora_execute_for_one_row (self,sSql=None):
""" execute_for_one_row method is used to execute the sql query and returns only first row.
sSql - Query to access the database
"""
sOut = None
sCursor = None
sConn = self._connection

if (sConn == None) :
return sOut
else:
try:
sCursor = sConn.cursor()
sCursor.execute(sSql )
rows = sCursor.fetchone ()
for sOut in rows:
break

except Exception:
self._bexception = True
print 'Query execution is failed. ', Exception
raise
finally:
if (sCursor <> None):
sCursor.close ()
return sOut

def ora_disconnect_from_database (self,sConn=None):
""" disconnect_from_database method is used to disconnect from the given connection object.
sConn - Connected Object, which is got through make_connection method.
"""
if (sConn <> None):
sConn.close ()
else:
self._connection.close ()
Like above, we can extend Robot Framework easily...

Sunday, February 12, 2012

RobotFramework Standards

RobotFramework team has given guidelines --> HowToWriteGoodTestCasesWithExamples. Similar to coding standards, Automation team should use certain guidelines for Keyword-Driven framework also. It would be more useful to functional team as well as other teams.

Test Suite / Script

  • Test Script names should be less than 20 characters and file type should be HTML.
  • It should be easily readable and self-explanatory.
  • Remember that suite names are created automatically from file/directory names. Extensions are stripped, underscores are converted to spaces and, if name is all lower case, words are capitalized. For example login_tests.html -> Login Tests and DHCP_and_DNS -> DHCP and DNS.
  • Documentation should be updated with purpose of the script and pre-conditions.
  • Proper keywords should be given for Suite Setup, Suite Teardown, Test Setup and Test Teardown.
  • Should not have too many tests (max 50) in one suite unless they are data-driven.

TestCases / Tests
  • Test case names should be less than 40 characters and file type should be HTML.
  • Test case Name should be in camel case (In a word, First letter is capital and remaining letters are in small).
  • It should be easily readable and self explanatory.
  • Documentation should be updated with manual test case steps, notes and pre-conditions.
  • Proper keywords should be given for Suite Setup, Suite Teardown, Test Setup and Test Teardown.
  • Appropriate tags should be given for each case.
  • Tests should be independent.
  • In dependant tests, detailed notes should be given. Consider verifying the status of the previous test using ${PREV TEST STATUS} variable.
  • Hard coding of object name should be avoided.
  • Should contain many high level keywords instead of repeating steps often.
  • High level keywords should be used for navigation.
  • Local variables should have prefix char ‘t’ as temporary variables

Resources
  • Keep all resource files in single folder.
  • Resource file names should be less than 20 characters and file type should be HTML.
  • All characters should be small characters.
  • Documentation should be updated with purpose.
  • All constants should be maintained in separate resource file.
  • Keep separate resource files for application’s data.
  • Keep separate resource files for all GUI objects page wise or module-wise.
  • Group the high level keywords by categories like business logic, module and general.

High Level Keyword / User Keyword / Function
  • Function names should be less than 35 characters.
  • It should be easily readable and self explanatory.
  • For easy readability, it should be in camel case (Capital & Small letters).
  • Prefixes are sometimes useful. For example, Is - to ask a question about something, Get - get a value, Set - set a value
  • Can have space for better readability.
  • Documentation should have clear details for purpose, variables and returning values.
  • Hard coding of object name should be avoided.
  • Arguments should have char ‘p’ as prefix and returned variable should have char ‘r’ as prefix.
  • Local variables should have prefix char ‘t’ as temporary variables
  • Duplicate Functions should not be added.
  • Can contain some programming logic (for loops, if/else)
  • Complex logic in libraries rather than in user keywords
  • Important variables can have comments on the RHS

Variables
  • Variable names should be less than 20 characters.
  • Variables should have meaningful words
  • For easy readability, it should be in camel case (Capital & Small letters).
  • Local variables should have prefix char ‘t’ as temporary variables
  • Arguments should have char ‘p’ as prefix and returned variable should have char ‘r’ as prefix.
  • GUI object variables should have char ‘o’ as prefix.
  • Constant variables should be in Capital letters. For example, APP_URL, DB_SERVER. All other type of variables should have mixed style (small and capital) characters.
  • Script/Global variables should be defined at the top of the script.
  • Function / test case level variables should be defined at top of the function.
  • Can have space. But try to restrict for minimum

Sunday, October 2, 2011

FOR loops & IF condition in RobotFramework

Using Robot Framework, test engineer can create FOR loops and IF conditions. I don't think so, any other Keyword driven framework is giving this kind of flexibility.

FOR loop can be set in two ways. First one is based on number of items in a List. Another one is based on range like from 1 to 50. Similarly keywords can be executed if condition matches or not. See below example.

FOR Loop & IF condition explantation using Robot Framework

TestCase Action Arguments
VerifyListItems [Arguments] ${Locator} @{ListItems}
[Documentation] Verifies the list of items present in a List Object.
: FOR ${Element} IN @{ListItems}
Select From List ${Locator} ${Element}
List Selection Should Be ${Locator} ${Element}
: FOR ${index} IN RANGE 50
${obj1}= Evaluate ${index}*4+3
Run Keyword if '@{tDriverData}[4]'=='2' Go To MyProfile
Run Keyword Unless '@{tDriverData}[4]'=='2' Go To UserCreation

Monday, August 15, 2011

Robotframework Installation

RobotFramework Installation is a tricky task. We need to install 6-7 utilities. All should be installed in the same order. Here I have given the instructions for Windows OS.

Tools installation
All RobotFramework related software can be the latest. The other software should be as the same version.

  1. Install Python (python-2.6.4.msi). Set installation directory as C:\Python26
  2. Install Robot Framework (robotframework-2.6win32.exe)
  3. Install Robot Selenium Library (robotframework-seleniumlibrary-2.7.win32.exe)
  4. Install Python Widgets (wxPython2.8-win32-unicode-2.8.11.0-py26.exe)
  5. Install Robot IDE (robotide-0.31.win32.exe)
  6. Install Python Win32 module (pywin32-214.win32-py2.6.exe)
  7. OPTIONAL (For SeleniumLibrary)- Install Java (jdk-6u14-windows-i586.exe), if your machine does not have Java.
  8. OPTIONAL (For SeleniumLibrary)- Extract Selenium RC Server (selenium-remote-control-1.0.3.zip)

Environment variables Configuration
To execute RIDE and Pybot, environment variables should set properly.
  1. Create a system level environment variable & value as --> PYTHONHOME=C:\Python26
  2. Create a system level environment variable & value as --> PYTHONPATH=C:\Python26\Lib;C:\Python26\Scripts;C:\Python26\Lib\site-packages;C:\Python26\Lib\site-packages\SeleniumLibrary;C:\Python26\Lib\site-packages\robotide\;C:\Python26\Lib\site-packages\robot\;C:\Python26\Lib\site-packages\wx-2.8-msw-unicode;
  3. Also add to PATH variable --> % PYTHONHOME%;% PYTHONHOME%\Scripts;

Steps for 64 Bit OS
To enable Robot Framework for 64 bit OS, you should install 64 bit python setup in same directory. Also the command prompt should be invoked through setting ‘Run as a Administrator’ if OS is Vista or Windows 7 version.

Verify the Installation
Open new command prompt and type ‘pybot --version’ and output like --> Robot Framework 2.6.0 (Python 2.6.4 on win32).

Tuesday, July 12, 2011

RobotFramework - Overview

I have executed many automation projects and also developed various automation frameworks using different tools like Silktest, QTP, Selenium, CodedUI, MS UIA, VisualTest (dead) and Winrunner (dead). Tried few open source frameworks and found RobotFramework as the best one. Successfully completed five projects using RobotFramework. Main advantage is, I'm able to integrate with different test tools and libraries. It is neither related to IBM Rational tools or any other commercial tools.

Summary in RobotFramework Homepage
Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD). It has easy-to-use tabular test data syntax and utilizes the keyword-driven testing approach. Its testing capabilities can be extended by test libraries implemented either with Python or Java, and users can create new keywords from existing ones using the same syntax that is used for creating test cases.

Robot Framework is open source software released under Apache License 2.0. Its copyrights are owned and development supported by Nokia Siemens Networks.

Robot Framework Features

  1. Advanced Keyword Driven framework
  2. Enable functional team contribution for automation
  3. Reusable/custom keywords
  4. Dynamic variables
  5. Easily extendable by Python, C# & Java
  6. Supports few test libraries including Selenium
  7. Provides simple and powerful Results Reporting
  8. Multiple Operating Systems support
  9. $ Free


Links for Robot Framework Resources
Robot Framework Home Page
Robot Framework User Guide
Robot Framework Quick Start Guide
Robot IDE
Robot Selenium Library

Robot Framework - Introduction
Robot Framework - Articles
Simple tutorial for Robot Framework

In last 6 months, many updates are happened on Robot framework and its related libraries. It is supporting many of my generic automation framework features.

Headers

Features

Robot Framework

Supported FrameworksFunctional DecompositionYes
Data DrivenYes
Keyword DrivenYes
Table DrivenYes
Independent toOperating SystemYes
ApplicationYes
TechnologyYes
Test ScriptingRecordingNo
ParametrizationYes
Suite Setup ModuleYes
Suite TearDown ModuleYes
Test Setup ModuleYes
Test TearDown ModuleYes
Database IntegrationYes
ScriptingYes
Environment LibraryYes
Test ExecutionMultiple OSYes
Multiple platformsYes
Parallel ExecutionNo
Test TimeoutYes
Based on PriorityYes
Grouping TestsYes
Running Failed testsYes
Result AnalysisDetail reporting for each step executionYes
Snapshots for failed testsYes
Test level reportingYes
Compiled reportYes
Results by categoryYes
Expected BenefitsLess effort to automateYes
Less dependence on highly skilled automation professionalsYes
Exception handlingYes
Easy to MaintainYes
Easy to Integrate with Other toolsYes
Support to CI (Continuous Integration) toolsYes
Additional ExpectationsDynamic conditionsYes
Dynamic Loop supportYes
UI to Edit dataYes
UI to execute testsYes
Update test metrics automaticallyYes
Update captured defects automaticallyYes

Friday, January 28, 2011

Generic Test Automation Framework

So far, I have developed various automation frameworks and recently using Robot Framework. Listed many features for Ideal Automation Framework and given below. Also would like to get more features from other users.

Reference to earlier posts and Links about automation framework.
Wikipedia - Test Automation
Wikipedia - KeyWord Driven Testing
Is KeyWord Driven Framework enough?
My Thoughts about Automation
What is an Automation Framework - from Dhanasekar's blog

Features for Generic and common Test Automation Framework

Headers

Features

Supported FrameworksFunctional Decomposition
Data Driven
Keyword Driven
Tabel Driven
Independent toOperating System
Application
Technology
Test ScriptingRecording
Parameterization
Suite Setup Module
Suite TearDown Module
Test Setup Module
Test TearDown Module
Database Integration
Scripting
Environment Library
Test ExecutionMultiple OS
Multiple platforms
Parallel Execution
Test Timeout
Based on Priority
Grouping Tests
Running Failed tests
Result AnalysisDetail reporting for each step execution
Snapshots for failed tests
Test level reporting
Compiled report
Results by category
Expected BenefitsLess effort to automate
Less dependence on highly skilled automation professionals
Exception handling
Easy to Maintain
Easy to Integrate with Other tools
Support to CI (Continuous Integration) tools
Additional ExpectationsDynamic conditions
Dynamic Loop support
UI to Edit data
UI to execute tests
Update test metrics automatically
Update captured defects automatically

Friday, January 21, 2011

Silktest2010R2

Silktest 2010R2 has been released in this month and Release notes - SilkTest_ReleaseNotes_en.pdf

Enhancements
Microfocus has improved the support for 64 bit Operating Systems and improved the features for Silk4NET and Silk4J Plugins.

  • Java AWT/Swing Application and Applet Record and Replay Support
  • Adobe Flex Version 4.x Support
  • 64-bit Support for .NET and Windows API-based Applications
  • Default Recording Mode for xBrowser Applications is Low-Level Native User Input
  • Dynamically Invoke Methods
  • SilkTest Workbench - Importing and Exporting Assets, ObjectMaps, Embedded Scripting Language & Integration with Additional Micro Focus Products
  • SilkTest Classic - Dynamic Object Recognition Supports Recording Locator Keywords

End-Of-Life (EOL) Components
I am wondering after seeing MSUIA technology in EOL list. Without that I'm sure that no body can support silverlight automation. Are they serious about this?
  • Adobe Air 1.x
  • Classic OCR
  • Firefox 3.0
  • IBM JRE 1.5
  • Java version 1.5
  • MSUIA technology domain (the WPF technology domain is still supported)

This time, Microfocus has developed few more documents and I like the effort for Migrating from the SilkTest Classic Agent to the Open Agent. More details from below links:
Silktest 2010R2 Release materials
Silktest 2010R2 Classic Documentation

Monday, December 27, 2010

Silverlight Automation

Few of our web applications were migrated to Silverlight technology. I was looking tools for Silverlight Automation. Still many of the leading automation tools have partial support. Few tools like Silktest do not have any support for Silverlight components. Even Microsoft's codedUI test didn't have support upto October 2010. So far, I have seen WebUI Test (Telerik's product) and QALiber (open source) have better support for Silverlight components.

Interestingly all of these UI tools are using MS UIA to identify and interact with Silverlight components. UIA is the successor technology to MSAA (Microsoft Active Accessibility). It is freely available from DotNet Framework. Recent Microsoft Operating Systems (Windows 7, Windows 2008 R2) have better support for UIA.

Microsoft UI Automation provides a single, generalized interface that automation clients can use to examine or operate the user interfaces of a variety of platforms and frameworks. UI Automation enables both accessibility applications such as screen readers and quality-assurance (test) code to examine user-interface elements and simulate user interaction with them from other code.

UIA Supporting Applications

  • Silverlight Applications
  • WPF Applications
  • .NET Windows Forms applications
  • Win32 Applications

Few References:
MS UIA (UI Automation)
Microsoft Documentation - Silverlight Accessibility Overview
UI Automation of a Silverlight Custom Control

WebUI Test tool - Commercial
QALiber tool - Open Source
WHITE tool - Open Source

Wishing you and your family a very happy, healthy and prosperous new year. Have a wonderful year ahead!!!

Tuesday, August 17, 2010

Silktest 2010

Microfocus released silktest 2010 last month. It has few additional features and enhancements. First time, release notes are published in PDF format. SilkTest_ReleaseNotes - pdf

Silktest 2010 Features

  1. Visual Tests- SilkTest Workbench lets you quickly record and playback visual tests. Visual tests comprise the basic building
    blocks of an automated testing solution. SilkTest Workbench uses visual tests to mimic the actions that are
    performed while testing an application.
  2. Embedded Scripting Language - SilkTest Workbench's scripting language is Microsoft's Visual Basic, a robust programming language that gives
    you total control over any application running in the Microsoft .NET framework. .NET scripts contain the functionality of a high-level programming language as well as features designed specifically for software control and testing.
  3. Integration with Additional Micro Focus Products- The SilkTest product suite includes two plugins, Silk4NET and Silk4J, which both work with SilkTest Recorder. Additionally, SilkTest Workbench works with SilkCentral Test Manager (SCTM).

I was expecting Silverlight Support in this release. I know that Mirofocus were working for Silverlight support. Microfocus may release the Silverlight support in next version.

Silk4J - Java as scripting language, introduced in Silktest 2008.
Silk4NET - C# or VB.NET as scripting language, introduced in Silktest 2010

End-Of-Life (EOL) Components
Also it has announced End of support for few OS and other features. The following operating systems, features, and integrations are not supported in SilkTest 2010.
  1. SilkTest Classic 4Test outline Editor mode Note: SilkTest Classic will continue to be supported. This change will not affect most SilkTest Classic users.
  2. Windows XP SP2
  3. Windows 2003 Server
  4. Java 1.4
  5. StarTeam integration
  6. PVCS integration

Monday, May 31, 2010

Keystroke automation through VBScript

I was looking for a solution, which should do collapse all for silktest code. It is needed before do code comparison. I tried simple VBScript and it is working fine. It is fully based on keystrokes. Below I've shared the code.

VBScript - Sending Keystrokes

' To Collapse All opened Silktest files ' Usage: wscript silktest_collapse.vbs 100 Dim WshShell, iItem, iCount If WScript.Arguments.Count > 0 Then iCount = CInt(WScript.Arguments.Item(0)) Else iCount = 10 End If Wscript.Echo "Count " & CStr(iCount) Set WshShell = Wscript.CreateObject("Wscript.Shell") 'WshShell.AppActivate "Silktest - *" WshShell.SendKeys "%{TAB}" Wscript.Sleep 5000 For iItem=1 to iCount 'To Collapse -> Alt+L+L WshShell.SendKeys "%" WshShell.SendKeys "l" Wscript.Sleep 200 WshShell.SendKeys "l" Wscript.Sleep 1000 'To Save -> Ctrl+S WshShell.SendKeys "^s" Wscript.Sleep 900 'To Close -> Alt+F+C WshShell.SendKeys "%" WshShell.SendKeys "f" Wscript.Sleep 200 WshShell.SendKeys "c" Wscript.Sleep 700 Next Wscript.Echo "Completed."

Tuesday, April 27, 2010

Rules for Object Recognition

Object Recognition is very important thing in any GUI testing tool. Silktest also having set of formats and limitations to identify the objects.

MicroFocus/Borland used to publish "Rules for Object Recognition" document for each silktest release. It is available at techpubs-Rules for Object Recognition

Rules for Object Recognition
Caption - Restricted to 127 characters
WindowID - Restricted to 63 characters
Closest Static Text or Attached Text
4Test Produces – Window Declaration Identifier, Single Tag or Multitag
Agent Produces – Index, Prior Text, Location
Extension Produces – WindowID, Caption

We can manage the automation suite properly for minor application changes by making proper tags. I have given few tips to control the UI changes in the application.
Window declarations Level
1. Object caption change. Use multiple tags
2. Object level change. Assume that UserName text field is under a HtmlTable. Now you set a window variable to have same object level.
3. Same set of objects are in multiple pages. Create a class.
4. Use Variables for page title changes.

Functions Level
1. Navigations. For example, clicking a link, clicking a button.
2. Micro functions. Split to small functions as you have to change in only one place.
3. Use some wrapper functions for all classes. For example, an object is a htmlcheckbox and now it is changed to radio button.