MainMenu

Home Java Overview Maven Tutorials

Tuesday 29 January 2019

Get Number of rows and column in html table

How to get Number of rows & column in html table



Hello Friends,
In this article , i will describe how to get number of rows and column in html table :-

NameAgeGenderCity
Chandan30MaleDelhi
tina29FemaleAlaska
Martin31MaleGoa
merry25FemaleIndianapolis
jim35MaleAustria
Nisha28FemaleMumbai


Video


Here is the code to get the Number of rows and column from the table

public class Tablequiz
{
WebDriver driver;
@BeforeTest
public void g() throws InterruptedException, InvalidFormatException, IOException
{
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\ChromeDriver\\new\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
Thread.sleep(3000);
driver.navigate().to("http://www.way2testing.com/2019/01/get-number-of-rows-and-column-in-html.html");
}
@Test
public void h()
{
int rownum = driver.findElements(By.xpath("//*[@id='csc']/tbody/tr[*]")).size();
System.out.println("Total rows are :-" +rownum);
int columnnum = driver.findElements(By.xpath("//*[@id='csc']/tbody/tr[2]/td")).size();
System.out.println("Total columns are :-" +columnnum);
String rowtext = driver.findElement(By.xpath("//*[@id='csc']/tbody/tr[2]/td[1]")).getText();
System.out.println("Row Text is :" +rowtext);
}
}

OUTPUT :-
Total rows are :7
Total columns are :4
Row Text is :Chandan

Friday 11 January 2019

Collection in Java

A brief intro of Java Collections



Hello Friends,
In this article , i will describe about collection in Java Language :-

COLLETION IN JAVA
Java collections refer to a single unit of objects.
You can perform all operations on data such as searching, sorting, insertion, manipulation, deletion, etc. by Java collections.
The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.
Java Collection framework provides many interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet).
What is a Java Collection Framework?
A Java collection framework provides an architecture to store and manipulate a group of objects. A Java collection framework includes the following:
Interfaces
Classes
Algorithm
Let’s learn about them in detail:
Interfaces: Interface in Java refers to the abstract data types. They allow Java collections to be manipulated independently from the details of their representation. Also, they form a hierarchy in object-oriented programming languages.
Classes: Classes in Java are the implementation of the collection interface. It basically refers to the data structures that are used again and again.
Algorithm: Algorithm refers to the methods which are used to perform operations such as searching and sorting, on objects that implement collection interfaces. Algorithms are polymorphic in nature as the same method can be used to take many forms or you can say perform different implementations of the Java collection interface.
The Java collection framework provides the developers to access prepackaged data structures as well as algorithms to manipulate data. Next, let us move to the Java collections framework hierarchy and see where these interfaces and classes resides.

Java Collections : Interface
Iterator interface : Iterator is an interface that iterates the elements. It is used to traverse the list and modify the elements. Iterator interface has three methods which are mentioned below:
public boolean hasNext() – This method returns true if the iterator has more elements.
public object next() – It returns the element and moves the cursor pointer to the next element.
public void remove() – This method removes the last elements returned by the iterator.

There are three components that extend the collection interface i.e List, Queue and Sets. Let’s learn about them in detail:
Java collections: List A List is an ordered Collection of elements which may contain duplicates. It is an interface that extends the Collection interface. Lists are further classified into the following:
ArrayList
LinkedList
Vectors
Let’s go into detail on each one of them:
Array list: ArrayList is the implementation of List Interface where the elements can be dynamically added or removed from the list. Also, the size of the list is increased dynamically if the elements are added more than the initial size.
ArrayList object = new ArrayList ();

Linked List: Linked List is a sequence of links which contains items. Each link contains a connection to another link.
Syntax: Linkedlist object = new Linkedlist();

Java Linked List class uses two types of Linked list to store the elements:
Singly Linked List
Doubly Linked List
Singly Linked List: In a singly Linked list each node in this list stores the data of the node and a pointer or reference to the next node in the list. Refer to the below image to get a better understanding of single Linked list.

