Pre-requisites for any selenium Project

Lets try to list out a few pre-requisites for selenium project shall we?

  1. Firefox
  2. Selenium IDE (Plug-in to firefox)
  3. Optionally other browsers if we intend to run our tests on them.
  4. Our application to be tested must be hosted some where.
  5. Latest JDK and JRE installed in the system.
  6. Any Java Development environment ( Eclipse / Net beans)

(This assuming you are going for Java. For C# you might need .Net framework 3.5 and VS)

And you are good to go :)

Tecnical skills required are:

  1. Basic Object oriented concepts.
  2. Java/C# knowledge or if you are good with any of the other scripting languages selenium supports you are good to go.
  3. Selenium/Webdriver APIs ( This you can learn as you code)
  4. Unit testing frameworks like Junit/Nunit ( no that important)
  5. Ability to Google and Google well.
  6. A passion to learn and put the effort coz mind you this is open source free software. Hence as much as the features it offers there will be a lot that it might not offer currently. It will keep getting better. So to overcome some of its limitations it will be a huge challenge. You might have to Google, ask around, do your own research to solve problems. So willingness to learn and work hard is also a pre-requisite.
2 Comments

Steps to Setting up selenium 2.0 project and use webdriver and selenium

  1. Start by Downloading the latest binaries and unpack them into a directory. From now on, we’ll refer to that as $SELENIUM_HOME.
  2. Now, open your favorite IDE , Lets assume your favorite language is java. Hence you should use Eclipse or Netbeans as the IDE. Both are free btw :)
  3. Start a new project in your favourite IDE/editor
  4. Add a reference to all the libraries in $SELENIUM_HOME
  5. Note : You can see that WebDriver/Selenium2.0 acts just as a normal library does: it’s entirely self-contained, and you usually don’t need to remember to start any additional processes or run any installers before using it, as opposed to the proxy server with Selenium-RC.
  6. You’re now ready to write some code. Lets see the following example
  7. package org.openqa.selenium.example;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class Selenium2Example {
    public static void main(String[] args) {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface,
    // not the implementation.
    WebDriver driver = new FirefoxDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    //Close the browser
    driver.quit();
    }
    }

    The above test would run on a firefox browser since we are using the firefox driver. Hence you would need firefox installed in your machine.

    In case you’d like to run the same test in other browsers you can use the Internet Explorer Driver or Chrome Driver or HtmlUnit Driver.

    HTMLunit driver does not run against any browser but is meant for speedier testing. We’ll be looking at them later.

    Now the code above uses the webdriver apis. Now if we wanted to use a selenium instance , we can create a webdriver backed selenium instance as shown below.

// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();

// A "base url", used by selenium to resolve relative URLs
String baseUrl = "http://www.google.com";

// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);

// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");

// Get the underlying WebDriver implementation back. This will refer to the
// same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver();

//Finally, close the browser. Call stop on the WebDriverBackedSelenium instance
//instead of calling driver.quit(). Otherwise, the JVM will continue running after
//the browser has been closed.
selenium.stop();

As mentioned in the website the pros and cons of using webdriver backed selenium are

Pros

  • Allows for the WebDriver and Selenium APIs to live side-by-side
  • Provides a simple mechanism for a managed migration from the Selenium RC API to WebDriver’s
  • Does not require the standalone Selenium RC server to be run

Cons

  • Does not implement every method
  • More advanced Selenium usage (using “browserbot” or other built-in JavaScript methods from Selenium Core) may not work
  • Some methods may be slower due to underlying implementation differences
As we learn more we’ll try to come up with how better to use these.
String baseUrl = "http://www.google.com";
1 Comment

Selenium 2.0 (Introductory video by the creators)

Here is a nice little introduction on selennium 2.0 by the creators. We have JAson higgins talkin about why they had to work on selenium 2.0. Very interesting . Should clear some of your doubts. If not atleast create a few interesting doubts. :)
Well this is part 2 of the video. You can check out the first part at youtube.

2 Comments

Selenium 2.0 -An Intro

Selenium 2.0 is the new kid in the block of Automation testing. If you have been working with selenium then you would definitely have heard of this new project.

I have only recently started exploring Selenium2.0 and boy does it sound interesting. It aims at merging the best of web-driver and selenium APIs to make a compelling and holistic automation tool.

Selenium1 worked by injecting JavaScript into the browsers to simulate user actions. So if you had to press “Down arrow key” you would essentially be injecting a java script which would simulate that user action. Hence naturally this had its own limitations like being slow and also security issues.

Webdriver on the other hand user native keystrokes. Its almost like the user pressing the keyboard. Web-driver in essence fills the many vulnerabilities of selenium and merging these two tools would make selenium2.0 a perfect tool fro web-testing.

So some very obvious benefits of migrating to selenium2.0 are:

  1. The tests would run really fast.
  2. Handling multiple windows and pop-ups will be easier.
  3. The best of Web-driver and Selenium APIs
  4. We don’t have to run the server every time to run our tests unlike in the first selenium.

Apart from these obvious APIs there are many others which we’ll see as I get to know them.

Challenges as of now seem to be at the time of this writing is that only the Firefox driver seems to be complete and for IE and chrome work is in progress and would soon be complete.

I have done a lot of research on this lately and would be posting tutorials on how to start writing your testcases and build frameworks around it soon.

Cheers.

Leave a comment