Selenium WebDriver Gmail Automation (Includes Compose, verify whether email has been sent or not and get number of the unread email in inbox folder)
package zellaxSolutions.automationTesting; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class newclass { public static void main(String[] args) throws InterruptedException { String subject="Write Subject Of Testing Email !!"; WebDriver driver; driver=new FirefoxDriver(); driver.navigate().to("https://www.google.co.in/?gfe_rd=cr&ei=Gmd-VdWTD-XH8AeqsbH4Bg&gws_rd=ssl"); driver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS); driver.findElement(By.className("gb_la")).click(); // Login to Gmail driver.findElement(By.id("Email")).sendKeys("Enter Email Address (FROM)"); driver.findElement(By.id("next")).click(); driver.findElement(By.id("Passwd")).sendKeys("Enter Password"); //Click on SignIn driver.findElement(By.id("signIn")).click(); Thread.sleep(3000); //Compose Email driver.findElement(By.xpath("//div[@class='z0']/div")).click(); Thread.sleep(3000); driver.findElement(By.className("vO")).sendKeys("Enter Email Address (TO)"); Thread.sleep(3000); driver.findElement(By.className("aoT")).sendKeys(subject); Thread.sleep(3000); driver.findElement(By.xpath("//td[@class='Ap']/div[2]/div[@class='Am Al editable LW-avf']")).sendKeys("Write Text For an email.!!! :)"); Thread.sleep(3000); driver.findElement(By.xpath("//div/div[text()='Send']")).click(); Thread.sleep(3000); driver.findElement(By.xpath("//div/div/span/a[text()='Sent Mail']")).click(); // To verify whether an email has been sent or not if(driver.findElements(By.xpath("//tr/td[6]/div/div/div[2]/span/b[text()='"+subject+"']"))!=null){ System.out.println("Email Sent Successfully... :)"); } else{ System.out.println("Email Sending Failed... :("); } // To get the number of the unread emails in inbox folder driver.findElement(By.xpath("//div[@class='TN GLujEb']/div/span[@class='nU n1']/a")).click(); String inboxString=driver.findElement(By.xpath("//div[@class='aim ain']/div/div/div/span/a")).getText(); String inboxElements = inboxString.substring(inboxString.indexOf("(") + 1, inboxString.indexOf(")")); System.out.print(inboxElements); driver.close(); } }
Can you please give the example of the same using POM in maven project using selenium webdriver?
ReplyDelete