Doubly Linked List: In a doubly Linked list, it has two references, one to the next node and another to previous node. You can refer to the below image to get a better understanding of doubly linked list.

Vector:- Vector uses a dynamic array to store the data elements. It is similar to ArrayList. However, It is synchronized and contains many methods that are not the part of Collection framework.

Stack :- The stack is the subclass of Vector. It implements the last-in-first-out data structure, i.e., Stack. The stack contains all of the methods of Vector class and also provides its methods like boolean push(), boolean peek(), boolean push(object o), which defines its properties.



A Collection is a group of individual objects represented as a single unit.
Java provides Collection Framework which defines several classes and interfaces to represent a group of objects as a single unit.

The Collection interface (java.util.Collection) and Map interface (java.util.Map)

are the two main “root” interfaces of Java collection classes.

1). List Interface

Child Interface of collection interface is List. It have a list type data structure in which we can store the ordered collection of objects also it can have duplicate values.


List alist= new ArrayList();
List llist = new LinkedList();
List vlist = new Vector();
List slist = new Stack();


2).Java Collections – Set
A Set is a Collection that cannot contain duplicate elements. There are three main implementations of Set interface:
HashSet, TreeSet, and LinkedHashSet. HashSet, which stores its elements in a hash table, is the best-performing
implementation; however it makes no guarantees concerning the order of iteration. TreeSet, which stores its elements
in a red-black tree, orders its elements based on their values; it is substantially slower than HashSet. LinkedHashSet,
which is implemented as a hash table with a linked list running through it, orders its elements based on the order in which they
were inserted into the set (insertion-order).

Set hs = new HashSet();
Set ls = new LinkedHashSet();
Set ts = new TreeSet();


3).Queue Interface
Queue interface maintains the first-in-first-out order. It
can be defined as an ordered list that is used to hold the elements which are about to be processed.
There are various classes like PriorityQueue, Deque, and ArrayDeque which implements the Queue interface.

Queue pq = new PriorityQueue();
Queue aq = new ArrayDeque();


ArrayList Example

Array List maintain the insertion order and non-synchronized



