Thursday, August 21, 2008

Gmail using Selenium RC


{
// Login to Gmail and get the link
try
{
selenium.Open("http://www.gmail.com"); // Open Gmail Webpage
selenium.WaitForPageToLoad(sel_TimeOut);
selenium.WindowMaximize();
if (selenium.IsElementPresent("//a[contains(text(),'Sign out')]")) // If Already logged on, logout first
{
selenium.Click("//a[contains(text(),'Sign out')]");
selenium.WaitForPageToLoad(sel_TimeOut);
}
selenium.Type("//input[contains(@id,'Email')]", inv_InviteEmailAddress); // Enter Gamil User Account. GAMIL account should be set with HTML view
selenium.Type("//input[contains(@id,'Passwd')]", inv_InviteEmailPassword); // Enter Gmail Password
selenium.Click("//input[contains(@name,'signIn')]"); // Click on Gmail Sign In button
selenium.WaitForPageToLoad(sel_TimeOut); // Wait for web page to load. If page dont load after timeout test is failed
Thread.Sleep(Int32.Parse(com_UserThinkTime)); // Time taken by user to take action after page is loaded
selenium.Click("//*[contains(text(),'" + inv_InviteEmailSubject + "')]"); // Click on email with subject as pointed by variable inv_InviteEmailSubject
selenium.WaitForPageToLoad(sel_TimeOut); // Wait for web page to load. If page dont load after timeout test is failed
Thread.Sleep(Int32.Parse(com_UserThinkTime)); // Time taken by user to take action after page is loaded
selenium.Click("//a[contains(text(),'" + inv_InviteEmailRegisterLinkText + "')]"); // Click on link with text as pointed by variable inv_InviteEmailRegisterLinkText
selenium.WaitForPopUp(selenium.GetAllWindowNames()[1], sel_TimeOut);
selenium.SelectWindow(selenium.GetAllWindowNames()[1]);
selenium.WindowMaximize();
selenium.Type("//input[contains(@id,'user_password')]", inv_InviteEmailPassword); // Enter password
selenium.Type("//input[contains(@id,'user_password_confirmation')]", inv_InviteEmailPassword); // Enter password again
selenium.Check("//input[contains(@id,'terms_of_use_accepted')]"); // Accpet Terms of USe
selenium.Check("//input[contains(@id,'privacy_statement_accepted')]"); // Accept Privacy statment
Thread.Sleep(Int32.Parse(com_UserThinkTime)); // Time taken by user to take action after page is loaded
selenium.Click("//input[contains(@class,'sign_up_btn')]"); // Click on Signup button
selenium.WaitForPageToLoad(sel_TimeOut); // Wait for web page to load. If page dont load after timeout test is failed
Thread.Sleep(5000);
}
catch (SeleniumException selEx)
{
throw new Exception("GMAIL Something went wrong",selEx);
}
// End of Gmail
}

4 comments:

Vaishakh Thayyil said...

Thanks for the post .
I want to know where could I get the
plugin of selenium for using it with eclipse.

Vaishakh Thayyil said...

Could you please mention what all classes to import along with the code.Also can I use this to bypass
gmail login in my browser..

Thanks,
vaishakh

Neha said...

Hi
Could you suggest how can I capture the compose button click. I want to automate compose and send new email to the same account.

Thanks

Ravindra Ugaji said...

You can not relay on Compose button. You can try Gmail Shortcut keys instead refer (http://maketecheasier.com/useful-gmail-shortcut-keys-to-improve-your-email-checking-experience/2008/06/10)

-Ravindra