Thursday, January 9, 2014

Implicit Wait in WebDriver


Implicit wait in WebDriver has solved the compile error of Element not found. Element not found kind of error mostly comes in to picture due to slow internet connection or some time due to responses time of Website or web-application and due to which expected element on the website/webpage takes more time to appear. This cause failure of test script written for that specific element on webpage.
Implicit wait in webdriver synchronize test. This implicit wait implementation in test ensure first that element is available in DOM(Data Object Model) or not if not then it wait for the element for a specific time to wait for appearance of element on Webpage.
Normally Implicit wait do the polling of DOM and every time when it does not find any element then it wait for that element for certain time and due to this execution of test become a slow process because implicit wait keep script waiting.Due to this people who are very sophisticated in writing selenium webdriver code advise not to use it in script and for good script implicit wait should be avoided.
Ok come to the point WebDriver API has one Interface named as Timeouts and this is used for implicit wait and since this is interface so have one function named as implicitlyWait(), this method takes the argument of time in Second, and this code is written like this
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Here I have taken 5 second as wait, once script see any findElement() method then it goes for 5 second wait.
But this keeps script waiting for 5 second once it see a findElement() method so WebDriver API has introduced one explicit wait and in this WebDriverwait class play a very important role.
So in next post I would let you know about the Explicit wait and i would suggest to use explicit wait.

How to automate drag & drop functionality using selenium web driver

/ Configure the action
Actions builder = new Actions(driver);

builder.keyDown(Keys.CONTROL)
   .click(someElement)
   .click(someOtherElement)
   .keyUp(Keys.CONTROL);

// Then get the action:
Action selectMultiple = builder.build();

// And execute it:
selectMultiple.perform();   
or
Actions builder = new Actions(driver);

Action dragAndDrop = builder.clickAndHold(someElement)
   .moveToElement(otherElement)
   .release(otherElement)
   .build();

dragAndDrop.perform();

Transformation from Manual tester to a Selenium WebDriver Automation specialist

TasksHuman Interaction (Manual Tester)WebDriver Commands
Invoke BrowserTester manually opens the browser Firefox, IE, chrome or Safari
WebDriver driver=new FirefoxDriver();
WebDriver driver=new SafariDriver();
WebDriver driver=new chromeDriver();
WebDriver driver=new InternetExplorerDriver();
This is actually a WebDriver object instantiation and
this will invoke the browser according to different
WebDriver implementation.
Load URL of ApplicationTester manually type’s in the URL http://www.google.com
driver.get("http://www.google.com");
Loads the given url into the browser
ClickTester clicks on the Search field in the Google home page
driver.findElement(By.cssSelector("#gbqfq")).click();
driver.findElement(By.cssSelector("#gbqfq")).clear();
Click actually comes with clear command in WebDriver.
Clear command will simply clear the input field. Basically
to avoid the auto-form fill.
TypeTester types the words manually
driver.findElement(By.cssSelector("#gbqfq")).sendKeys("test");
Types “test” into the input element identified by css selector.
Select from Drop-downTester clicks on the Drop-down field and selects the required option
Select select = new Select(driver.findElement(By.tagName
("select")));
select.selectByVisibleText("Apple");
Selects the text
displayed as “Apple” in the select combo box which
is identified by tag name “select”
Moving between WindowsTester will simply click on the window or will do a Alt+tab combination to toggle between windows
driver.switchTo().window("windowName");
driver.switchTo().frame("frameName");
We can switch between frames or iframes using above command.
Alert HandlingTester knows that Alert will be pop-up and then asserts it.
driver.findElement(By.xpath (“<Xpath>”)).click();
Alert alert = driver.switchTo().alert();
alert.accept();

Start Selenium WebDriver Test Script on your own

Following steps will guide you to write your own Selenium WebDriver script:

1. Launch Eclipse IDE & create a new Java Project called “SoftwareTestingClass” (To create new Java Project refer post “How to Create Project in Eclipse IDE?”)@@Link Color@@:
selenium webdriver create java project

2. Inside newly created project, create New Package called “home_page” shown in below screenshot:
Selenium Wedriver Create New Package

3. Under newly created Package, create New Class called “OpenURL” shown in below screenshot. The new class is displayed as “OpenURL.java”.
Selenium Wedriver Create New Class

4. Once you created class on right side of above image you will the class name is displayed in the code editor. Now within “OpenURL” class create one new method called “openSoftwareTestingClass()” as shown below:
Selenium Webdriver New Method

