"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

December 27, 2010

Ringo - Selenium Automation Framework by Google

I found below link useful for developing automation framework using selenium.



tseng -  based on Google's Ringo now available for public. Link
Presentation slides available in link
Notes from the talk
Design Decisions
  • Build common framework
  • Isolate Test Case specific details
  • Application specific logic kept in client class
  • Provide uniform way of accessing UI elements
  • Flexibility - Group Test Cases
  • Placeholder for configuration data
  • Maintainability - Maintaining Data for Testcases
  • Support Data Driven Test, Same test run with different sets of data
Architecture
  • Tool Selection Criteria - Handle AJAX Controls
  • Selenium Locators - Identify element in page
  • Testing Framework - TestNG
  • Data provider features- Support for Data Driven Testing
  • TestNG would handle looping and invoking methods
  • Read from XML, Database is supported
  • Firebug - Used as Development Tool
Architecture
  • Configuration Layer
  • UI Layer Abstraction
  • Application logic lies in client class
  • Uniform way of accessing UI object using helpers
  • UI Map - Storing UI Elements
  • Data could be shared acrosss Test Cases
  • Keep data in one place
  • Web Apps Common Action - Filling forms
  • Helper class takes page & data object
  • For each UI element fill corresponding provided values
  • Changes is updating UI & Datamap
  • Application Client - Subtree of classes
Application Test
  • Contains Test cases, Uses API's provided by client class
  • Test Case Flow - Test Case -> Client Class (High level API) -> Helper (Common actions, Wrapper classes using selenium commands)
Yep, Excellent Presentation and lot of Information for building automation framework.

More Reads - Link1, Link2
Selenium - is NOT a Framework
Template method pattern
Selenium 2 Examples
Web test automation best practices
First steps with Lightweight Test Automation Framework
Selenium Framework by Google

December 21, 2010

TestNG: Passing Array of Objects in DataProvider


Now in this example, We will try an example to pass Array of Objects in the Dataprovider for TestNG test.

Please find working code and example listed below. Please run it as TestNG test in your eclipse editor


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.testng.Assert;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.*;

//Example for Array of Objects
public class TestNGExample
{

 private String InputData;
 private List<String> ExpectedResults = new ArrayList<String>();
public String getInputData()
{
  return InputData;
}

public void setInputData(String inputData)
{
  InputData = inputData;
}

public List<String> getExpectedResults()
{
  return ExpectedResults;
}

public void setExpectedResults(List<String> expectedResults)
{
  ExpectedResults = expectedResults;
}


@DataProvider(name = "Array of objects Example")
public Object[][] parameterIntTestProvider()
{
  System.out.println("Start Data Provider Section");
  List<String> TestOneExpectedList = new ArrayList<String>();
  TestOneExpectedList.add("one expected");
  TestOneExpectedList.add("Three expected");
  TestOneExpectedList.add("two expected");
  TestOneExpectedList.add("four expected");

  List<String> TestTwoExpectedList = new ArrayList<String>();
  TestTwoExpectedList.add("one expected");
  TestTwoExpectedList.add("Three expected");
  TestTwoExpectedList.add("two expected");
  TestTwoExpectedList.add("four expected");

  TestNGExample[] Arrayobj = new TestNGExample[2];
  System.out.println("Declaration Successful : Assign Data Provider");
  Arrayobj[0] = new TestNGExample(); // I made mistake here, Commenting to highlight learning
  Arrayobj[0].setInputData("One");
  Arrayobj[0].setExpectedResults(TestOneExpectedList);
  System.out.println("First Assignment : " + Arrayobj[0].getInputData());

  Arrayobj[1] = new TestNGExample();
  Arrayobj[1].setInputData("Two");
  Arrayobj[1].setExpectedResults(TestTwoExpectedList);
  System.out.println("End : Assign Data Provider");

  for (int i = 0; i < 2; i++)
  {
   TestNGExample arrayobj = Arrayobj[i];
   System.out.println("Input Data is :" + arrayobj.getInputData());
   List<String> ls = arrayobj.getExpectedResults();
   Iterator it = ls.iterator();
   while (it.hasNext())
   {
    String value = (String) it.next();
    System.out.println("Value :" + value);
   }
  }
 return new Object[][] { { Arrayobj } };
}

@Test(dataProvider = "Array of objects Example")
public void TestMethodforClass(TestNGExample[] Arrayobj)
{
  System.out.println("Start Test : Array of objects Example");
  for (int i = 0; i < 2; i++)
  {
    TestNGExample arrayobj = Arrayobj[i];
    System.out.println("Input Data is :" + arrayobj.getInputData());
    List<String> ls = arrayobj.getExpectedResults();
    Iterator it = ls.iterator();
    while (it.hasNext())
    {
     String value = (String) it.next();
     System.out.println("Value :" + value);
    }
   }
  System.out.println("End Test : Array of objects Example");
 }

}

