Tuesday, June 20, 2017

Part-2 COLLECTIONS :ARRAY LIST

So in the above example , we have created an array list object arrobj .
To add elements in the arrobj , we have called the add method on arrobj.
After printing the arrobj, we get the desired result i.e values are added in the arrobj.


But the question is how add(object) method adds the value in ArrayList ?

Answer :
There are 2 overloaded methods add (methods in array list):

1. add(object) : adds object to the end of the List.
2. add(int index, object) : inserts the specified object to the specified position in the list

ArrayList internally uses array object to add or store the elements .In other words Array List is backed by Array data-structure. The array of Array List is re sizable or dynamic.

There are 2 ways to create an ArrayList object :-
a. Create an empty list with initial capacity:
List arrlistobj= new ArrayList();
When you create an ArrayList this way , the default constructor of the ArrayList class is invoked .
It will create internally an array of object with default size to 10.

b. List arrlistobj = new ArrayList(20);
When we create an arrayList this way , the array list will invoke the constructor with the integer argument . It will create internally an array of object . The size of the object[] will be equal to the argument passed in the constructor . Thus when above line of code is execute it creates an object[] of capacity as 20.
Thus ArrayList constructor will create an empty list . Their initial capacity can be 10 or equal to the value of the argument passed in the constructor.

List arrlistobj= new ArraList(Collection c);
The above ArrayList constructor will create a non empty list containing elements of the collection passed in the constructor.























PART-1 : INTRODUCTION TO COLLECTIONS

Collections- Need of Collection Framework 

I want to represent one value by one variable , 2 values with 2 variable etc , we will have no problem .
int x=10;
int y=20;
int z=30;

Now if we want to represent huge values, declaring 10,000 variable is worst type of programming practice . Readability of the code is going to get down.
To overcome this problem we should go for next level that is Arrays.

Normally, array is a collection of similar type of elements that have contiguous memory location.

------------------------------------------------------------------------------------------------------------
Overview of Array:-
+Java array is an object the contains elements of similar data type. It is a data structure where we store similar elements. We can store only fixed set of elements in a java array.
Array in java is index based, first element of the array is stored at 0 index.
java array

  1. int a[]=new int[5];//declaration and instantiation  
  2. a[0]=10;//initialization  
  3. a[1]=20;  
  4. a[2]=70;  
  5. a[3]=40;  
  6. a[4]=50;  



Syntax with values given (variable/field initialization):



int[] num = {1,2,3,4,5};



Multidimensional array

Declaration

int[][] num = new int[5][2];

Initialization

 num[0][0]=1;
 num[0][1]=2;
 num[1][0]=1;
 num[1][1]=2;
 num[2][0]=1;
 num[2][1]=2;
 num[3][0]=1;
 num[3][1]=2;
 num[4][0]=1;
 num[4][1]=2;

Or

 int[][] num={ {1,2}, {1,2}, {1,2}, {1,2}, {1,2} }

Advantage of Java Array

  • Code Optimization: It makes the code optimized, we can retrieve or sort the data easily.
  • Random access: We can get any data located at any index position.

Disadvantage of Java Array

  • Size Limit: We can store only fixed size of elements in the array. It doesn't grow its size at run time. To solve this problem, collection framework is used in java.
------------------------------------------------------------------------------------------------------------

Arrays :

Student[] s=new Student [100000];
Biggest advantage of array is we can represent huge number of values by using a single variable , so that readability of the code is going to be improved.

Problem with arrays is that : 
1. Arrays are fixed in size , once we declare an array size of the array will be fixed .We cannot  increase or decrease size of  an array.
Suppose i have started java training and i have got 10,000 applicants who are interested in learning java . I have arranged 10,000 chairs for each student to sit.
At run time only 200 students came . What will happen to the remaining chairs , it will become waste.
Now based on the previous experience i started a new batch and i though around 200 students is gonna come . So i have arranged only 200 chairs . Now 10,000 students came at run time. Will i be in a position to provide support to remaining students . Answer will be "NO".
Same case happens for Arrays too.
So for arrays concept compulsory we have to know the size in advance which may or may not be possible at run time.

2. Arrays can hold only homogeneous data elements . Suppose we have created a student array:
Student [] s = new Student[10000];
Here we can represent only student type of information .
s[0]= new Student(); ---valid
s[1]= new Customer();----invalid

compile time error : expecting student type object but will get customer type object . So incompatible type error we are going to get.
Incompatible type found : required student but found Customer.


So what will be the solution to this problem :
We can solve this problem by using object type array.
Object []a= new Object[10000];
a[0]= new Student ();----valid
a[1]= new Customer();----valid


Because student and customer are of object type , so happily we can go for Object type arrays as both Student and Customer are of type Object.


3. Arrays concept is not implemented based on some standard data structure , but every collection class is implemented based on some standard data structure. That is why underlying data structure or ready made method support we can't expect from arrays.
For every requirement we have to compulsory write the code.

Suppose i want to inset elements into an array and all elements must be inserted in some sorting order , then who is responsible to write the sorting logic ?
The programmer is responsible to write.
Check if an element is there or not : We do not have ready made method support for it.
So it will be the programmer responsibility to write down the sorting logic for it.
So ready made method support is not available for each and every requirement . Compulsory we have to write down the code.

If we want to enter elements based on some sorting order , better to go for tree set .
If we want to search a particular element is there or not , collection contains a method called contains .
So for every requirement ready made method support , you can expect in collection but in Arrays you can't.




So we can say that collections concept provide solutions for all limitations of an Array.


Which concept is recommended to use : Arrays or Collections?

