Access your gmail account through webdriver
---------------------------------------------------------------------------------------
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;
public class gmail {
/**
* @param args
*/
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com");
driver.manage().window().maximize();
String actualTitle = driver.getTitle();
String expected="Sign in - Google Accounts";
if(expected.equalsIgnoreCase(actualTitle))
{
System.out.println("Title match");
}
else
{ System.out.println("Title does not match");
}
// enter a valid username in the email textbox
WebElement username = driver.findElement(By.id("Email"));
username.sendKeys(" user email id");
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
WebElement Nextbutton= driver.findElement(By.id("next"));
Nextbutton.click();
WebElement Password = driver.findElement(By.id("Passwd"));
Password.sendKeys("your password");
// click on the Sign in button
WebElement SignInButton = driver.findElement(By.id("signIn"));
SignInButton.click();
// close the web browser
driver.close();
System.out.println("Test script executed successfully.");
// terminate the program
System.exit(0);
}//Closed main functionality
}//closed classes
Same program can be run through testng after few modification inside the code.
package demo_Testng;
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.testng.annotations.Test;
public class demo {
WebDriver driver = new FirefoxDriver();
@Test
public void f() {
driver.get("https://accounts.google.com");
driver.manage().window().maximize();
String actualTitle = driver.getTitle();
String expected="Sign in - Google Accounts";
if(expected.equalsIgnoreCase(actualTitle))
{
System.out.println("Title match");
}
else
{ System.out.println("Title does not match");
}
// enter a valid username in the email textbox
WebElement username = driver.findElement(By.id("Email"));
username.sendKeys("Sachin1985garg@gmail.com");
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
WebElement Nextbutton= driver.findElement(By.id("next"));
Nextbutton.click();
WebElement Password = driver.findElement(By.id("Passwd"));
Password.sendKeys("Success07");
// click on the Sign in button
WebElement SignInButton = driver.findElement(By.id("signIn"));
SignInButton.click();
// close the web browser
driver.close();
System.out.println("Test script executed successfully.");
// terminate the program
System.exit(0);
}
}
---------------------------------------------------------------------------------------
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;
public class gmail {
/**
* @param args
*/
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com");
driver.manage().window().maximize();
String actualTitle = driver.getTitle();
String expected="Sign in - Google Accounts";
if(expected.equalsIgnoreCase(actualTitle))
{
System.out.println("Title match");
}
else
{ System.out.println("Title does not match");
}
// enter a valid username in the email textbox
WebElement username = driver.findElement(By.id("Email"));
username.sendKeys(" user email id");
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
WebElement Nextbutton= driver.findElement(By.id("next"));
Nextbutton.click();
WebElement Password = driver.findElement(By.id("Passwd"));
Password.sendKeys("your password");
// click on the Sign in button
WebElement SignInButton = driver.findElement(By.id("signIn"));
SignInButton.click();
// close the web browser
driver.close();
System.out.println("Test script executed successfully.");
// terminate the program
System.exit(0);
}//Closed main functionality
}//closed classes
Same program can be run through testng after few modification inside the code.
package demo_Testng;
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.testng.annotations.Test;
public class demo {
WebDriver driver = new FirefoxDriver();
@Test
public void f() {
driver.get("https://accounts.google.com");
driver.manage().window().maximize();
String actualTitle = driver.getTitle();
String expected="Sign in - Google Accounts";
if(expected.equalsIgnoreCase(actualTitle))
{
System.out.println("Title match");
}
else
{ System.out.println("Title does not match");
}
// enter a valid username in the email textbox
WebElement username = driver.findElement(By.id("Email"));
username.sendKeys("Sachin1985garg@gmail.com");
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
WebElement Nextbutton= driver.findElement(By.id("next"));
Nextbutton.click();
WebElement Password = driver.findElement(By.id("Passwd"));
Password.sendKeys("Success07");
// click on the Sign in button
WebElement SignInButton = driver.findElement(By.id("signIn"));
SignInButton.click();
// close the web browser
driver.close();
System.out.println("Test script executed successfully.");
// terminate the program
System.exit(0);
}
}
No comments:
Post a Comment