Pages

Search This Blog

Friday, July 22, 2011

Easy Way To Automate Using WebDriver

WebDriver is a clean, fast framework for Automation development of web-apps. WebDriver takes many advantages over selenium because selenium is written in java-script which causes a significant weakness: browsers impose a pretty strictly model , try to upload a file ,form control etc.
webDriver takes a different approach to solve the same problem as selenium. Rather than being running a java-script application within a browser, it uses whichever the mechanism is most appropriate to control the browser. Like for Firefox ,this means that webDriver is implemented as an extension.
The real beauty which I like most is real time environment, which means we are more closely modeling how the user interacts with the browser, and that we can type into "file" input elements. WebDriver can make use of facilities offered by the Operating System.
With the benefit of hindsight, we have developed a cleaner, Object-based API for WebDriver, rather than follow Selenium's dictionary-based approach.

Please download the respective jar related to your language from google code selenium project Download

Now follow below steps:-
1:- Extract the download file into a folder name and include the jars file ion your ClassPath
2:- Sample coding in java




import junit.framework.TestCase;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class WebDriverTest extends TestCase{
@Test
public void test_hellotest()throws Exception{
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
// Find the text input element by its name WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Niraj Kumar");
// 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());
driver.close();
}
}

9 comments:

  1. Hi, Don't you need to place the url in quotes:

    driver.get("http://www.google.com/webhp?complete=1&hl=en");

    ReplyDelete
  2. nice blog post for good help provide the Automation Testing Services i really like you post most important thing i thank full to you for code great help providing these codes.

    ReplyDelete
  3. IMP provides a complete range of innovative solutions from sampling to analysis
    sampling
    automation systems

    ReplyDelete
  4. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  5. It was very nice blog to learn about SAP HR.Thanks for sharing new things.SAP HR

    ReplyDelete
  6. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete
  7. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  8. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete