June 09, 2017

A JNI error has occurred, please check your installation and try again

I was creating JAR from eclipse Project --> Export --> JAR file
Executing it via simple command "java -jar example.jar" following error occurs

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/security/pki/OracleSecretStoreException

After debugging and analyzing I found that JAR was runnable. To resolve this while creating JAR from eclipse choose following options,

creating JAR from eclipse Project --> Export --> Runnable JAR file  and then execute by "java -jar example.jar"

May 26, 2017

Jmeter testing with mutiple urls for different tenants

Use the JMeter StringFromFile function.

A very simple example: read from a file c:/jmeter/urls.csv into a jmeter variable hostname.
Add a User Defined Variables config element to your test plan:
  • name: hostname
  • value: ${_StringFromFilec:/jmeter/urls.csv ,hostname,,)}
Then use the variable as ${hostname} in your requests.

or if above doesn't work, you can directly place following string in each HTTP Request under Server Name or IP

${_StringFromFilec:/jmeter/urls.csv ,hostname,,)}

It will read next line each time it is called and all threads will share same instance

Another Ideal way

ThreadGroup - 10 thread 1 loop
Add a beanshell with following code:
vars.put("hostname","${_StringFromFilec:/jmeter/urls.csv ,hostname,,)}"); return "BeanShell extract cvs";

And a LoopController with value 10, and add all samplers under it.

Now you have 10 thread running on different URL's and looping 10 times

May 04, 2017

Jmeter useful variables

Defining useful variables while scripting Jmeter

_${__threadNum()} /  ${threadNum()}   : This is used to print the thread number while used in body.

_${__time(dd-mmm-yyyy_HHmmss)} / ${time(dd-mmm-yyyy_HHmmss)} : This is used to print current date together with time

_${__UUID} / ${UUID} : Universally Unique IDentifier (UUID).This is used to print unique number.

December 16, 2016

Java array declarations and instantiations

  • int[ ] a[ ] = new int [5][4] ;

       This will create an array of length 5. Each element of this array will be an array of 4 ints.

  • int a[ ][ ] = new int [5][4] ;

       This will create an array of length 5. Each element of this array will be an array of 4 ints.

  • int a[ ][ ] = new int [ ][4] ;

      The statement int[ ][4] will not compile, because the dimensions must be created
      from left to right.

  • int[ ] a[ ] = new int[4][ ] ;

        This will create an array of length 4. Each element of this array will be null. But you can assign           an array of ints of any length to any of the elements. For example:
        a[0] = new int[10];//valid
        a[1] = new int[4];//valid
       a[2] = new int[]; //invalid because you must specify the length
       a[3] = new Object[] //invalid because a[3] can only refer to an array of ints.
       This shows that while creating a one dimensional array, the length must be specified but while creating multidimensional arrays, the length of the last dimension can be left unspecified. Further, the length of multiple higher dimensions after the first one can also be left unspecified if none of the
dimensions are specified after it. So for example,
a[][][][] = new int[4][3][3][5]; is same as a[][][][] = new
int[4][][][]; (Note that the first dimension must be specified.)
Thus, multidimensional arrays do not have to be symmetrical.

  • int[ ][ ] a = new int[5][4] ;

       This will create an array of length 5. Each element of this array will be an array of 4 ints.
The [] notation can be placed both before and after the variable name in an array
int[] ia, ba; // here ia and ba both are int arrays.
int ia[], ba; //here only ia is int array and ba is an int.
Multidimensional arrays are created by creating arrays that can contain references to
other arrays .

Java superclass reference to subclass object

Given Example,

