May 13, 2011

Send a Mail to Friend from Gmail

Send mail to any one from Gmail..using the below script..

Gmail is one of the complicated stuff..Record and play back will not work here..because IDs and Names of the elements are changing randomly..Here we need to use ClickAt instead of Click...and we need to use Xpaths...

Below is the script to send mail to one mail ID...

Please change your mail and password  to execute this program...



package reporting;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

public class Gmail extends SeleneseTestCase {
public SeleniumServer ss;
@Before
public void setUp() throws Exception {
ss=new SeleniumServer();
ss.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://www.google.com/");
selenium.start();
}

@Test
public void testGmail() throws Exception {
selenium.open("/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&ltmplcache=2");
selenium.windowMaximize();
selenium.type("Email", "nagaqtt");
selenium.type("Passwd", "xxxx");
selenium.click("signIn");
selenium.waitForPageToLoad("30000");
//Click the compose button
selenium.clickAt("//div[3]/div[1]/div[1]/div[1]/div/div", "");
//Enter Email ID in To field
Thread.sleep(10000);
selenium.type("to", "nagaselenium@gmail.com");
//Subject of the mail
selenium.type("subject", "testing");
Thread.sleep(1000);
selenium.selectWindow("null");
//Content in the mail
Thread.sleep(1000);
selenium.typeKeys("//html/body[@class='editable  LW-yrriRe']", "nagaraju sending mail to his friend");
//Clicking the send button
selenium.clickAt("//div[@role='button']/b", "");
Thread.sleep(10000);
//Clicking the logout
if(selenium.isElementPresent("gbi4m1"))
{
selenium.click("gbi4m1");
}

selenium.click("link=Sign out");
Thread.sleep(10000);
}

@After
public void tearDown() throws Exception {
selenium.stop();
ss.stop();
}
}




3 comments:

  1. The future of automation testing tool is on the positive tool. As the demand of quality web application keeps on increasing, the tool like Selenium IDE is getting very popular all over the world. Thus, taking Selenium Training in Chennai will help you to enter software testing industry.Best Selenium training institute in Chennai

    ReplyDelete
  2. " Gmail extends SeleneseTestCase" but where is gmail class script

    ReplyDelete