5. Add “@Test” annotation above method name “openSoftwareTestingClass()”. Once you add this annotation you will display error showing as below screen shot:
JUnit Selenium Webdriver Annotations

6. To resolve this annotation error we have to hover mouse over “@Test” & click on option “Import ‘Test’ (org.junit)” link shown below screenshot:
Selenium Webdriver Test Annotation Error

7. Once you executed above statement, the new import statement called “import org.junit.Test;” will be added in your code shown in below screenshot. Here we have imported pre-defined “Test” class from JUnit framework.
Selenium Webdriver Import Test Annotation

8. To execute test script in Selenium WebDriver we have to specify the web browser on which we have to execute the test script. So here we have created new Object to connect specified browser while executing our test script. In this script we have selected FireFox Browser. (Selenium WebDriver supports different browser like Chrome, Safari etc. based on your requirement you can use the browser in your test script.)
Selenium Webdriver Firefox Browser Driver

9. Now you will see two error in the newly added line above screenshot. In previous step we have imported predefined class from “WebDriver” from “open.openqa.selenium” package into our “SoftwareTestingClass” Class.
To resolve this error we have to hover mouse over ‘WebDriver’ & click on option “Import ‘WebDriver’ (org.openqa.selenium)” link shown below screenshot:
Selenium Webdriver Resolve Error 1
Make sure that once you imported WebDriver the first error is resolved & new import statement is added in the head of the code.

10. Similarly to resolve above second error we have to import predefined class “FirefoxDriver” from “open.openqa.selenium.firefox” package into our “SoftwareTestingClass” Class.
Selenium Webdriver Resolve Error 2

11. Ensure that new Import statement of FirefoxDriver is added in head of the code & all errors are resolved. now inbuilt FirefoxDriver Class functionality can be used in our “SoftwareTestingClass” Class.
Selenium Webdriver Firefox Browser Driver Added

12. Now I know you have question in mind where these line come from & what is exact meaning of this lines. So before going forward lets discuss meaning of each below statement one by one:
WebDriver _driver = new FirefoxDriver( );
  1. WebDriver: It is a predefined imported Class from “open.openqa.selenium”
  2. _driver: This is name of the new object created, it is _driver id object of WebDriver Class. To identify the objects in the code we have added underscore before the object name. This is not compulsion to add this.
  3. To create an object of specified class, new” java keyword is used.
  4. FirefoxDriver is a predefined Class. FirefoxDriver( ) is a predefined constructor calling statement.

13. Have you observed that in the creation statement of WebDriver object, FirefoxDriver( ) class is used without any parameter. If we do not provide any parameter then it picks up the default values & Java program will launch the default FireFox profile. Default profile means launching FireFox in the safe mode i.e. without any extensions.

14. Till now we have resolved all errors observed in the code. Now let’s launch new Webpage URL & quit the FireFox browser session.
In selenium to open the new url type “_driver.get”, now you will see new box is opened will seven options. Choose first option shown in below screenshot:
Selenium Webdriver Get Argument

15. Now just replace “arg0” value with “http://www.softwaretestingclass.com” shown in below screen shot:
Selenium Webdriver Url To Launch

16. Save the Selenium WebDriver Test and Run the Test using JUnit as shown below:
Selenium Wedriver Run JUnit Test

17. New FireFox browser window is open opened & page “http://www.Softwaretestingclass.com” page is opened as shown in below screen shot:
Selenium Webdriver Launch Url

18. Now we will add next command _driver.quit( );to close the session of the FireFox Browser as shown blow:
Selenium Webdriver Close Browser Session

19. Before conclude this post I want explain few things. Once the new session of FireFox Browser is opened while executing the Selenium WebDriver script, then “WebDriver” text is displayed in red color at bottom right side of the browser.
Selenium Webdriver Test Running

20. Once the test execution is completed, “WebDriver” text color is changes to black as shown in below:
Selenium Webdriver Test Not Running

How to use JUnit Annotations in Selenium WebDriver Automation Script

In Selenium WebDriver if you want to run test script using JUnit framework we have to add few JUnit Annotations in Selenium WebDriver Test script.
Below we are using few most commonly used JUnit annotations & execute our Selenium WebDriver Tests:
  1. @Before
  2. @Test
  3. @After
