Tuesday, 7 January 2014

Why we refer Firefox driver to the web driver inheritance

7.   Why we refer Firefox driver to the web driver inheritance. 

web Driver driver = new FireFoxDriver();
WebDriver is an interface which contain several abstract methods such as get(...), findElamentBy(...) etc.
We simply create reference of web Driver and we can assign objects (Firefox driver, CromeDriver, IEDriver, Andriod driver etc) to it.
Ex :
WebDriver driver = new FireFoxDriver();-----------(1)
If we are using (1) we can do the same thing by using
FireFoxDriver driver = new FireFoxDriver();---------(2)
We can use (1) and (2) for same purpose but if we want to switch to another browser in same program
then again we have to create the object of other class as for example
CromeDriver driver = new CromeDriver();.
creating object of several class is not good. So we create the reference of WebDriver and
we assign the objects of another class as for example
WebDriver driver; // it is created only one time in the program
driver = new FireFoxDriver();// any where in the program
driver = new CromeDriver(); // any where in the program


Best way to locate element in selenium

  Which is the best way to locate an element?

Finding elements by ID is usually going to be the fastest option, because at its root, it eventually calls down to document.getElementById(), which is optimized by many browsers.

Finding elements by XPath is useful for finding elements using very complex selectors, and is the most flexible selection strategy, but it has the potential to be very slow, particularly in IE. In IE 6, 7, or 8, finding by XPath can be an order of magnitude slower than doing the same in Firefox. IE provides no native XPath-over-HTML solution, so the project must use a JavaScript XPath implementation, and the JavaScript engine in legacy versions of IE really is that much slower.


If you have a need to find an element using a complex selector, I usually recommend using CSS Selectors, if possible. It's not quite as flexible as XPath, but will cover many of the same cases, without exhibiting the extreme performance penalty on IE that XPath can.


Difference between Selenium RC and Selenium Web driver

 Difference between Selenium RC and Selenium Web driver.

Selenium RC
Selenium Web driver

Selenium RC’s architecture is way more complicated.

Web Driver’s architecture is simpler than Selenium RC’s.
Selenium RC is slower since it uses a JavaScript program called Selenium Core. This Selenium Core is the one that directly controls the browser, not you.
Web Driver is faster than Selenium RC since it speaks directly to the browser uses the browser’s own engine to control it.
Selenium Core, just like other JavaScript codes, can access disabled elements.
Web Driver interacts with page elements in a more realistic way.
Selenium RC’s API is more matured but contains redundancies and often confusing commands.
Web Driver’s API is simpler than Selenium RC’s. It does not contain redundant and confusing commands.
Selenium RC cannot support the headless HtmlUnit browser. It needs a real, visible browser to operate on.
Web Driver can support the headless HtmlUnit browser.
Selenium RC Has Built-In Test Result Generator. Selenium RC automatically generates an HTML file of test results. 
Web Driver has no built-in command that automatically generates a Test Results File.
Selenium RC needs the help of the RC Server in order to do so.
web Driver directly talks to the browser
Selenium RC can support new browsers
It cannot readily support new browsers




Difference between Absolute path & Relative path

Difference between Absolute path & Relative path.

Absolute path will start with root path (/) and Relative path will from current path (//)
Click Here for Detailed Answer
Absolute xPath : /html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div[@id='main']/div[@id='Blog1']/div[1]/div[1]/div/div[1]/div/h3/a

Relative xPath : //h3/a[text()='Working on New Window']

Or In  Selenium IDE.
http://ruchi-myseleniumblog.blogspot.in
and
http://ruchi-myseleniumblog.blogspot.in/2013/12/100-selenium-interview-questions.html
Both are absolute path.

Let say you have set you base URL as
http://ruchi-myseleniumblog.blogspot.in
and you want to go to other page of it like
http://ruchi-myseleniumblog.blogspot.in/2013/12/100-selenium-interview-questions.html
or
http://ruchi-myseleniumblog.blogspot.in/2013/12/basic-core-java-interview-questions.html

then you don’t have to type complete absolute path each time. use relative path like
/2013/12/100-selenium-interview-questions.html.
Or
/2013/12/basic-core-java-interview-questions.html

Once you set the base URL you don’t have to pass the same URL for any of the page on that webpage.
First set the base URL in SIDE as
http://ruchi-myseleniumblog.blogspot.in then run script.


Selenium Hybrid Framework using Selenium WebDriver, POI,testNg , Log4J

To be updated asap with new framework and its documentation.

Friday, 3 January 2014

program to transpose a Matrix.

Write a program to transpose a Matrix.

package programs;

import java.util.Scanner;

public class TransposeMatrix {

public static void main(String[] args) {
int row, col, i, j;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
row = in.nextInt();
col = in.nextInt();

int mtrx[][] = new int[row][col];

System.out.println("Enter the elements of matrix");

for (i = 0; i < row; i++)
for (j = 0; j < col; j++)
mtrx[i][j] = in.nextInt();

System.out.println("Original Entered matrix  :-");

for (i = 0; i < row; i++) {
for (j = 0; j < col; j++)
System.out.print(mtrx[i][j] + "\t");

System.out.print("\n");
}

int transpose[][] = new int[col][row];

for (i = 0; i < row; i++) {
for (j = 0; j < col; j++)
transpose[j][i] = mtrx[i][j];
}

System.out.println("Transposed matrix  :-");

for (i = 0; i < row; i++) {
for (j = 0; j < col; j++)
System.out.print(transpose[i][j] + "\t");

System.out.print("\n");
}
}
}

program to fetch unique elements from Array.

Write a program to fetch unique elements from Array.

package programs;

import java.util.LinkedHashSet;
import java.util.Set;

public class Arrayuniqno {
public static void main(String[] args) {
int[] array1 = { 1, 1, 2, 1, 3, 4, 5, 8, 8, 8, 8 };

System.out.println("Original Array1  Elements1:");
for (Integer x : array1) {
System.out.print(x + " ");
}
Set<Integer> UniqueNumbers = new LinkedHashSet<Integer>();
for (int x : array1) {
UniqueNumbers.add(x);
}
System.out.println("");
System.out.println("Array2 with Unique Elements: ");
Object[] array2 = UniqueNumbers.toArray();
for (Object x : array2) {
System.out.print(x + " ");
}
}
}