-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGmail.java
More file actions
85 lines (62 loc) · 3.63 KB
/
Gmail.java
File metadata and controls
85 lines (62 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//package Test.Gmail;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Gmail {
public static void main(String[] args) {
//System.setProperty("webdriver.firefox.marionette", "C:\\Users\\samkitjain\\Downloads\\geckodriver-v0.16.1-win64\\geckodriver.exe");
//driver =new FirefoxDriver();
System.setProperty("webdriver.chrome.driver", "C:\\Users\\samkitjain\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait myWait = new WebDriverWait(driver,10) ;
// And now use this to visit Gmail
driver.get("https://www.google.com/gmail/about/#");
// Alternatively the same thing can be done like this
// driver.navigate().to("https://www.google.com/gmail/about/#");
WebElement signin = driver.findElement(By.linkText("SIGN IN"));
signin.click();
WebElement username = driver.findElement(By.xpath("//*[@id='identifierId']"));
//enter username
username.sendKeys("dummya481@gmail.com");
username.submit();
//next
driver.findElement(By.xpath("//*[@id='identifierNext']/content")).click();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
//delay for password to arrive using the visibility of password tag
myWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='password']/div[1]/div/div[1]/input")));
WebElement password = driver.findElement(By.xpath("//*[@id='password']/div[1]/div/div[1]/input"));
password.sendKeys("asdfghjkl@12345");
password.submit();
//clicking next
driver.findElement(By.xpath("//*[@id='passwordNext']")).click();
myWait.until(ExpectedConditions.titleContains("Inbox"));
System.out.println("Page title is: " + driver.getTitle());
//getting initial count
String inbox = driver.getTitle();
int count1 = Integer.parseInt(inbox.substring(inbox.indexOf('(')+1,inbox.indexOf(')')));
System.out.println(count1);
WebElement compose = driver.findElement(By.xpath("//*[(text()='COMPOSE')]"));
compose.click();
//wait till the compose dialog box appears
myWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='Send']")));
driver.findElement(By.name("to")).sendKeys("dummya481@gmail.com");
driver.findElement(By.name("subjectbox")).sendKeys("Samkit - Test Script ");
// finding xpath using contains
driver.findElement(By.xpath("//*[contains(@class,'Am Al editable LW-avf')]")).sendKeys("First script in java");
driver.findElement(By.xpath("//*[text()='Send']")).click();
//wait until value changed to count +1
myWait.until(ExpectedConditions.titleContains(Integer.toString(count1+1)));
String inbox2 = driver.getTitle();
int count2 = Integer.parseInt(inbox2.substring(inbox2.indexOf('(')+1,inbox2.indexOf(')')));
System.out.println(inbox2);
if(count2-count1==1)System.out.println("Successful");
else System.out.println("Not Successful");
driver.findElement(By.xpath("//*[contains(@class,'T-I J-J5-Ji nu T-I-ax7 L3')]")).click();
// driver.quit();
}
}