HOW TO WRITE FIRST SELENIUM WEBDRIVER SCRIPT?

It is very simple to write the Selenium Webdriver programs to perform automation testing.
Here is the very basic program to open hello selenium blog using Selenium Webdriver script.




Java Source code:

package com.helloselenium.selenium.test;

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

public class OpenHelloSeleniumBlog{

 public static void main(String[] args) { 

  WebDriver driver = new FirefoxDriver();

  driver.get("http://helloselenium.blogspot.com");
  
  driver.quit();
 }

}

Detailed explanation for the above program is as follows:




package com.helloselenium.selenium.test;
Above code is package structure for current program file.
Following code is the required packages for Selenium Webdriver.
import org.openqa.selenium.WebDriver;
Following code is the required packages for Firefox browser.
import org.openqa.selenium.firefox.FirefoxDriver;
Above both required packages are available in downloaded selenium server jar file.
Following code is to initialize the Firefox driver.
WebDriver driver = new FirefoxDriver();




Following code is to open the hello selenium blog in browser.
driver.get("http://helloselenium.blogspot.com");
You can also use the following code is to open the hello selenium blog in browser.
driver.navigate().to("http://helloselenium.blogspot.com");
Following code is to quit the Firefox driver instance.
driver.quit();
You can also use the following code is to close the Firefox driver instance.
driver.close();


Post a Comment

0 Comments