Automation Script Implementation in Webdriver

Automation Script Implementation in Webdriver:

Let’s know, how to do Automation Script Implementation in Webdriver in Eclipse by using Java. Here in this article, I have implemented a Selenium Webdriver automation script of Practice form to fill for the purpose of Practice for Automation Testing.

In this script, I have taken Project Name: Selenium Automation, Package name: Practice, Classname: Webdriver_Practice

In this script I have used to automate Text boxes, dropdown, Multiple options select in List box, Button, Radio button, Checkbox, Image path for upload, parameterization, Google chrome browser launch etc.

 

package Practice.Practice;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

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

 

public class Webdriver_Practice {               

                public WebDriver driver;

          

                public void Chrome_Launch() {

                           System.setProperty(“webdriver.chrome.driver”, “D:\\Selenium\\Library\\chromedriver.exe”);

                           driver=new ChromeDriver();

                }

               

                public void Url_0pen() {

                               driver.manage().window().maximize();

                                driver.get(“http://toolsqa.com/automation-practice-form/”);

                }

               

              public void Practice_Automation_Form(){

 driver.findElement(By.partialLinkText(“Partial Link Test”)).click();  //click on Partial Link Test                                                               driver.findElement(By.xpath(“/html/body/div[1]/div[5]/div[2]/div/div/div[1]/div/div/div/div[2] /div/form/fieldset/div[8]/input”)).sendKeys(“Test”);  //Enter First Name

 driver.findElement(By.xpath(“/html/body/div[1]/div[5]/div[2]/div/div/div[1]/div/div/div/div[2] /div/form/fieldset/div[11]/input”)).sendKeys(“Name1”);   //Enter Last Name

 driver.findElement(By.id(“sex-0”)).click();  // Select the Sex as Male

 driver.findElement(By.id(“exp-3”)).click();  // Select the Years of Experience

 driver.findElement(By.id(“profession-0”)).click(); // click on check box of Profession as Manual Tester

 driver.findElement(By.id(“profession-1”)).click(); // click on check box of Profession as Automation Tester

 driver.findElement(By.id(“photo”)).sendKeys(“C:\\Users\\Public\\Pictures\\Sample Pictures\\test.jpg”); // This line of code will upload the Profile pic from the Local system drive

 new Select(driver.findElement(By.id(“continents”))).selectByVisibleText(“Australia”); // This line of code is for Select the value from a dropdown field.                     

 }

 /*This below method is to select multiple options in a Listbox or dropdown  */        

  public void Select_Multiple_Options_In_Listbox(){

                               WebElement Groupid_select=driver.findElement(By.id(“selenium_commands”));

                                Select group=new Select(Groupid_select);

                                group.selectByVisibleText(“Browser Commands”);

                                group.selectByVisibleText(“Navigation Commands”);

                                group.selectByVisibleText(“Wait Commands”);

                   }

               

                public void Submit_Form(){

                                driver.findElement(By.id(“submit”)).click();  // click on the Submit button

                                driver.close();

                               }

 

                public static void main(String[] args) {

                                // TODO Auto-generated method stub

                               Webdriver_Practice d=new Webdriver_Practice();

                                d.Chrome_Launch();

                                d.Url_0pen();

                                d.Practice_Automation_Form();

                                d.Select_Multiple_Options_In_Listbox();

                                d.Submit_Form();         

                }

}

 

Please click here to Read Browser Launch in Selenium Webdriver

Please click here to Read X-path through Firebug and FirePath

Leave a Comment