Results
Start Data Provider Section
Declaration Successful : Assign Data Provider
First Assignment : One
End : Assign Data Provider
Input Data is :One
Value :one expected
Value :Three expected
Value :two expected
Value :four expected
Input Data is :Two
Value :one expected
Value :Three expected
Value :two expected
Value :four expected
Start Test : Array of objects Example
Input Data is :One
Value :one expected
Value :Three expected
Value :two expected
Value :four expected
Input Data is :Two
Value :one expected
Value :Three expected
Value :two expected
Value :four expected
End Test : Array of objects Example
PASSED: TestMethodforClass([LTestNGExample;@1ac2f9c)


Below link was useful for working on Array of Objects.

Happy Reading!!

December 19, 2010

TestNG - Assigning Data Providers using Class Members

In continuation with previous posts, We will look at passing data using class members. The following blog helped me to understand and write the example

Please find working code and example listed below. Please run it as TestNG test in your eclipse editor

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.testng.Assert;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.*;

public class Test3
{
 private String InputData;
 private String ExpectedResult;
 private List<String> ls = new ArrayList<String>();

 public List<String> getLs()
{
  return ls;
 }
 public void setLs(List<String> ls)
{
  this.ls = ls;
 }
 // Under Source Menu Select Generate Getters & Setters - Tip from my colleague Avinash
public String getInputData()
{
  return InputData;
 }

 public void setInputData(String inputData)
{
  InputData = inputData;
 }

 public String getExpectedResult()
{
  return ExpectedResult;
 }

 public void setExpectedResult(String expectedResult)
{
  ExpectedResult = expectedResult;
 }

@DataProvider(name = "Dataprovider set with class members")
public Object[][] parameterIntTestProvider()
{
  Test3 obj = new Test3();
  obj.setInputData("TestInput");
  obj.setExpectedResult("TestExpectedResult");
  List<String> TestList = new ArrayList<String>();
  TestList.add("one expected");
  TestList.add("Three expected");
  TestList.add("two expected");
  TestList.add("four expected");
  obj.setLs(TestList);
  return new Object[][] { { obj } };
 }

@Test(dataProvider = "Dataprovider set with class members")
public void TestMethodforClass(Test3 TestClass)
{
  System.out.println("Start Test : Dataprovider set with class members");
  System.out.println("Input Data is :" + TestClass.getInputData());
  System.out.println("Expected Result is :"+ TestClass.getExpectedResult());
  List<String> ls = TestClass.getLs();
  Iterator it = ls.iterator();

  while (it.hasNext())
{
   String value = (String) it.next();
   System.out.println("Value :" + value);
  }
  System.out.println("End Test");
 }
}

Hope it Helps!!

Selenium Automation Tricks From Selenium Wiki

Bunch of useful posts I bookmarked for Selenium. A very good site Selenium Wiki, UnLtdGroup| Selenium Wiki I came across. Nice work by Pavandeep managing the site. Impressive quote "It is not the software that is great; it's the people who use it who make it great". Sharing the Learning's very much appreciated.

Useful posts I bookmarked for my future reference
Commonly Used Selenium Commands
Selenium Data Driven Testing with C#
Selenium RC with Java and JUnit
Selenium – verifyXpathCount
Using Xpath in Selenium and Selenim RC
Using Selenium IsVisible
Using Array to execute Selenium commands in C#
How to verify the image height and width in Selenium
Getting the Browser details in Selenium
Selenium and Hudson Integration:Keeping your Test Code separate from execution code
Selenium Tutorial: Ant Build for Selenium Java project
Handling JS Errors in Selenium
Handling Pop-up Windows in Selenium
Upload a File in Selenium
Java Properties File
Measuring Web Page Performance with Selenium 2 and the Web Timings API
Selenium 2 - Get Number of Rows in a Table


Next set of links
Automated Selenium Testing with Maven
Maven Selenium
Defining test descriptions in testng reports
Extending Selenium server with custom commands
Maven Getting Started Guide
Using groups with TestNG
Start your webtests with Selenium2, Maven, TestNG – now
Next-Generation Testing with TestNG
TestNG - Basic
TestNG Report
ReportNG
How To Get Started With Selenium Core And ASP.NET MVC
Selenium IE Issues
Writing Selenium Tests
Using XPath Expressions as Locators
Selenium XPath Cheatsheet
Selenium Locator Tips

Java Script Error Handling
Checking for JavaScript Errors with Selenium

Selenium Xpath Reads
Selenium Xpath
Selenium Locators
Selenium Tips: Start improving your locators
How To Minimize The Pain Of Locator Breakage
Selenium Tips: CSS Selectors in Selenium Demystified

Happy Reading!!

TestNG - Passing List & Hash as Single parameter

In continuation with my previous post, Now I tried for Passing List & Hash as Single parameter. Below is the example code

Below is the working example code

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.testng.Assert;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.*;
public class Test1 {
@DataProvider(name = "Passing Three Parameters")
 public Object[][] createDataforTest1()
{
  System.out.println("Start Data Provider: Test1");
  Map<String, String> TestData1 = new HashMap<String, String>();
  TestData1.put("Onee", "One");
  TestData1.put("Twoo", "Two");
  Map<String, String> TestData2 = new HashMap<String, String>();
  TestData2.put("One", "One Expected");
  TestData2.put("Two", "Two Expected");
  Object[][] retkeyword = { { "One", TestData1, TestData2 },
    { "Two", TestData1, TestData2 } };
  System.out.println("End Data Provider: Test1");
  return (retkeyword);
 }
@DataProvider(name = "Passing List & Hash as Single parameter")
public Object[][] createDataforTest2()
{
  System.out.println("Start Data Provider: Test2");
  HashMap<String, List<String>> TestData3 = new HashMap<String, List<String>>();
  List<String> ls = new ArrayList<String>();
  ls.add("one expected");
  ls.add("Three expected");
  ls.add("two expected");
  ls.add("four expected");
  TestData3.put("One", ls);
  TestData3.put("Two", ls);
  Object[][] retkeyword = { { "One", TestData3 }, { "Two", TestData3 } };
  System.out.println("End Data Provider: Test2");
  return (retkeyword);
 }
 @Test(dataProvider = "Passing List & Hash as Single parameter")
 public void verifyData3(String keyword,HashMap<String, ArrayList<String>> hm)
{
  System.out.println("Start Test : Passing List & Hash as Single parameters");
  System.out.println("Keyword :" + keyword);

  List<String> ls = hm.get(keyword);
  Iterator it = ls.iterator();
while (it.hasNext())
{
   String value = (String) it.next();
   System.out.println("Value :" + value);
  }
  System.out.println("Keyword present in List " + ls.contains(keyword));
  System.out.println("End Test");
 }
@Test(dataProvider = "Passing Three Parameters")
public void verifyData3(String keyword, HashMap hM1, HashMap hM2)
{
  System.out.println("Start Test : Passing Three Parameters");
  System.out.println("Keyword :" + keyword);
  System.out.println("HashMap 1 Value is :" + hM1.get(keyword)
    + " Second HashMap value is :" + hM2.get(keyword));
  System.out.println("End Test");
 }
}
Hope it Helps!!

December 18, 2010

TestNG - Passing Multiple parameters in DataProviders

I am learning TestNG. This blogpost is for passing multiple parameters for Test method using data providers. To get started with TestNG please refer link.

Below is code snippet I tried. This is working code.

Dataproviders in TestNG test

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.testng.Assert;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.*;
public class test {
@DataProvider(name = "Pass Single Parameter")
public Object[][] createData() {

    Object[][] retkeyword={{"One"},
                        {"Two"},
                        {"Three"}};
    return(retkeyword);
}

@DataProvider(name = "Passing Two parameters")
public Object[][] createDataforTest2() {
 List<String> ls=new ArrayList<String>();
 ls.add("one expected");
    ls.add("Three expected");
    ls.add("two expected");
    ls.add("four expected");
    Object[][] retkeyword={{"One", ls},
                        {"Two", ls},
                        {"Three", ls}};
    return(retkeyword);
}

@DataProvider(name = "Passing Three parameters")
public Object[][] createDataforTest3() {
    HashMap hm = new HashMap();
    hm.put("One", "One Test");
    hm.put("Two", "Two Test");
    hm.put("Three", "Three Test");

 List<String> ls=new ArrayList<String>();
 ls.add("one expected");
    ls.add("Three expected");
    ls.add("two expected");
    ls.add("four expected");
    Object[][] retkeyword={{"One", ls, hm},
                        {"Two", ls, hm},
                        {"Three", ls, hm}};
    return(retkeyword);
}

@Test(dataProvider = "Passing Three parameters")
public void verifyData3(String keyword, ArrayList<String> ls, HashMap hm)
{
   System.out.println("Passing 3 parameters to Test");
   System.out.println("Start Test");
   System.out.println("Value :"+keyword);
      Iterator it=ls.iterator();
      while(it.hasNext())
      {
        String value=(String)it.next();
        System.out.println("Value :"+value +" Hash Map is "+ hm.get(keyword));
      }
      System.out.println("End Test");
}

@Test(dataProvider = "Pass Single Parameter")
public void verifyData1(String keyword)
{
   System.out.println("Passing Single parameter to Test");
   System.out.println("Start Test");
      System.out.println("Value :"+keyword);
      System.out.println("End Test");
}

@Test(dataProvider = "Passing Two parameters")
public void verifyData2(String keyword, ArrayList<String> ls )
{
   System.out.println("Passing Two parameter to Test");
   System.out.println("Start Test");
      System.out.println("Value :"+keyword);
      Iterator it=ls.iterator();
      while(it.hasNext())
      {
        String value=(String)it.next();
        System.out.println("Value :"+value);
      }
      System.out.println("End Test");
}
}

Hope it helps!!

December 13, 2010

Visibility aspect @ Work

I have seen instances where being visible helped people grow but I personally don’t believe in ‘Being centre of Attraction or Acting smart in front of senior management’ is a way to promote you.

People must be evaluated based on their achievements not based on their visibility. But sometimes it’s the other way. Skills will help you work anywhere. Visibility helps you sustain your current role.

Visibility by itself is a talent. Ability to convince and create perception is a talent. It’s the responsibility of the manager to differentiate visibility vs ability. People who contribute to the organization are as important as people who represent the organization. End of you day you need to be satisfied with your work. This alone can give you satisfaction.

”A good conscience is a soft pillow”.....

December 10, 2010

Process Failures - Reality Check

For every role, job profile - Dev, Test, Support there would be areas of improvements / continuous improvements / Removing Muda (Waste) / Kaizen ....

From Customer perspective - Looking for working product @ the earliest time
From IT Project Team perspective - Meet the Requirement, Beat the Schedule, Manage the Cost
From Development Perspective - Functionality agreed and Signed off to Freeze Design
From Test Perspective - Access functionality changes in every iteration and test it

Where is the Noise
  • Everything looks fine with the first draft version of functional spec.During Design when it changes this has ripple effect in design, testing, schedule and timeline.
  • Not Every Business Team is IT Savvy. Not every IT team understands the project business value
  • Communication does to flow across the team consistently. Keeping whole in same page requires effective communication
What Actually Happens
  • Developer spending late nights @ work to make code release
  • Test Team testing during weekends/working beyond office hours to meet the schedule  
  • Work + Work - Life, Work Life Balance Issues
Reality of Process Implementation
  • Process is a guideline not the best practice, Getting better at things we do helps us improve ourselves and Improve working environment
  • I really doubt every developer aware of best coding practice / Every tester aware of best testing practices
  • I have a team of 10 Developers. How do we ensure everyone develops the same quality of code
  • Enforce-Use tools to implement Code Checks - This is a reactive way in my perspective
  • If I know this is the best practice to handle this problem. Memory use, Better Logic. Make everyone understand rationale behind usage of particular approach.
  • Knowing facts is not sufficient. You also need to know Why?
  • Have this best practices shared in Email Communications, Employee Kits, Notes, Posters
  • Subscribe to a newsletter for a subject and learn it thoroughly
  • Best practices once developed never get communicated (marketing) - selling part of it is often poor. A best practice should justify why it is a best practice, how it evolved, Future reading....
  • Knowledge Sharing Sessions - Reading Subject matter experts blog - Blogging your learnings are good ways of learning and sharing....
Sometimes it is worth to re-learn!!

Happy Reading!!

TestNG Automation Tricks

Very Good and useful links on TestNG based data-driven Automation. Please check on earlier posts labelled selenium to get started with Selenium and TestNG.

Stupid TestNG Tricks - Reading Input from File
Parallel Testing with TestNG DataProviders
DataProvider for Object as Parameter
Using TestNG to launch your tests (and the Selenium server)
TestNG GTAC Presentation
Setting up a test project with Selenium, TestNG and Maven
Difference between Junit and TestNG
Everytime when you know more about something you already know. It only means you ( I ) have to learn better....

Happy Reading!!

December 04, 2010

Web Service Testing

Yes, Learning basics once again. Basics of Web Services, How it Works. Testing has been fairly easy using Web Service Studio Tool.
Web Service - What is it
  • Web Services is all about XML
  • Enables this communication by using open protocols and standards XML, SOAP and WSDL
  • Structure of the messages is described using XML Schema (XSD)
Why Web Services
  • Platform-independent - The use of open protocols enables Web services to be platform independent
  • Secure - Enable SSL, Certificates
Technology
  • WSDL (Web Services Description Language) - WSDL is a document that describes a Web service and also tells you how to access and use its methods.
  • UDDI - Universal Description, Discovery and Integration - Organizations register their Web services in a global directory so clients can find them
  • SOAP - Simple Object Access Protocol. Messaging protocol. SOAP is a simple XML-based protocol to let applications exchange information over HTTP.
How it works
A very good walkthrough is provided in link. Client sends Serialized SOAP Request. This is Deserialized by the Server. The response is again Serialized and passed to the client in SOAP Response in serialized format. Deserialization happens at Client again.

Performance 
Typically there would be multiple consumers who can consume this service, scalability and performance is very important for web service

Web Services Testing
Fairly Simple. Provide the wsdl URL in Web Service Studio Tool. Methods would be listed. Easy Walkthrough and tool download in link
Web service Studio 2.0 by Sowmy Srinivasan - Link
More Tools Read
More Reads

Happy Learning!!!