class SuperClass{
    int intVar = 0;
    void method(){
        //in super class
class SubClass extends SuperClass{
    int intVar = 2;
    void method(){
        //in sub class

SuperClass obj = new SubClass();

int val = obj.intVar;// this is taken from SuperClass as variables are decided on reference basis, if both superclass and subclass contain the same variable it is called shadowing

obj.method();// it is taken from the SubClass as it is method overriding and is decided at runtime based on the object not the reference
However there is one exception, if the method is Static in Superclass, then its decided on base of reference.

In normal scenarios, reference can access variables & methods of both Superclass and Subclass.

December 08, 2016

Difference between Array and ArrayList in Java

Resizable :   Array is static in size that is fixed length data structure, One can not change the length after creating the Array object.
ArrayList is dynamic in size . Each ArrayList object  has instance variable capacity which indicates the size of the ArrayList. As elements are added to an ArrayList its capacity grows automatically.

Performance : Performance of Array and ArrayList depends on the operation you are performing :

resize() opertation : Automatic resize of ArrayList will slow down the performance as it will use temporary array to copy elements from the old array to new array.
ArrayList is internally backed by Array during resizing  as it calls the native implemented method System.arrayCopy(src,srcPos,dest,destPos,length) .

add() or get() operation : adding an element or retrieving an element from the array or arraylist object has almost same  performance , as for ArrayList object these operations  run in constant time.

Primitives :  ArrayList can not contains primitive data types (like int , float , double) it can only contains Object while Array can contain both primitive data types as well as objects.
One get a misconception that we can store primitives(int,float,double) in ArrayList , but it is not true 

Suppose we have ArrayList object ,

ArrayList<int> list1 = new ArrayList<int>();

 JVM through Autoboxing(converting primitives to equivalent objects internally) ensures that only objects are added to the arraylist object.

thus , above step internally works like this :

ArrayList<Integer> list1 = new ArrayList<Integer>();

Iterating the values : We can use iterator  to iterate through ArrayList.
 The iterators returned  by the ArrayList class's iterator and list iterator 
method are fail-fast.We can use for loop or for each loop to iterate through array .  

Type-Safety :  In  Java , one can ensure Type Safety through Generics.
 while Array is a homogeneous data structure , thus it will contain objects of specific 
class or primitives of specific  data type. In array if one try to store
 the different data type other than the specified while creating the 
array object , ArrayStoreException is thrown
 String temp[] =  new String[2];  // creates a string array of size 2
temp[0] = new Integer(12); // throws ArrayStoreException, trying to add Integer object in String[] 
Length :  Length
 of the ArrayList is provided by the size() method while Each array 
object has the length variable which returns the length of the array.
 Integer arrayobject[] = new Integer[3];
arraylength= arrayobject.length   ;  //uses arrayobject length variable 

ArrayList  arraylistobject = new ArrayList();
arraylistobject.size();   //uses arraylistobject size method
Adding elements : We can 
insert elements into the arraylist object using the add() method while  
in array we insert elements using the assignment operator.
import java.util.ArrayList;
import java.util.Iterator;

public class ArrayArrayListExample {
    public static void main(String[] args) { 
        // ArrayList Example   
        ArrayList<String> arrlistobj = new ArrayList<String>();
        arrlistobj.add("Alive is awesome");
        arrlistobj.add("Love yourself");
        Iterator it = arrlistobj.iterator();
        System.out.print("ArrayList object output :");  
          System.out.print(it.next() + " ");
        // Array Example
        String[] arrayobj = new String[3];
        arrayobj[0]= "Love yourself";  
        arrayobj[1]= "Alive is awesome";
        arrayobj[2]= "Be in Present"; 
        System.out.print("Array object output :");
        for(int i=0; i < arrayobj.length ;i++)
        System.out.print(arrayobj[i] + " ");   

Output :  ArrayList object output :{ Alive is awesome , Love yourself }

                 Array object output :{ Love yourself , Alive is awesome, Be in present}

December 07, 2016

What is the difference between == vs equals() in Java?

There are some small differences depending whether you are talking about "primitives" or "Object Types"; the same can be said if you are talking about "static" or "non-static" members; you can also mix all the above...
Here is an example (you can run it):

public final class MyEqualityTest
    public static void main( String args[] )
        String s1 = new String( "Test" );
        String s2 = new String( "Test" );

        System.out.println( "\n1 - PRIMITIVES ");
        System.out.println( s1 == s2 ); // false
        System.out.println( s1.equals( s2 )); // true

        A a1 = new A();
        A a2 = new A();

        System.out.println( "\n2 - OBJECT TYPES / STATIC VARIABLE" );
        System.out.println( a1 == a2 ); // false
        System.out.println( a1.s == a2.s ); // true
        System.out.println( a1.s.equals( a2.s ) ); // true

        B b1 = new B();
        B b2 = new B();

        System.out.println( "\n3 - OBJECT TYPES / NON-STATIC VARIABLE" );
        System.out.println( b1 == b2 ); // false
        System.out.println( b1.getS() == b2.getS() ); // false
        System.out.println( b1.getS().equals( b2.getS() ) ); // true

final class A
    // static
    public static String s;
        this.s = new String( "aTest" );

final class B
    private String s;
        this.s = new String( "aTest" );
    public String getS()
        return s;

November 10, 2016

Source Not Found .jar has no source attachment

Source Not Found
The JAR file selenium-server-standalone-3.0.1.jar has no source attachment
You can attach the source by clicking Attach Source below.

This in my case was impact of Chrome driver version. I updated it to latest version and scripts starts running smoothly.

November 03, 2016

Benefits of Automation

List of benefits of automation:

1.     Test execution cost is reduced to zero
2.     Test report creation cost is reduced to zero
3.     Reusable: Tests can be re-used on different versions of the software.
4.     Reliable: Tests perform precisely the same operation each time they are run thereby eliminating human error.
5.     Better Quality: More tests can run with few resources in very less time, which ensures the quality of software better.
6.     Test Coverage: Testers can build test suites that covers wider range of application on various versions.
7.     Resources: Reduction in cost of resources with expanding application.
8.     Faster:  Significant reduction in test cycle time

9.     Major component of Continuous Integration(CI) and DevOps

October 17, 2016

Concepts of Cucumber BDD

Cucumber is successfully implemented only if two scenarios are followed religiously

1. Collaboration: Collaboration between business analysts, programmers and testers. In this case all 3 entities will sit together and create Cucumber scenarios
2. Outside-in: Programmers start with functionality that is closest to the user(eg. user interface) and then move to business logic of code, followed by test case execution

Cucumber scenarios should be written even before writing any piece of code, as rightly said " Your cucumber feature should drive your implementation, not reflect it."

In the nut shell, regression suite are the by product of BDD which came out at the end of cycle.

The BDD Given, When, Then syntax is designed to be intuitive. Consider the syntax elements:

    Given provides context for the test scenario about to be executed, such as the point in your application that the test occurs as well as any prerequisite data.
    When specifies the set of actions that triggers the test, such as user or subsystem actions.
    Then specifies the expected result of the test.