First Program
package automationPractice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstAutomationProgram
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com");
}
}
Firefox program
package automationPractice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirefoxBrowserProgram
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com/");
}
}
package automationPractice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstAutomationProgram
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan Velo\\Automation
Batch Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//get method --> url open
driver.get("https://www.facebook.com/");
Thread.sleep(5000); //script pause 5 seconds
//maximize the browser
driver.manage().window().maximize();
Thread.sleep(5000);
//to minimize
// driver.manage().window().minimize();
//browser close
// driver.close();
//or
driver.quit();
// //nevigate().to();
// driver.navigate().to("https://www.selenium.dev/");
//
// Thread.sleep(5000);
//
// driver.navigate().back(); //facebook
//
// Thread.sleep(5000);
//
// driver.navigate().forward(); //selenium
//
// Thread.sleep(5000);
//
// driver.navigate().refresh(); //selenium
}
}
Program1
package automationPractice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstAutomationProgram
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan Velo\\Automation
Batch Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//get method --> url open
driver.get("https://www.facebook.com/");
Thread.sleep(5000); //script pause 5 seconds
//maximize the browser
driver.manage().window().maximize();
Thread.sleep(5000);
//to minimize
// driver.manage().window().minimize();
//browser close
// driver.close();
//or
driver.quit();
// //nevigate().to();
// driver.navigate().to("https://www.selenium.dev/");
//
// Thread.sleep(5000);
//
// driver.navigate().back(); //facebook
//
// Thread.sleep(5000);
//
// driver.navigate().forward(); //selenium
//
// Thread.sleep(5000);
//
// driver.navigate().refresh(); //selenium
}
}
Program2
package automationPractice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MethodsOfWebDriver
{
public static void main(String[] args) throws
InterruptedException
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//get method --> url open
driver.get("https://www.facebook.com/");
Thread.sleep(5000); //to pause the script
//maximize -method chaining
driver.manage().window().maximize();
//website url
String url = driver.getCurrentUrl();
System.out.println(url);
//website title-
String webTitle = driver.getTitle();
System.out.println(webTitle);
// Thread.sleep(10000);
//browser close //current tab close
driver.close();
// driver.quit(); //total browser close
}
}
Program-3-method chaining
package automationPractice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebDriver.Options;
import org.openqa.selenium.WebDriver.Window;
import org.openqa.selenium.chrome.ChromeDriver;
public class MethodChaining
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
//upcasting
//refvar-webdriver
//method-webdriver
//const-chromedriver
// WebDriver driver = new ChromeDriver();
//
// driver.get("https://www.facebook.com/");
//browser maximize
//no method near to webdriver to maximize the browser
// driver.maximize(); //not possible
//method chaining-calling one method with the help of
//another method
// driver.manage().window().maximize();
//or
// String s = driver.getTitle(); storing in string
WebDriver driver = new ChromeDriver();
//
// Options o = driver.manage();
//
// Window w = o.window();
//
// w.maximize();
// driver.manage().window().maximize();
//
// driver.manage() --> Options o
// o.window(); --> Window w
// w.maximize();
//refresh syntax
// driver.refresh(); --> webdriver -no such method
// Navigation n = driver.navigate();
//
// n.refresh();
driver.navigate().refresh();
}
}
Program-4 different syntax
package automationPractice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DifferntSyntaxex
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
//upcasting
// webdriver--> interface
// chromedriver-->class
//syntax-1
// WebDriver driver = new ChromeDriver();
//syntax-2-->WebDriver is iterface and
//we cant create the object interface
//there is no such const concept interface
// WebDriver driver = new WebDriver(); -->not possible
//syntax-3 -Possible
//but it is not necessary that all the merthods which were
//present near webdriver should be present here as well
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/"); //--
>Remotewebdriver-get method
}
}
Program-5 setPosition() and setSize() method
package automationPractice;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SetSizeAndPosition
{
public static void main(String[] args) throws
InterruptedException
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//get method --> url open
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
Thread.sleep(5000);
//browser -size set--> W X H
// //W and H --> screens --> mm, m -->Pixels
//
// //size of browser
} Dimension d = new Dimension(300,500);
}
driver.manage().window().setSize(d);
//position of browser
Point p = new Point(600, 600);
driver.manage().window().setPosition(p);
package automationPractice;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.chrome.Chrom
eDriver;
public class URLOpeningProgram
{
public static void
main(String[] args)
{
System.setProperty("webdriver.
chrome.driver",
"D:\\Back-up
Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedrive
r_win32\\chromedriver.exe");
//upcasting
WebDriver driver = new
ChromeDriver();
//method chaining
driver.manage().window().maxim
ize();
//open the url
driver.get("https://www.facebo
ok.com/");
//to bring the url from
browser
String actualURL =
driver.getCurrentUrl();
//result
String expectedURL =
"https://www.facebook.com/";
//given
if(actualURL.equals(expectedUR
L))
{
System.out.println("test
case is passed");
}
else
{
System.out.println("test
case is failed");
}
}
}
Do the practice on following websites
https://opensource-demo.orangehrmlive.com/
ID - Admin
PWD - admin123
https://www.saucedemo.com/
ID - standard_user
PWD - secret_sauce
Program-1 saucedemo login
package automationPractice;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SauceDemoLoginProgram
{
public static void main(String[] args) throws
InterruptedException
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.saucedemo.com/");
Thread.sleep(3000);
//login
// username value pass
// password value pass
// login button click
//username element //A-->//AV
WebElement userNameTextBox = driver.findElement(By.id("user-
name"));
//value send -method --> sendKeys
userNameTextBox.sendKeys("standard_user");
Thread.sleep(3000);
//password element
WebElement passwordTextBox =
driver.findElement(By.id("password"));
passwordTextBox.sendKeys("secret_sauce");
Thread.sleep(3000);
//login button driver.findElement(By.id("login-
WebElement loginButton =
button"));
loginButton.click();
}
}
Program-2 facebook login
package automationPractice;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class FaceBookLogin
{
public static void main(String[] args) throws
InterruptedException
{
System.setProperty("webdriver.chrome.driver",
"D:\\Back-up Data\\Desktop-Backup\\Pavan
Velo\\Automation Batch
Material\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
Thread.sleep(3000);
//usernametextbox
WebElement username =driver.findElement(By.id("email"));
username.sendKeys("UserName");
Thread.sleep(3000);
//password textbox
WebElement password = driver.findElement(By.name("pass"));