Let’s open previously created project in Eclipse IDE (click here to get How to create Selenium WebDriver Test using Selenium IDE? – Selenium Tutorial)
1) Once you open the above created Selenium WebDriver Test script and then check if have we used JUnit annotations in the code or not?
Junit Annotations Used In Selenium Webdriver Code
2) The highlighted part in above script is saying that we have used JUnit annotation in Selenium WebDriver code. In this script we have used @Before, @Test and @After annotations.
@Test
When we Run the script as JUnit then all the methods specified below @Test are executed using JUnit Test. As @Test JUnit annotation is specified before the testUntitled() method, this method will be executed when we run the “GoogleSearch” class using JUnit (i.e. Run As > JUnit Test)
Test Annotation Used In Selenium Webdriver
@Before
All the methods are defined in the @Before are executed first & then method which are defined in @Test are executed. The primary use of this annotation is used to set up the test environment which is needed for executing the test. You can in below screen shot we have used setup() method in @Before.
@After
All the methods are defined in the @Test annotation are executed first & then method which are defined in @After are executed. The primary use of this method is to do tear down i.e. deleting temporary data or setting up default values or cleaning up test environment etc.
Here @After annotation is specified before the ‘teardown()’ method. Hence this method will be executed by JUnit after executing all methods that are specified with @Test Annotation.
After Annotation Used In Selenium Webdriver

Run Selenium WebDriver Test Code without JUnit Annotaions:

Now let’s try to run Selenium WebDriver Test Code with commenting JUnit Annotaions & check if you are able execute test code as JUnit Test or not.
1. Comment all three Annotations line as shown in below screen shot. To comment line we have to add // before each line which we have to comment.
Comment Test Annotation Used In Selenium Webdriver
2. Run the Selenium WebDriver Test code with JUnit Test after commenting the annotations as shown below:
Junit Option Not Present
Now you understand if we are not using JUnit annotations in the Selenium WebDriver code then while running the code you cannot able to run the code as JUnit Test.
3. Now let’s uncomment annotations same as shown in below screen shot & check if you able to run the test using JUnit or not:
Uncomment Test Annotation Used In Selenium Webdriver
4. Have you notice that if we try to Run Selenium WebDriver code then the JUnit Test option is available as shown below:
Junit Option Present
So till now we have learned we can run the code using JUnit only if the JUnit annotations added in the code else Run As > JUnit Test option will not be available to Run the test.

Selenium-beginners-webdriver

How to create selenium webdriver maven project

1.How to create selenium maven project.
2.run tests using maven project.
3.selenium grid setup and execute sample test case using grid.


1.How to create selenium maven project

step1: Down load eclipse kepler IDE from eclipse downloads

https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/kepler/SR1/eclipse-java-kepler-SR1-win32.zip

step 2: install maven and testng plugin from eclipse help--->install new software

               add below sites and install testng and maven

                TestNG - http://beust.com/eclipse

                Maven - http://download.jboss.org/jbosstools/updates/m2e-extensions/m2e-apt.
step 3:
create maven project in eclipse and add below depedency tags in pom.xml file.

step4: selenium maven dependency and testng maven dependency

<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.1.1</version>
  <scope>test</scope>
</dependency>
  <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.37.1</version>
    </dependency>
  </dependencies>

step:4
right click on maven project and select maven--->update project option

update project will download latest testng and selenium jars in to .m2 folder in

example:C:\Users\Home\.m2

now you are ready to use your selenium maven project.

for reference you can use my maven project from git repository

https://github.com/naveenkumarks/selenium.git


Note :to download git project install git bash in your local pc

http://git-scm.com/download/win

After installation of git use below command to download selenium maven project.

step1: open git bash

step2: run below command in git bash

git clone https://github.com/naveenkumarks/selenium.git

your GIT bash screen will be like this.


import downloaded maven project

1.click file---->import from eclipse


2.select existing maven project

3.after import successful below screen will come to make sure you import successful

4.click finish and select maven project from eclispe and do right click and select
maven--->update project
5.after update .m2 folder will get all latest testng and selenium jar files.

i have explained two ways to create maven selenium project
1.import from existing maven project
2.create maven project from scratch.





GUI Automation Using Selenium and Junit usgae with selenium RC and Webdriver

I will update following topics every day.if any one knows any updates on following topics please help me.
this topics are updating as per my knowledge.if any mistakes please correct me.

