Creating First Web Automation Project

Prerequisites:

  1. Eclipse (Development Environment)
  2. Selenium Jars (Jars)
  3. Chrome driver/ Firefox driver

 

  • Launch the eclipse and create new Maven project
  • Add Group Id and Artifact Id and select Finish

  • Right click on the project name from the package explorer and add new class.

  • Right click on the project and select build Path –> Configure build path
  • Add the required jars for selenium or use maven repository and configure the .pom file
  • Provide the driver path in the property. Consider the chrome driver
  • System.setProperty("webdriver.chrome.driver""/Users/username/Downloads/chromedriver")
  • Create an object for chromeDriver.
  • WebDriver driver = new ChromeDriver();
  • Launch the website using get method.
  • driver.get("https://facebook.com");
  • Select the element and perform action.
  • driver.findElement(By.id("signIn")).sendKeys("hello@abc.com");
  • Tap on the errors and import the respective classes from the jars.
  • Finally the Web automation code looks like:
package org.connecttokc.com.FirstProject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Test {

public static void main(String args[]) throws InterruptedException {

 System.setProperty("webdriver.chrome.driver", "/Users/krishnachaitanya/Downloads/chromedriver");

// WebDriver driver = new FirefoxDriver();

WebDriver driver = new ChromeDriver();

driver.get("https://facebook.com");

Thread.sleep(5000);

driver.findElement(By.linkText("Sign Up")).click();

Thread.sleep(1000);

driver.findElement(By.id("signIn")).sendKeys("hello@abc.com");

driver.findElement(By.id("pass")).sendKeys("123456");

driver.findElement(By.id("loginbutton")).click();

}

}
  • Execute/Run the class.
  • This will perform the following actions
    • launch the chrome browser
    • Open facebook page
    • Enter email and password
    • tap on log in button

Leave a Reply

Your email address will not be published. Required fields are marked *