Automation Script for different login page
1) Gmail Application
package com.selenium.automate;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class GmailLogin {
public static void main(String[] args) throws InterruptedException {
//initialize FireFox driver
WebDriver driver = new FirefoxDriver();
//Open gmail
driver.get("http://www.gmail.com");
// Enter user id
WebElement element = driver.findElement(By.id("Email"));
element.sendKeys("your email id");
// Click on Next Button
WebElement element1= driver.findElement(By.id("next"));
element1.click();
//wait 5 secs for userid to be entered
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Enter Password in the textfield
WebElement element2 = driver.findElement(By.id("Passwd"));
element2.sendKeys("your password");
// Click on Submit button
driver.findElement(By.id("signIn")).click();
WebElement myDynamicElement = (new WebDriverWait(driver, 15)).until(ExpectedConditions.presenceOfElementLocated(By.id("gbg4")));
driver.findElement(By.id("gbg4")).click();
//press signout button
driver.findElement(By.xpath("//*[@id='gb']/div[1]/div[1]/div[2]/div[4]/div[1]/a/span")).click();
Thread.sleep(2000);
driver.findElement(By.id("gb_71")).click();
driver.close();
}
}
2) Facebook Page
package com.selenium.automate;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Facebooklogin {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
Thread.sleep(2000);
WebElement username = driver.findElement(By.id("email"));
WebElement password = driver.findElement(By.id("pass"));
WebElement Login = driver.findElement(By.id("u_0_v"));
username.sendKeys("your email-id");
password.sendKeys("your password");
Login.click();
Thread.sleep(3000);
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement navigationclick = driver.findElement(By.id("logoutMenu"));
WebElement logout = driver.findElement(By.xpath("//div[@id='u_d_1']/div/div/div/div/div/ul/li[12]/a/span/span"));
navigationclick.click();
if(logout.isEnabled() && logout.isDisplayed()) {
logout.click();
}
else {
System.out.println("Element not found");
}
}
}
3) Linkedin Login
package Com.selenium.automate;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class linkedinLoginAndLogout {
public static void main(String[] args) throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.linkedin.com/");
driver.findElement(By.id("login-email")).sendKeys("your email-id");
driver.findElement(By.id("login-password")).sendKeys("your password");
driver.findElement(By.xpath(".//*[@type='submit']")).click();
Actions act=new Actions(driver);
WebElement sign = driver.findElement(By.id("signin"));
act.moveToElement(sign).doubleClick().perform();
WebElement network = driver.findElement(By.xpath("//li[@class='nav-item']/a[contains(text(),'Connections')]"));
act.moveToElement(network).perform();
Thread.sleep(1000);
WebElement addConn = driver.findElement(By.xpath("//ul[@class='sub-nav']//a[contains(text(),'Add Connections')]"));
act.moveToElement(addConn).click().perform();
WebElement img = driver.findElement(By.xpath(".//*[@id='img-defer-id-1-35948']"));
act.moveToElement(img).perform();
WebElement signOut = driver.findElement(By.xpath(".//*[@class='account-submenu-split-link']"));
act.moveToElement(signOut).click().perform();
}
}
4) Twitter Page
package Com.selenium.automate;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TwitterLogin {
public static void main(String[] args) throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Step1: Navigate to the Url
driver.get("https://twitter.com/");
//step2: Click on the login link
driver.findElement(By.xpath(".//*[@class='Button StreamsLogin js-login']")).click();
//Step3: Enter values in the username textbox
driver.findElement(By.xpath(".//*[@placeholder='Phone, email or username']")).sendKeys("your email-id");
// Step 4: enter values in the password
driver.findElement(By.xpath(".//*[@placeholder='Password']")).sendKeys("your password");
// Step 5: Click on the Login button
driver.findElement(By.xpath(".//*[@value='Log in']")).click();
// Step 6: Wait for the page to load
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Step7: Click on the Popup link
driver.findElement(By.xpath(".//*[@id='user-dropdown-toggle']")).click();
//Step 8: Click on Logout button
driver.findElement(By.xpath(".//*[@id='signout-button']/button")).click();
// Step 9 : close the browser
driver.close();
}
}
1) Gmail Application
package com.selenium.automate;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class GmailLogin {
public static void main(String[] args) throws InterruptedException {
//initialize FireFox driver
WebDriver driver = new FirefoxDriver();
//Open gmail
driver.get("http://www.gmail.com");
// Enter user id
WebElement element = driver.findElement(By.id("Email"));
element.sendKeys("your email id");
// Click on Next Button
WebElement element1= driver.findElement(By.id("next"));
element1.click();
//wait 5 secs for userid to be entered
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Enter Password in the textfield
WebElement element2 = driver.findElement(By.id("Passwd"));
element2.sendKeys("your password");
// Click on Submit button
driver.findElement(By.id("signIn")).click();
WebElement myDynamicElement = (new WebDriverWait(driver, 15)).until(ExpectedConditions.presenceOfElementLocated(By.id("gbg4")));
driver.findElement(By.id("gbg4")).click();
//press signout button
driver.findElement(By.xpath("//*[@id='gb']/div[1]/div[1]/div[2]/div[4]/div[1]/a/span")).click();
Thread.sleep(2000);
driver.findElement(By.id("gb_71")).click();
driver.close();
}
}
2) Facebook Page
package com.selenium.automate;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Facebooklogin {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
Thread.sleep(2000);
WebElement username = driver.findElement(By.id("email"));
WebElement password = driver.findElement(By.id("pass"));
WebElement Login = driver.findElement(By.id("u_0_v"));
username.sendKeys("your email-id");
password.sendKeys("your password");
Login.click();
Thread.sleep(3000);
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement navigationclick = driver.findElement(By.id("logoutMenu"));
WebElement logout = driver.findElement(By.xpath("//div[@id='u_d_1']/div/div/div/div/div/ul/li[12]/a/span/span"));
navigationclick.click();
if(logout.isEnabled() && logout.isDisplayed()) {
logout.click();
}
else {
System.out.println("Element not found");
}
}
}
3) Linkedin Login
package Com.selenium.automate;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class linkedinLoginAndLogout {
public static void main(String[] args) throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.linkedin.com/");
driver.findElement(By.id("login-email")).sendKeys("your email-id");
driver.findElement(By.id("login-password")).sendKeys("your password");
driver.findElement(By.xpath(".//*[@type='submit']")).click();
Actions act=new Actions(driver);
WebElement sign = driver.findElement(By.id("signin"));
act.moveToElement(sign).doubleClick().perform();
WebElement network = driver.findElement(By.xpath("//li[@class='nav-item']/a[contains(text(),'Connections')]"));
act.moveToElement(network).perform();
Thread.sleep(1000);
WebElement addConn = driver.findElement(By.xpath("//ul[@class='sub-nav']//a[contains(text(),'Add Connections')]"));
act.moveToElement(addConn).click().perform();
WebElement img = driver.findElement(By.xpath(".//*[@id='img-defer-id-1-35948']"));
act.moveToElement(img).perform();
WebElement signOut = driver.findElement(By.xpath(".//*[@class='account-submenu-split-link']"));
act.moveToElement(signOut).click().perform();
}
}
4) Twitter Page
package Com.selenium.automate;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TwitterLogin {
public static void main(String[] args) throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Step1: Navigate to the Url
driver.get("https://twitter.com/");
//step2: Click on the login link
driver.findElement(By.xpath(".//*[@class='Button StreamsLogin js-login']")).click();
//Step3: Enter values in the username textbox
driver.findElement(By.xpath(".//*[@placeholder='Phone, email or username']")).sendKeys("your email-id");
// Step 4: enter values in the password
driver.findElement(By.xpath(".//*[@placeholder='Password']")).sendKeys("your password");
// Step 5: Click on the Login button
driver.findElement(By.xpath(".//*[@value='Log in']")).click();
// Step 6: Wait for the page to load
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Step7: Click on the Popup link
driver.findElement(By.xpath(".//*[@id='user-dropdown-toggle']")).click();
//Step 8: Click on Logout button
driver.findElement(By.xpath(".//*[@id='signout-button']/button")).click();
// Step 9 : close the browser
driver.close();
}
}
No comments:
Post a Comment