1.how to setup a selenium project in eclipse
2.how to write sample login using selenium webdriver.
3.basics of junit frame work and different annotations .
4.how to parameterize login with different username and passwords.
5.how to integrate ant in your selenium project.
6 how to configure log4j in selenium project.
7.how to read and write data from excel sheet using poi jars.
8.how to configure sqljdbc jar to your selenium project.
9.how to handle multiple browsers using webdriver.
10.Login application with multiple userid and password using junit parameters annotation
11.Read google search Ajax data(ex:type "apple" in search box and do not enter button and  "apple" string results"


1.How to configure selenium project in eclipse.

1.install first Java in your pc and configure java_home and java path in system variable
open command prompt and check java version


C:\Users\Home>java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode, sharing).

2.Download eclipse from eclipse download location.

http://www.eclipse.org/downloads/

eclipse-jee-europa-winter-win32.

3.Download selenium-java-2.15.0.jar and selenium-server-standalone-2.16.0.jar from selenium hq website.
http://seleniumhq.org/

4.open eclipse and create project
Create eclipse java project.
5.Add lib folder in create java project.
lib folder inside java project


6.Copy selenium selenium-java-2.15.0.jar and selenium-server-standalone-2.16.0.jar in lib folder .
copy   selenium-java-2.15.0.jar and selenium-server-standalone-2.16.0.jar  in lib folder.

7.select jar files inside lib in eclipse and right click and select addtobuild path option in eclipse.
selenium jars add to build path.
8.Create new class in java project and start using selenium.

Note:I have explained all examples using Gmail and actitime application

2.how to write sample login using selenium webdriver.

Before starting i want to tell you about GUI automation basic funda :
Any tool QTP/RFT or selenium will identify GUI elemenst based on webelement properties.

Step1:find element on browser using  element properties. .
       2.operate on element (Actions: click,set text and get text from text box ).
Selenium basically identify GUI webelements using ID,NAME,XPATH AND CSS PATH.
i will start GUI automation using gmail login
NOTE:To identify web element properties using  IE devlopers tool in internet explorer and in firefox using firebug tools.(and even you can find xpath using firebug).

element propery for username is "Email"


LOGIN Script:


import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;


public class CreateNewClass {
//login gmail using webdriver
WebDriver Browser;
@Test //junit annotation
public void loginGmail()
{
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
 ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
//create webdriver  object for internetexplorer
Browser=new InternetExplorerDriver(ieCapabilities);
//launch Gmail using get() method
Browser.get("http://www.gmail.com");
//find username text field using name property
WebElement username=Browser.findElement(By.id("Email"));//find and store webelement in username.
//Action on webelement.set text field using send keys.
username.sendKeys("enter your user name");
//find password text box on gmail home page.
WebElement password=Browser.findElement(By.id("Passwd"));//find and store webelement in password
//Action on webelement.set text field using send keys.
password.sendKeys("enter your password");
//find sign button using name property.
WebElement signin=Browser.findElement(By.id("signIn"));
//Action on webelement.set text field using send keys.
signin.click();
}
9.how to handle multiple browsers using webdriver.

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;


public class DialogHndl {

@Test

public void dialog() throws Exception
{
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
System.out.println("dialog test");
WebDriver browser=new InternetExplorerDriver(ieCapabilities);
browser.get("http://home-pc:8080/login.do");
browser.findElement(By.name("username")).sendKeys("admin");
browser.findElement(By.name("pwd")).sendKeys("manager");
browser.findElement(By.id("loginButton")).click();
Thread.sleep(1000);
browser.findElement(By.linkText("Create new tasks")).click();
Set<String> hndls=browser.getWindowHandles();
Iterator itr=hndls.iterator();
while(itr.hasNext())
{

if(browser.getTitle().equals("actiTIME - Enter Time-Track"))
{
itr.hasNext();
browser.switchTo().window((String)itr.next());//this method is switch between windows
System.out.println(browser.getTitle());
}
}
Thread.sleep(1000);
System.out.println(browser.getTitle());
      browser.findElement(By.name("task[0].name")).sendKeys("naveen");
      browser.findElement(By.id("task0.image")).click();
      Thread.sleep(1000);
     // browser.switchTo().activeElement();
      browser.findElement(By.name("comment")).sendKeys("this is subba naveen");
      browser.findElement(By.name("nscbutton")).click();
}
}

10.Login application with multiple userid and password using junit parameters annotation

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;



@RunWith(Parameterized.class)
public class JavaPrograms {

public String username;
public String password;
//public int empid;

public JavaPrograms(String userName,String passwd)
{
this.username=userName;
this.password=passwd;
//this.empid=Empid;
}
@Parameters
public static Collection<Object[]> getdata()
{
Object[][] data=new Object[3][2];

// 1st row
data[0][0]="admin";
data[0][1]="manager";
// data[0][2]=123;

// 2nd row
data[1][0]="admin";
data[1][1]="manager";
//data[1][2]=456;

// 3nd row
data[2][0]="admin";
data[2][1]="manager";
//data[2][2]=456;
//return null;

            return Arrays.asList(data);

}
@Test
public void para() throws Exception
{
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
System.out.println("dialog test");
WebDriver browser=new InternetExplorerDriver(ieCapabilities);
browser.get("http://home-pc:8080/login.do");
browser.findElement(By.name("username")).sendKeys(username);
browser.findElement(By.name("pwd")).sendKeys(password);
browser.findElement(By.id("loginButton")).click();
Thread.sleep(1000);
browser.findElement(By.linkText("Logout")).click();
browser.close();
}
}

3.basics of junit frame work and different annotations .

