import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
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 gmailSendAndReceiveMailTest {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver-v0.23.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}
@Test
public void gmailSendAndReceiveEmailShouldBeSuccessful() throws Exception{
driver.get("http://gmail.com");
WebElement usernameTextbox = driver.findElement(By.id("identifierId"));
usernameTextbox.clear();
usernameTextbox.sendKeys("mail@gmail.com");
WebElement usernameClick = driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/content"));
usernameClick.click();
WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//input[contains(@type,'password')]")));
WebElement passwordTextbox = driver.findElement(By.xpath("//input[contains(@type,'password')]"));
passwordTextbox.clear();
passwordTextbox.sendKeys("şifre");
WebElement passwordClick = driver.findElement(By.xpath("//span[contains(@class,'RveJvd snByac')]"));
passwordClick.click();
//Aşağıda findElements kullanılmasının sebebi gelen kutusunun bir tabloya bağlı olması, bu tabloda bulunan en az bir element olmalı o da gelenkutusu, div/span/a
//a olarak belirtildiğinde link oluyor(linkage), bunda partialLinkText kullanılabilir
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.partialLinkText("Gelen Kutusu")));
Assert.assertTrue("Inbox should exist", driver.findElements(By.partialLinkText("Gelen Kutusu")).size() > 0);
WebElement composeButton = driver.findElement(By.xpath("//div[@class='T-I J-J5-Ji T-I-KE L3']"));
composeButton.click();
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//textarea[@aria-label='Alıcı']")));
WebElement toTextArea = driver.findElement(By.xpath("//textarea[@aria-label='Alıcı']"));
toTextArea.clear();
toTextArea.sendKeys("sinemayk@gmail.com");
WebElement subjectTextArea = driver.findElement(By.cssSelector("input[name='subjectbox'"));
final String subject = "Gmail Send Email Test";//Mailin konusu
subjectTextArea.clear();
subjectTextArea.sendKeys(subject);
WebElement bodyTextArea = driver.findElement(By.cssSelector("div[aria-label='İleti Gövdesi']"));
final String body = "Hello Testers Good Morning";//Mailin içeriği
bodyTextArea.clear();
bodyTextArea.sendKeys(body);
WebElement sendButton = driver.findElement(By.xpath("//div[contains(@aria-label,'Gönder')]"));
sendButton.click();
Thread.sleep(10000);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("a[aria-label='Gelen Kutusu 1 okunmamış']")));
WebElement inboxLinkage = driver.findElement(By.cssSelector("a[aria-label='Gelen Kutusu 1 okunmamış']"));
inboxLinkage.click();
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("/html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div/div[2]/div/div[1]/div/div/div/div/div/div[1]/div/div[6]/div/div[1]/div/table/tbody/tr[1]/td[6]/div/div/div/span/span")));
WebElement newEmail = driver.findElement(By.xpath("/html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div/div[2]/div/div[1]/div/div/div/div/div/div[1]/div/div[6]/div/div[1]/div/table/tbody/tr[1]/td[6]/div/div/div/span/span"));
newEmail.click();
Thread.sleep(2000);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("/html[1]/body[1]/div[7]/div[3]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tr[1]/td[1]/div[2]/div[1]/div[2]/div[1]/h2[1]")));
WebElement subjectArea = driver.findElement(By.xpath("/html[1]/body[1]/div[7]/div[3]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tr[1]/td[1]/div[2]/div[1]/div[2]/div[1]/h2[1]"));
Assert.assertEquals("Email subject should be the same", subject,subjectArea.getText());
WebElement bodyArea = driver.findElement(By.xpath("/html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div/div[2]/div/div[1]/div/div[2]/div/table/tr/td[1]/div[2]/div[2]/div/div[3]/div/div/div/div/div/div[1]/div[2]/div[3]/div[3]/div/div[1]"));
Assert.assertEquals("Body text should be the same", body,bodyArea.getText() );
WebElement profileButton = driver.findElement(By.xpath("//a[@class='gb_x gb_Da gb_f']"));
profileButton.click();
WebElement signOutLinkage = driver.findElement(By.linkText("Oturumu kapat"));
signOutLinkage.click();
}
@After
public void tearDown() {
driver.quit();
}
}
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
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 gmailSendAndReceiveMailTest {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver-v0.23.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}
@Test
public void gmailSendAndReceiveEmailShouldBeSuccessful() throws Exception{
driver.get("http://gmail.com");
WebElement usernameTextbox = driver.findElement(By.id("identifierId"));
usernameTextbox.clear();
usernameTextbox.sendKeys("mail@gmail.com");
WebElement usernameClick = driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/content"));
usernameClick.click();
WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//input[contains(@type,'password')]")));
WebElement passwordTextbox = driver.findElement(By.xpath("//input[contains(@type,'password')]"));
passwordTextbox.clear();
passwordTextbox.sendKeys("şifre");
WebElement passwordClick = driver.findElement(By.xpath("//span[contains(@class,'RveJvd snByac')]"));
passwordClick.click();
//Aşağıda findElements kullanılmasının sebebi gelen kutusunun bir tabloya bağlı olması, bu tabloda bulunan en az bir element olmalı o da gelenkutusu, div/span/a
//a olarak belirtildiğinde link oluyor(linkage), bunda partialLinkText kullanılabilir
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.partialLinkText("Gelen Kutusu")));
Assert.assertTrue("Inbox should exist", driver.findElements(By.partialLinkText("Gelen Kutusu")).size() > 0);
WebElement composeButton = driver.findElement(By.xpath("//div[@class='T-I J-J5-Ji T-I-KE L3']"));
composeButton.click();
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//textarea[@aria-label='Alıcı']")));
WebElement toTextArea = driver.findElement(By.xpath("//textarea[@aria-label='Alıcı']"));
toTextArea.clear();
toTextArea.sendKeys("sinemayk@gmail.com");
WebElement subjectTextArea = driver.findElement(By.cssSelector("input[name='subjectbox'"));
final String subject = "Gmail Send Email Test";//Mailin konusu
subjectTextArea.clear();
subjectTextArea.sendKeys(subject);
WebElement bodyTextArea = driver.findElement(By.cssSelector("div[aria-label='İleti Gövdesi']"));
final String body = "Hello Testers Good Morning";//Mailin içeriği
bodyTextArea.clear();
bodyTextArea.sendKeys(body);
WebElement sendButton = driver.findElement(By.xpath("//div[contains(@aria-label,'Gönder')]"));
sendButton.click();
Thread.sleep(10000);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("a[aria-label='Gelen Kutusu 1 okunmamış']")));
WebElement inboxLinkage = driver.findElement(By.cssSelector("a[aria-label='Gelen Kutusu 1 okunmamış']"));
inboxLinkage.click();
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("/html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div/div[2]/div/div[1]/div/div/div/div/div/div[1]/div/div[6]/div/div[1]/div/table/tbody/tr[1]/td[6]/div/div/div/span/span")));
WebElement newEmail = driver.findElement(By.xpath("/html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div/div[2]/div/div[1]/div/div/div/div/div/div[1]/div/div[6]/div/div[1]/div/table/tbody/tr[1]/td[6]/div/div/div/span/span"));
newEmail.click();
Thread.sleep(2000);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("/html[1]/body[1]/div[7]/div[3]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tr[1]/td[1]/div[2]/div[1]/div[2]/div[1]/h2[1]")));
WebElement subjectArea = driver.findElement(By.xpath("/html[1]/body[1]/div[7]/div[3]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tr[1]/td[1]/div[2]/div[1]/div[2]/div[1]/h2[1]"));
Assert.assertEquals("Email subject should be the same", subject,subjectArea.getText());
WebElement bodyArea = driver.findElement(By.xpath("/html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div/div[2]/div/div[1]/div/div[2]/div/table/tr/td[1]/div[2]/div[2]/div/div[3]/div/div/div/div/div/div[1]/div[2]/div[3]/div[3]/div/div[1]"));
Assert.assertEquals("Body text should be the same", body,bodyArea.getText() );
WebElement profileButton = driver.findElement(By.xpath("//a[@class='gb_x gb_Da gb_f']"));
profileButton.click();
WebElement signOutLinkage = driver.findElement(By.linkText("Oturumu kapat"));
signOutLinkage.click();
}
@After
public void tearDown() {
driver.quit();
}
}
Yorumlar
Yorum Gönder