If you know size in advance , highly recommended to go for Arrays concept. Collections are growable in nature that is based on our requirement we can increase or decrease the size. This growable nature we are not going to get free of cost . What are are paying or convincing is : PERFORMANCE.

example :
Suppose we have an array of size 10.
If 11th element comes , array will not be able to provide support.
Assume ArrayList:
ArrayList of 10 element :


If 11th element comes , ArrayList will not be in a position to provide support.Do not feel that cell is going to get automatically created and 11th element is going to get stored.
What happens internally is once ArrayList reaches its max capacity a bigger array list object will be created internally.
ArrayList uses an array to store elements . Arrays have a fixed size . The array that arrayList uses has to have a default size, obviously. 10 is a probably a more or less an arbitrary number for the default number of elements.
When you create a new ArrayList with nothing in it , then ArrayList will have made an array of 10 elements behind the scenes . Of course those 10 elements are all null.

Each time the array is full, ArrayList creates a new larger array and copies the elements from the old array to the new array. You don't want this to happen every time you add an element to the ArrayList.
Copying the array takes time especially if the array size is larger .So array list does it in the steps of 10 or so.
(If you want to know how it works , look for the files src.zip in your JDK instala\lation directory .pen it and look up the sorce code for java.util ArrayList).






Sunday, January 24, 2016

INTRODUCTION TO AUTOMATION TESTING

What is Selenium ?
Selenium automates browsers. 
Selenium is an open source functional automation tool.

We have testing which is divided into two streams:
1. One is functional and
2. Another is Non-Functional.

‘Functional Testing’, is the type of testing done against the business requirements of application. It is a black box type of testing.

The ‘Non-Functional’, Testing is the type of testing done against the non-functional requirements.

The testing of software attributes which are not related to any specific function or user action like performance, scalibility, security or behavior of application under certain constraints.
In manual testing our main activity is to write test cases and these test cases will be executed
manually by some resource like test engineer.

When comes to Automation , all the manual test cases will be converted to test scripts with the help
of some tools like Selenium, QTP ,Sikuli etc.

The process of converting manual test cases to test scripts with the help of some automation tools  is called as “Automation”.  

So I can use any of the automation tools to convert the test cases to the test scripts.



So you may have a doubt  , Sir in manual testing we are writing the test cases and executing the test
Cases  ,in test scripts we are doing the same activity the same test cases converted to test scripts
and executing it .So what is the use: The main advantage is we can save time.


Now another questions arises : How much time??
Suppose i am having 500 test cases , per day how many test cases we can execute??
50/60 test cases can be executed manually per day. So all the test cases can be executed in 9-10 days. Time . Suppose your lead says that I cannot allocate you 10 days time in every sprint to execute the test cases, you have to complete in 4-5 days  then  what will you do?
If we are executing it in 4-5 days then there can be a challenge to the quality.
So what’s the solution ,

There can be two solutions :
1. Add few more resource which can help you to execute tests in the time frame
2. Or else automation.

Remember that it’s not possible to automate 100% of the application, majority can be automated but few cannot be

For instance, if the application’s user interface will change considerably in the near future, then any automation might need to be rewritten anyway. Also, sometimes there simply is not enough time to build test automation. For the short term, manual testing may be more effective. If an application has a very tight deadline, there is currently no test automation available, and it’s imperative that the testing get done within that time frame, then manual testing is the best solution.
So here we have 500 test cases out of which 400 can be automated and rest cannot be , so in 2 days time with manual efforts we can achieve it.

But how much time will be required to test the remaining 400 cases ? This question is still not being answered?

So my answer is “0” .It will not require any manual QA intervention when the test scripts are running. We can assign a separate machine and just via a click the rest can be achieved or the scheduler can automatically do the rest of the job.
We will be getting the detailed report of the test run i.e. number of test cases passed/failed/skipped etc.  along with the snap shot of the failures.
Once the scripts are stable ,we don’t execute the scripts in regular timings ,my plan is to go home .So before leaving i will run all the test cases. Next morning when i come to office everything will be executed along with screen shots and results.
So here i am not investing any of my time to execute the test cases.

So the main advantage is we can save time.

Time is directly proposal to cost and we can maintain accuracy also. Same scripts can be executed again and again with quality with accuracy.

Why Selenium why not any other automation tool like QTP?

1. Open Source
2. Supports multiple languages(java,perl,php, pyton,ruby etc)
3. Browsers: FF,Chrome ,IE,Safari and Opera
4. Supports the OS like windows,mac and linux.
5. It’s for web applications and mobile applications also.
(Does not support desktop applications)

Suppose i have a web application say gmail which i want to automate ,in that web application we
have some desktop components say uploading a file .is it possible : My answer is “Yes”  we have a tool called a sikuli.I will use this tool to use as an adone to selenium to handle desktop components. “AutoIt” is also there .Some companies are using “Sikuli” and some are using “autoIT”. to handle desktop components.
6. Its flexible and extendable-reusable.

QTP features when compared to Selenium:

1. Not an open source-Commercial as well as costly
2. Language-VP script (somewhat Java Script)
3. Browser: Main compatible with ie (use ff als0)
4. OS : Only windows
5. For Desktop, mobile and web
6. Flexible and extendable.

Selenium is more flexible and extendable.

How can Selenium be more flexible when compared to QTP ?

Compare java with Vb script : which one is more flexible and extendable. Its java ,because it’s a proved language ,since 20 years we are using and still its no-1.That’s the reason companies are using Selenium.


About Me

My photo
Pune, Maharastra, India
You can reach me out at : jimmiamrit@gmail.com