power_settings_new
I am completely new to selenium WebDriver and Test Automation. Can you help me with a few sites to start coding in Selenium? Is there any online document or book I should buy or follow?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
edited by
0 votes

Let me give you some brief about selenium.

At first, you need to understand what test automation is all about. Test Automation is processed automating repeating test cases to reduce manual work.

What is selenium?

Selenium is just a browser automation tool. It is completely based on JavaScript. If something is beyond the scope of JavaScript, you can not use selenium in that case.

Why selenium for Test Automation?

Nowadays you know that most of the applications are developed as a web application. Cross browser testing and parallel execution are really important to reduce time to test. For example, you have the script which validates user login functionality. You enter a username, enter a password, click on login button and user logs in. This will take close to 30 seconds while doing it manually. Imagin doing the same for 5 different browsers. You will end up spending 2 min 30 seconds. Now you will have 1000s of such test cases. Imaging the manual work you have to do. If you automate most of the possible scenarios, you will end up saving 80% on time and budget.

If selenium is just browser automation tool, how to use that for test automation?

Selenium is available in many languages. I assume that you are using Java as your language for test automation. Now as you know, every program needs the starting point. Typical Java class will start with public static void main function. But using public static void main will not help you manage your test cases. In that case, you will have to use a testing framework which will help you manage your tests and suite. E.g. TestNG or JUnit. You will use your Selenium code with TestNG or JUnit to manage your test cases and suites. For BDD you can use Cucumber or JBehave.

Where to start with selenium?

To start with selenium, you can use below code.

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;

import org.openqa.selenium.support.ui.ExpectedCondition;

import org.openqa.selenium.support.ui.WebDriverWait;

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");

        // Alternatively the same thing can be done like this

        // driver.navigate().to("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());

        

        // Google's search is rendered dynamically with JavaScript.

        // Wait for the page to load, timeout after 10 seconds

        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {

            public Boolean apply(WebDriver d) {

                return d.getTitle().toLowerCase().startsWith("cheese!");

            }

        });

        // Should see: "cheese! - Google Search"

        System.out.println("Page title is: " + driver.getTitle());

        

        //Close the browser

        driver.quit();

    }

}

As you can see in example give above, there is a public static void main function to start the program. And you use selenium code for sample automation.

Above code is taken from http://www.seleniumhq.org/docs/03_webdriver.jsp#introducing-webdriver

Key factors to remember while learning selenium.

  • Automation Framework (TestNG or JUnit)
  • Element identification
  • WebDriverWait

Above guide is enough to understand selenium. Rest you can google out and use http://www.seleniumhq.org/docs/

If you want an application to try your Selenium suite, we have hosted OrangeHRM application that can help you do testing.

add
...