public class ConsTest
{
public static void main(String args[]) throws IOException
{
ArrayList alist = new ArrayList();
alist.add("chandan");
alist.add("Singh");
alist.add("chauhan");
alist.add("chandan");
Iterator itr = alist.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}

Output :-
chandan
Singh
chauhan
chandan

LinkedList example
It can store the duplicate elements. It maintains the insertion order and is not synchronized

public class ConsTest
{
public static void main(String args[]) throws IOException
{
LinkedList alist = new LinkedList();
alist.add("chandan");
alist.add("Singh");
alist.add("chauhan");
alist.add("chandan");
Iterator itr = alist.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}

Output :-
chandan
Singh
chauhan
chandan

Example of Vector :-
public class ConsTest
{
public static void main(String args[]) throws IOException
{
Vector alist = new Vector();
alist.add("chandan");
alist.add("Singh");
alist.add("chauhan");
alist.add("chandan");
Iterator itr = alist.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}

Output :-
chandan
Singh
chauhan
chandan

Example of Stack :-
public class ConsTest
{
public static void main(String args[]) throws IOException
{
Stack stk = new Stack();
stk.push("chandan");
stk.push("Singh");
stk.push("chauhan");
stk.push("chandan");
stk.push("Singh");
stk.pop();
Iterator itr = stk.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}

Output :-
chandan
Singh
chauhan
chandan



PriorityQueue
The PriorityQueue class implements the Queue interface. It holds the elements or objects which are to be processed by their priorities. PriorityQueue doesn't allow null values to be stored in the queue.

package com.lang.beginner;
import java.io.*;
import java.util.ArrayList;
import java.util.*;

public class ConsTest
{
public static void main(String args[])
{
PriorityQueue queue = new PriorityQueue();
queue.add("ChandanSingh");
queue.add("Adhiraaj");
queue.add("Amit");
queue.add("Anngraaj");
System.out.println(queue.element());
System.out.println(queue.peek());
Iterator itr = queue.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
queue.remove();
queue.poll();
System.out.println("After removing elements");
Iterator itr2 = queue.iterator();
while(itr2.hasNext())
{
System.out.println(itr2.next());
}
}
}

Output :-
Adhiraaj
Adhiraaj
Adhiraaj
Anngraaj
Amit
ChandanSingh After removing elements
Anngraaj
ChandanSingh

HashSet :- HashSet class implements Set Interface. It represents the collection that uses a hash table for storage. Hashing is used to store the elements in the HashSet. It contains unique items

public class ConsTest
{
public static void main(String args[])
{
HashSet hset = new HashSet();
hset.add("chandan");
hset.add("chandan");
hset.add(null);
hset.add("Singh");
Iterator itr = hset.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}
Output :-
null
chandan
Singh

LinkedHashSet
LinkedHashSet class represents the LinkedList implementation of Set Interface. It extends the HashSet class and implements Set interface. Like HashSet, It also contains unique elements. It maintains the insertion order and permits null elements.

public class ConsTest
{
public static void main(String args[])
{
LinkedHashSet hset = new LinkedHashSet();
hset.add("chandan");
hset.add("chandan");
hset.add(null);
hset.add("Singh");
Iterator itr = hset.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}
Output :-
chandan
null
Singh



TreeSet :-
Java TreeSet class implements the Set interface that uses a tree for storage. Like HashSet, TreeSet also contains unique elements. However, the access and retrieval time of TreeSet is quite fast. The elements in TreeSet stored in ascending order.

public class ConsTest
{
public static void main(String args[])
{
TreeSet hset = new TreeSet();
hset.add("chandan");
hset.add("chandan");
//hset.add(null);
hset.add("Singh");
Iterator itr = hset.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
}
Output:-
Singh
chandan









Array ListLinked List
Array List is not SynchronizedLinked List is also not synchronized
Array List maintain insertion orderLinked List Also Maintain insertion order
Array List can have multiple null values and multiple duplicate valuesLinked List can also have multiple null values and multiple duplicate values
ArrayList internally uses a dynamic array to store the elementsLinkedList internally uses a doubly linked list to store the elements.
Manipulation with ArrayList is slow because it internally uses an array. If any element is removed from the array, all the other elements are shifted in memoryManipulation with LinkedList is faster than ArrayList because it uses a doubly linked list, so no bit shifting is required in memory.
When read scenarios are more as complare to add and remove scenario, then linked list preferred When Add remove scenarios are more than read scenarios then linked list preferred






HashSetLinkedHashsetTreeset
HashSet uses hashmap for it’s internal storageLinkedHashSet extends HashSet class and implements Set interface and use HashMap internally to store it's elementTreeSet extends AbstractSet and implements NavigableSet interface use TreeMap internally to store it's element
Hashset does not maintains any orderLinked HashSet maintains insertion ordermaintains ascending order of inserted items
HashSet represents a group of unique elementsLinkedHashSet represents a group of unique elementsit also represents a group of unique elements
HashSet can have one null valueLinkedHashSet can also have one null valueNo null values allows in TreeSet
not synchronized and hence not Thread safenot synchronized and hence not Thread safenot synchronized and hence not Thread safe


When To Use?
1). Use HashSet if you don’t want to maintain any order of elements.
2). Use LinkedHashSet if you want to maintain insertion order of elements.
3). Use TreeSet if you want to sort the elements according to some Comparator.

Tuesday 8 January 2019

Introduction of Appium

A brief intro of Appium



Hello Friends,
In this article , i will describe about mobile automation toolAppium :-

Before starting with the appium we should know about Emulator, Simulator & Real Devices

Simulator
A simulator is used in another thinking context, e.g a plane simulator, a car simulator, etc. The simulation will take care only of some aspect of the actual thing, usually those related to how a human being will perceive and control it. The simulator will not perform the functions of the real stuff, and cannot be sustituted to it.

Emulator
An emulator is a device that mimics something close enough so that it can be substituted to the real thing. E.g you want a circuit to work like a ROM (read only memory) circuit, but also wants to adjust the content until it is what you want.

Difference between Emulator & Simulator

1).An emulator can replace the original for real use. A Virtual PC emulates a PC.
A simulator is a model for study and analysis.

2). Simulation = For analysis and study
Emulation = For usage as a substitute



What is Emulator & Simulator in terms of mobile?

Emulator and simulator are virtual devices, A virtual devices is not the real phone but software which gives same functionality as the real phone(Except few functionality like camera).

Android Virtual devices : Emulator
iOS Virtual device : Simulator. Important Points
An Appium is an open source tool for automating mobile application which can be :-
Native
Hybrid
Web

Examples of hybrid apps
For many it is surprising to learn that some of the world’s most popular mobile apps turn out to be…hybrid! This includes: Amazon (for iOS and Android), Evernote (for iOS and Android), Netflix (for iOS and Android).

Appium supports platforms such as :-
Andriod
iOS
Firefox OS

Appium was designed to meet mobile automation needs according to a philosophy outlined by the following four tenets :-
1). You should not have to recompile your app or modify it in any way in order to automate it.
2). You should not be locked into a specific language or framework to write and run your tests.
3). A mobile automation framework should not reinvent the wheel when it comes to automation APIs.
4). A mobile automation framework should be open source, in spirit and practice as wll as in name.