   junit frame work will work mainly on annotations
List of annotations is useful for beginners  to start junit framework with selenium

1.@before
2.@After
3.@Test
4.@BeforeClass
5.@AfterClass
6.@Ignore
7.@Rule

Usage of @before @After and @Test usage.
following example will explain @before and @after will execute Testcase level.


package junit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class Testclass2 {

@Before
public void setup()
{
System.out.println("Testcase level intial condition");
}

@Test
public void TC1()
{
System.out.println("testcase1");
}

@Test
public void TC2()
{
System.out.println("testcase2");
}

@After
public void TearDown()
{
System.out.println("Clear the Testcase conditions");
}

}
output:



Testcase level intial condition @before
testcase1                                 @testmethod
Clear the Testcase conditions@After
Testcase level intial condition@Before
testcase2                                 @testmethod
Clear the Testcase conditions@After 



11.Read google search Ajax data(ex:type "apple" in search box and do not enter button and  "apple" string results" 


import java.util.List;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;


public class Ajax {

String Search="huawei";
@Test

public void name() throws Exception {
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver web=new InternetExplorerDriver(ieCapabilities);
web.get("http://google.com");
web.findElement(By.name("q")).sendKeys(Search);
Thread.sleep(1000);
List<WebElement> list=web.findElements(By.xpath("//*/span[1]/b[1]"));
System.out.println(list.size());
for (WebElement webElement : list) {
System.out.println(Search+" "+webElement.getText());
}


}

}

7.how to read and write data from excel sheet using poi jars.

A.How to write data in to Excel sheet.


package junit;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.Test;

public class ExcelWrite {

@Test
public void ExcelWrite() throws IOException
{
String excelfilepath="D:\\ExcelReadWrite.xls";
FileInputStream write=new FileInputStream(excelfilepath);
//Create work object and create sheet sheet name
HSSFWorkbook wb=new HSSFWorkbook(write);
System.out.println(wb);
HSSFSheet sheet=wb.createSheet("naveen");
System.out.println(sheet);
//i will write data for 10 rows and 10 coulmns
for(int i=0;i<=10;i++)
{
HSSFRow row=sheet.createRow(i);
for(int j=0;j<=10;j++)
{
HSSFCell cell=row.createCell(j);
cell.setCellValue("naveen");
}
}
FileOutputStream out=new FileOutputStream(excelfilepath);
wb.write(out);
out.close();

}

}

Selenium WebDriver Tutorial – From IDE to Eclipse

Moving from Selenium IDE to Java (JUnit) is more straightforward than one could think! When you have your Selenium IDE test case recorded and Eclipse (for Java) installed, simply follow these steps:
  • Download Selenium Client & WebDriver Language Bindings from Selenium website
  • Extract downloaded ZIP file to intended location (keep some permanent one, as you will need them for a long time)
  • Create new Java project in Eclipse
  • Add all extracted JARs (also these in lib folder) to Java Build Path in project Properties
  • Create Java class
  • Open recorded test case in Selenium IDE, click File » Export Test Case As » Java / JUnit4 / WebDriver
  • Save this file in temporary location
  • Copy it’s content to Java class created in one of previous steps
  • Adjust package and class name, get rid of warnings – finally it should look similar to this one:
package com.example;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class SampleTest {
   private WebDriver driver;
   private String baseUrl;
   private StringBuffer verificationErrors = new StringBuffer();

   @Before
   public void setUp() throws Exception {
      driver = new FirefoxDriver();
      baseUrl = "http://www.google.pl/";
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
   }

   @Test
   public void testZ() throws Exception {
      driver.get(baseUrl);
      driver.findElement(By.id("gbqfq")).clear();
      driver.findElement(By.id("gbqfq")).sendKeys("selenium");
      driver.findElement(By.id("gbqfb")).click();
      driver.findElement(By.linkText("Downloads")).click();
      assertEquals("Selenium Client & WebDriver Language Bindings", 
       driver.findElement(By.cssSelector(
         "a[name=\"client-drivers\"] > h3")).getText());
   }

   @After
   public void tearDown() throws Exception {
      driver.quit();
      String verificationErrorString = verificationErrors.toString();
      if (!"".equals(verificationErrorString)) {
         fail(verificationErrorString);
      }
   }

   private boolean isElementPresent(By by) {
      try {
         driver.findElement(by);
         return true;
      } catch (NoSuchElementException e) {
         return false;
      }
   }

}

Difference between selenium IDE, RC & WebDriver

Selenium is an automation testing tool used to automate various types of applications. It consists of three main parts Selenium IDE, Selenium RC & Selenium WebDriver. In today’s date the WebDriver is the latest version of the Selenium. In today’s article we are seeing what is actual “Difference between selenium IDE, RC & WebDriver“. Also we gonna take a look at
What all different testing Frameworks can be used along with Selenium.
The Selenium IDE is basically something having record & playback options which present in the every automation tool like QTP, Sliktest etc. & also has very good user interface. The core part of Selenium IDE is based on JavaScript & also supports different extension in it. Along with record & playback, you can use Selenium IDE for multiple dynamic stuffs. The main limitation of Selenium IDE is that, it supported in only Firefox browser. If you want to execute your scripts on different browsers, then you can use Selenium RC (Selenium Remote Control). The Selenium RC supports multiple browsers like IE, Firefox, Chrome, Safari, Opera etc.
It also supports multiple languages like Java, Ruby, C#, Perl, Python etc. You have to get expertise in one language (preferred Java language) & code in selenium RC. The application under test in developed in C# & it does not matter the to create your script in the Java or C# or in any language. It’s totally independent on which your testing is carried out. Similar to language independent it is also platform independent, same code will work on Windows OS, Linux, Mac & Solaris. Most common extension used in the selenium RC is the Java Extension, because Java is platform independent language. Similar to Selenium IDE, the RC is also has its limitations. Before start testing, we have to start & stop the server to execute you test.
Difference between selenium IDE, RC & WebDriver
Difference between selenium IDE, RC & WebDriver
So to overcome the all issues & increase the scope of Selenium RC, introduced new version of SE called Selenium WebDriver. WebDirver is come up with the some cool features. Also supports the multiple languages. Main feature over the Selenium RC is that we don’t have to start the server in the Selenium WebDriver. One of the cool feature is that it supports the Android Testing & iPhone testing as well.
The code of WebDriver look different than RC & IDE, it allows you to convert the IDE code to WD & RC code. As IDE supports with the user interface but WebDirver & RC does not have UI, we have to use core programming language in it.

What are difference between Selenium IDE, RC and WebDriver

Selenium IDE
Selenium RC
Selenium WebDriver
It only works in Mozilla browser. It supports with all browsers like Firefox, IE, Chrome, Safari, Opera etc. It supports with all browsers like Firefox, IE, Chrome, Safari, Opera etc.
It supports Record and playback It doesn’t supports Record and playback It doesn’t supports Record and playback
Doesn’t required to start server before executing the test script. Required to start server before executing the test script. Doesn’t required to start server before executing the test script.
It is a GUI Plug-in It is standalone java program which allow you to run Html test suites. It actual core API which has binding in a range of languages.
Core engine is Javascript based Core engine is Javascript based Interacts natively with browser application
Very simple to use as it is record & playback. It is easy and small API As compared to RC, it is bit complex and large API.
It is not object oriented API’s are less Object oriented API’s are entirely Object oriented
It doesn’t supports of moving mouse cursors. It doesn’t supports of moving mouse cursors. It supports of moving mouse cursors.
Need to append full xpath with ‘xpath=\\’ syntax Need to append full xpath with ‘xpath=\\’ syntax No need to append full xpath with ‘xpath=\\’ syntax
It does not supports listeners It does not supports listeners It supports the implementation of listeners
It does not support to test iphone/Android applications It does not support to test iphone/Android applications It support to test iphone/Android applications

What all different testing Frameworks can be used along with Selenium?

When we use selenium, then we make scripts like Script1, Script2, Script3… etc. & execute the script. Sometimes to execute script we have to get the test data from XLS file or user. To read the data from XLS file, the process of reading the data from XLS file is called Parameterization. Along with this you have to generate the test reports, we need to know what happened after executing the script, is script Passed or Failed? Also along with the reports you need to add logging as well. If your script is taking more time to execute script then you need to know what happened at each and every minute, you need to log each & everything to get idea what script is doing & also at what point script is failed & why.
So we need a centralized controller which will read the test data, execute the test cases, generate reports & do the logging as well. In the market two frameworks are available for testing. So that the centralize testing controller are TestNG OR JUnit framework. You can use selenium with TestNG or JUnit framework. These frameworks will execute the test scripts. They will read the data from XLS file generate the reports & also do the logging while executing the scripts. How to started with these testing frameworks can be seen in next couple of articles to get hands on it.

How to Create Project in Eclipse IDE?

To create a project in Eclipse IDE, you have to follow some simple steps:
1) Navigate the extracted Eclipse software zip file showing in following screen shot (Download latest version of Eclipse here: http://www.eclipse.org/downloads/):

open-extracted-eclipse-ide-folder

2) In the extracted Eclipse folder double click on the Eclipse Application file to launch the Eclipse application same as mention in the below screenshot:

open-eclipse-application

Eclipse will take some time to launch the Eclipse welcome window, so wait for little time.

3) Eclipse will ask you to select the workspace, here you can select the path where you want to save Eclipse project. Once you enter the path click on OK button shown as mention below screen shot:

