|
| 1 | +package com.crossover.e2e; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.io.FileReader; |
| 5 | +import java.util.Properties; |
| 6 | +import junit.framework.TestCase; |
| 7 | +import org.junit.Test; |
| 8 | +import org.openqa.selenium.*; |
| 9 | +import org.openqa.selenium.chrome.ChromeDriver; |
| 10 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
| 11 | +import org.openqa.selenium.support.ui.WebDriverWait; |
| 12 | + |
| 13 | + |
| 14 | +public class GMailTest extends TestCase { |
| 15 | + private WebDriver driver; |
| 16 | + private Properties properties = new Properties(); |
| 17 | + private WebDriverWait wait; |
| 18 | + |
| 19 | + public void setUp() throws Exception { |
| 20 | + |
| 21 | + properties.load(new FileReader(new File("src/test/resources/test.properties"))); |
| 22 | + //Dont Change below line. Set this value in test.properties file incase you need to change it.. |
| 23 | + System.setProperty("webdriver.chrome.driver",properties.getProperty("webdriver.chrome.driver") ); |
| 24 | + driver = new ChromeDriver(); |
| 25 | + driver.manage().window().maximize(); |
| 26 | + wait = new WebDriverWait(driver,20); |
| 27 | + } |
| 28 | + |
| 29 | + public void tearDown() { |
| 30 | + driver.quit(); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testSendEmail() { |
| 35 | + driver.get("https://mail.google.com/"); |
| 36 | + |
| 37 | + //Enter User Name read from the properties file |
| 38 | + WebElement userElement = driver.findElement(By.id("identifierId")); |
| 39 | + String userName = properties.getProperty("username"); |
| 40 | + userElement.sendKeys(userName); |
| 41 | + |
| 42 | + //Click next |
| 43 | + driver.findElement(By.id("identifierNext")).click(); |
| 44 | + |
| 45 | + //Enter Password read from the properties file |
| 46 | + By passwordElementIdentifier = By.name("password"); |
| 47 | + wait.until(ExpectedConditions.presenceOfElementLocated(passwordElementIdentifier)); |
| 48 | + WebElement passwordElement = driver.findElement(passwordElementIdentifier); |
| 49 | + String passwordValue = properties.getProperty("password"); |
| 50 | + passwordElement.sendKeys(passwordValue); |
| 51 | + wait.until(ExpectedConditions.presenceOfElementLocated(By.id("passwordNext"))); |
| 52 | + driver.findElement(By.id("passwordNext")).click(); |
| 53 | + |
| 54 | + //Click Compose |
| 55 | + By composeElementIdentifier = By.xpath("//*[@role='button' and (.)='Compose']"); |
| 56 | + wait.until(ExpectedConditions.presenceOfElementLocated(composeElementIdentifier)); |
| 57 | + driver.findElement(composeElementIdentifier).click(); |
| 58 | + |
| 59 | + By toFieldIdentifier = By.name("to"); |
| 60 | + wait.until(ExpectedConditions.presenceOfElementLocated(toFieldIdentifier)); |
| 61 | + WebElement txtBoxToField = driver.findElement(toFieldIdentifier); |
| 62 | + txtBoxToField.clear(); |
| 63 | + String toUserValue = properties.getProperty("username"); |
| 64 | + txtBoxToField.sendKeys(String.format("%s@gmail.com",toUserValue)); |
| 65 | + |
| 66 | + // emailSubject and emailbody to be used in this unit test. |
| 67 | + String emailSubject = properties.getProperty("email.subject"); |
| 68 | + String emailBody = properties.getProperty("email.body"); |
| 69 | + |
| 70 | + //Enter subject |
| 71 | + By subjectBoxIdentifier = By.name("subjectbox"); |
| 72 | + wait.until(ExpectedConditions.presenceOfElementLocated(subjectBoxIdentifier)); |
| 73 | + WebElement subjectBox = driver.findElement(subjectBoxIdentifier); |
| 74 | + subjectBox.clear(); |
| 75 | + subjectBox.sendKeys(emailSubject); |
| 76 | + |
| 77 | + //Enter email body |
| 78 | + driver.findElement(By.xpath("//div[@class='Am Al editable LW-avf']")).clear(); |
| 79 | + driver.findElement(By.xpath("//div[@class='Am Al editable LW-avf']")).sendKeys(emailBody); |
| 80 | + |
| 81 | + //Click More settings |
| 82 | + wait.until(ExpectedConditions.presenceOfElementLocated( |
| 83 | + By.xpath("//div[@class='J-JN-M-I J-J5-Ji Xv L3 T-I-ax7 T-I']/div[2]"))).click(); |
| 84 | + wait.until(ExpectedConditions.presenceOfElementLocated( |
| 85 | + By.xpath("//span[@class='J-Ph-hFsbo']"))).click(); |
| 86 | + |
| 87 | + //Choose Social label |
| 88 | + wait.until(ExpectedConditions.presenceOfElementLocated( |
| 89 | + By.xpath("//div[@class='J-LC-Jz' and text()='Social']/div[@class='J-LC-Jo J-J5-Ji']"))).click(); |
| 90 | + wait.until(ExpectedConditions.presenceOfElementLocated( |
| 91 | + By.xpath("//div[@class='J-JK-Jz' and text()='Apply']"))).click(); |
| 92 | + |
| 93 | + //Click Send |
| 94 | + driver.findElement(By.xpath("//*[@role='button' and text()='Send']")).click(); |
| 95 | + |
| 96 | + //Click Social Tab |
| 97 | + wait.until(ExpectedConditions.presenceOfElementLocated( |
| 98 | + By.xpath("//div[@class='aKz' and text()='Social']"))).click(); |
| 99 | + |
| 100 | + //Thread.sleep(5000); |
| 101 | + wait.until(ExpectedConditions.presenceOfElementLocated( |
| 102 | + By.xpath("//table[@class='F cf zt']/tbody/tr[1]/td[3]/span"))); |
| 103 | + |
| 104 | + try{ |
| 105 | + driver.findElement(By.xpath("//table[@class='F cf zt']/tbody/tr[1]/td[3]/span")).click(); |
| 106 | + }catch (ElementNotVisibleException e){ |
| 107 | + driver.findElements(By.xpath("//table[@class='F cf zt']/tbody/tr[1]/td[3]/span")).get(1).click(); |
| 108 | + } |
| 109 | + |
| 110 | + //Open the received email |
| 111 | + try { |
| 112 | + driver.findElement(By.xpath("//table[@class='F cf zt']/tbody/tr[1]")).click(); |
| 113 | + }catch (ElementNotVisibleException e){ |
| 114 | + driver.findElements(By.xpath("//table[@class='F cf zt']/tbody/tr[1]")).get(1).click(); |
| 115 | + } |
| 116 | + |
| 117 | + //Verify email came under proper Label i.e. "Social" |
| 118 | + try{ |
| 119 | + driver.findElement(By.xpath("//div[@class='T-I J-J5-Ji T-I-Js-Gs mA mw T-I-ax7 L3']")).click(); |
| 120 | + }catch (ElementNotVisibleException e) { |
| 121 | + driver.findElements(By.xpath("//div[@class='T-I J-J5-Ji T-I-Js-Gs mA mw T-I-ax7 L3']")).get(1).click(); |
| 122 | + } |
| 123 | + |
| 124 | + String isSocialLabelChecked = driver.findElement(By.xpath("//div[@class='J-LC J-Ks-KO J-LC-JR-Jp']")) |
| 125 | + .getAttribute("aria-checked"); |
| 126 | + assertEquals("true", isSocialLabelChecked); |
| 127 | + |
| 128 | + //Verify the subject and body of the received email |
| 129 | + String subjectOfReceivedEmail = wait.until(ExpectedConditions.presenceOfElementLocated( |
| 130 | + By.xpath("//h2[@class='hP']"))).getText(); |
| 131 | + assertEquals(emailSubject, subjectOfReceivedEmail); |
| 132 | + |
| 133 | + String bodyOfReceivedEmail = wait.until(ExpectedConditions.presenceOfElementLocated( |
| 134 | + By.xpath("//div[@class='a3s aXjCH ']"))).getText(); |
| 135 | + assertEquals(emailBody, bodyOfReceivedEmail); |
| 136 | + } |
| 137 | +} |
0 commit comments