we don't have to recompile or modify anything in our application under test(AUT) to perform automated test with appium, sience appium under the hood uses the vendor specific frameworks meaning :-
Android :- UIAutomator(developed by Android developers)
iOS :- UIAutomation(developed by Apple Inc)

Sience Appium has extended web driver client library, appium also support all the languages which webdriver suports like :-
Java
C#
Ruby
Python
Php etc.


How is Appium Built
1). Appium is basically an HTTP server written in Node.js that creates and handles webdriver sessions.
2). Node.js is a platform build on Chrome's javaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Appium Architecture :-
As appium is an HTTP server, its performs pretty much same as Selenium Webdriver server by :-
1). Receiving request/commands from clent libraries.
2). Executes the command on the target devices/emulators .
3). Responds with an HTTP response.

Hence Appium Works as a client/server architecture.

Client Librares -
Appium Client libraries has different language bindngs like :-
Ruby
Python
Java
JavaScript
PHP
C#
RobotFramework

How Appium Works?
1).As we already know that Appium suports Andriod, iOS and Firefox OS platforms, there should be a mechanism for appium to handle them.
2).Hence Appium handles these platforms using vender-provided frameworks.

The Vendor-provided frameworks for differnt platforms are :-
iOS Apple's UIAutomations
Android 4.2+ Google's UiAutomator
Andriod 2.3+Google's Instrumentation (Instrumentation support is provded by bundling a seprate projects, Selendroid)

How Appium Works in Android



How Appium Works in iOS



What is appium desired capabilities

Desired capabilities are keys and values and they are encoded in a JSON Object.
Desired capabilities sent by the appium client to the server when a new automation session is requested.
They tell the Appium drivers all kinds of important things about how you want your test to work. Each Appium client builds capabilities in a way specific to the client's language, but at the end of the day, they are sent over to Appium as JSON objects.


appPackage, appActivity, appWaitPackage, appWaitActivity, LaunchTimeout & UDID all are capabilities.

appPackage call desired JAVA package in android that user want to run.
appActivity Application Activity that user wants to launch from the package.
appWaitPackage Package from which application needs to wait for
appWaitActivity Any Android activity that user need wait time
LaunchTimeout Total time(in ms) to wait for instrumentation.
UDID To identity unique device number for connected physical device.

What is the full form of ADB
Ans :-Android Debug Bridge