If you have just started with Selenium and struggling with creating and executing your first test case, here's a script to Login to Gmail using Selenium Webdriver.
Once you Login to Gmail using Selenium Webdriver you will get enough confidence to move on further and automate whatever you like:
Here's the code to automate Login to Gmail using Selenium Webdriver:
package automationFramework;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstTestCase {
public static void main(String[] args) throws Exception {
// Create a new instance of the Firefox driver
WebDriver driver = new ChromeDriver();
//Launch the Online Store Website
driver.get("http://www.gmail.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website gmail.com");
//Wait for 5 Sec
Thread.sleep(5);
//Maximize window
driver.manage().window().maximize();
//Enter Username
driver.findElement(By.id("Email")).sendKeys("ishan.shukl@tolexo.com");
//Click on Next
driver.findElement(By.id("next")).click();
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
//Enter Password
driver.findElement(By.id("Passwd")).sendKeys("Wolverine@123");
// Click on 'Sign In' button
driver.findElement(By.id("signIn")).click();
// Close the driver
//driver.quit();
}
}
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstTestCase {
public static void main(String[] args) throws Exception {
// Create a new instance of the Firefox driver
WebDriver driver = new ChromeDriver();
//Launch the Online Store Website
driver.get("http://www.gmail.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website gmail.com");
//Wait for 5 Sec
Thread.sleep(5);
//Maximize window
driver.manage().window().maximize();
//Enter Username
driver.findElement(By.id("Email")).sendKeys("ishan.shukl@tolexo.com");
//Click on Next
driver.findElement(By.id("next")).click();
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
//Enter Password
driver.findElement(By.id("Passwd")).sendKeys("Wolverine@123");
// Click on 'Sign In' button
driver.findElement(By.id("signIn")).click();
// Close the driver
//driver.quit();
}
}
Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!
ReplyDeleteOnline training in USA
This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up selenium Online Training
ReplyDeleteSelenium allows the end users to share and write extensions or other code modifications, even the ones that are project specific. This gives ample freedom to selenium testing companies to write custom functions that do sophisticated manipulations. Using such custom functions allows tester to have more readable tests. Selenium Automation Training London
ReplyDeletePlease note that gmail don't allow to login through selenium script for security reasons how did you resolved this issue ?
ReplyDeleteThis is an old post from 2015. That time Gmail wasn't that secure with features like captcha, multi-factor authentication etc.
Delete