eclipse-set-workspace

4) Eclipse will setup the workspace path & launch the Eclipse Welcome window first time as below, this means that eclipse ide is successfully installed on your machine.

eclipse-welcome-window

5) Go to File menu > New > Java Project.

eclipse-new-project

6) Enter Project Name as “First Project”:

java-project-in-eclipse

In New Java Project window under JRE section select “Use Project specific JRE” radio option & select any value from the JRE version (here I am selecting ‘jre7’). Everytime you have to select the JRE version based on the project.

7) In New Java Project dialog click on Finish button.

create-java-project

8) The new java project called “First Project” is created here & you can see the name of the project in the left section in the below screenshot:

first-eclipse-java-project

Installation of TestNG in Eclipse IDE - Selenium WebDriver

Please follow following simple steps to Install TestNG in Eclipse. We have installed Eclipse in few days back, if you don’t have eclipse then please get installed using post: “Link”

Steps to install TestNG in Eclipse IDE:

1)  Launch Eclipse IDE & under Help menu click on “Install New Software” option.
Testng Eclipse Install New Software

2) Install dialog box will be appeared same as below:
TestNG Eclipse Install Dialog

3) In the install dialog box, enter URL as “http://beust.com/eclipse” in Work with text box & press keyboard enter key.
TestNG Eclipse Enter Url

4) Under Name column TestNG check box will be displayed same as below:
TestNG Eclipse Available Softwares

5) Select the “TestNG” check box & click on Next button.
Eclipse Select TestNG

6) On Install Details screen, make sure that TestNG is selected & then click on Next button same as mentioned below screenshot:
TestNG Eclipse Install Details

7) On Review Licenses screen read license agreement & select “I accept…” option shown in below screen shot & click on Finish button.
TestNG Eclipse License Agreement

8) Ensure that Installing Software dialog appear. Wait till installation gets completed:
TestNG Eclipse Installing Software

9) One security warning message will appear during installation. Ensure that you click on Ok button if same security dialog is appeared.
TestNG Eclipse Security Warning

10) Once the installation process is completed then Eclipse ask you to Restart, click on Yes button.
TestNG Eclipse Software Updates

11) Once the Eclipse is restarted, to make sure whether TestNG is installed or not. Just under Run menu click on “Run As” option & check new option is added called “TestNG Test”same as below screen shot:
Eclipse TestNG Run As Option

Conclusion:
TestNG is really impressive framework where we can execute the simple to complex test scripts with ease. It supports many powerful features, like annotations, reporting, data-driven testing etc.