Ankit_Add

Thursday, January 1, 2015

Selenium Web Driver with all Browser


Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese)to write tests in a number of popular programming languages, including Java, C#, Groovy, Perl, PHP, Python and Ruby. The tests can then be run against most modern web browsers. Selenium deploys on Windows, Linux, and Macintosh platforms. It is open-source software, released under the Apache 2.0 license, and can be downloaded and used without charge


Here is a basic Selenium program for Selenium developer who want to to use Selenium
In this program i have covered basic functionality of Selenium and how it works on different browser like Mozila Firefox,Chrome and Internet Explorer

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.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.io.File;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Testing1 {

    public void setUp(String sBrowser){
       
        WebDriver driver = null;
       
        if(sBrowser.equalsIgnoreCase("Firefox")){
            driver = new FirefoxDriver();
        }
        if(sBrowser.equalsIgnoreCase("Chrome")){
       
            File file = new File("C:\\Users\\Ankit\\workspace\\Selenium\\Chrome\\chromedriver.exe");
            System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
            driver = new ChromeDriver();
        }
        if(sBrowser.equalsIgnoreCase("IE")){
       
            File file = new File("C:\\Users\\Ankit\\workspace\\Selenium\\IE\\IEDriverServer.exe");
            System.setProperty("webdriver.ie.driver", file.getAbsolutePath() );
            driver = new InternetExplorerDriver();
        }
       
        driver.get("http://www.google.com");
        WebElement searchBox = driver.findElement(By.xpath(".//input[@name='q']"));
        searchBox.sendKeys("Ankit Singhal");
        driver.findElement(By.name("btnG")).click();
    }
   
   
    public static void main(String args[]){
       
        Testing1 test = new Testing1();
        test.setUp("Chrome");
    }
   
}

No comments:

Post a Comment