Ana içeriğe atla

Selenium Gmail Giriş, Mail Atma, Atılan Maili Kontrol Etme ve Çıkış

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();
    }
}

Yorumlar

Bu blogdaki popüler yayınlar

Selenium - XPath Kodları

XPath, XML Path Absolute XPath: root node u verir ve / ile başlar Elementin path inde herhangi bir değişiklik yapılırsa, test kodu hata verir. Örn:  html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[1]/b Relative XPath: xml dokümanındaki elementi verir ve // ile başlar Örn : //*[@class='featured-box']//*[text()='Testing'] XPath Kombinasyonları: Belli bir tagin belli bir attribute değeri ile kullanımı Herhangi bir tag in belli bir attribute değeri ile kullanımı "and" operatörü "or" operatörü Belirli bir değer ile başlayan attribute Metnin bir kısmını içeren attribute Sadece text() Herhangi bir attribute un değeri Belli Bir Tag'ın Belli Bir Attribute Değeri ile Kullanımı (Specific tag with specific attribute value) Html Kodu < input   id = "Lid"  .....   > input:tag adı (etiket adı) id : attribute Lid : attribute değeri Selenium Kodu driver.findElement(By.x...

Nutch 2.2 'yi Intellij'de Çalıştırma

          İlk olarak pom.xml'i oluşturun. pom.xml'de  <build> kısmında <sourceDirectory> bölümüne plugin'ini kaynak kod olarak göstermeniz gerekir. (ikincisi yeni eklenen plugin için gerekli) <resources>             <resource>                 <directory>${basedir}/src/plugin/SaveFile/src/java</directory>             </resource> </resources>           Ana dizindeki conf klasöründe; nutch-site.xml'e aşağıdakini ekleyin.     <property>         <name>storage.data.store.class</name>         <value>org.apache.gora.hbase.store.HB...

Selenium - Fonksiyonlar

FindElement(By by) Bu method işlem sırasında 'implicit wait' i bekler. Yani aradığı elementi implicit wait ne kadar verildiyse o kadar süre için arar, bulamazsa timeout olur,  NoSuchElementException hatası verir. FindElements(By by) Birşey bulamazsa boş liste döndürür. Bir sayfadaki bütün linkleri bulabilirsin, linkler dediği yere gidiyor mu, aktif link mi, vs. findElement.getAttribute("attribute name") Element in verilen attribute unu getirir. Yoksa boş döndürür. String value = driver.findElement(By.name("btnK")).getAttribute("value"); System.out.println("Value of search button: " + value); Value of search button: Google'da Ara findElement.getCssValue("css property") Verilen CSS özelliğinin değerini getirir; font size, renk, arka plan rengi gibi. F12 ye bastığında style kısmında dönen sonuçları doğrulatabilirsin. WebElement searchbutton = driver.findElement(By.name("btnK...