package kr.ne.outsider.demo2;

import org.openqa.selenium.By;
import org.testng.annotations.Test;
 
public class WebmailTest extends WebDriverTestBase {
 
	//variables
	public static final String YAHOO_EMAIL = "이메일주소@yahoo.co.kr";
	public static final String HOTMAIL_EMAIL = "이메일주소@live.com";
 
	@Test(description = "Sends an e-mail from Yahoo account")
	public void sendFromYahoo() {
		//new message variables
		String to = HOTMAIL_EMAIL;
		String subject = "Test Sending Email Message From Yahoo";
		String message = "This is a test e-mail from Yahoo";
 
		//login to yahoo
		driver.get("http://mail.yahoo.com/");
		driver.findElement(By.id("username")).sendKeys(YAHOO_EMAIL);
		driver.findElement(By.id("passwd")).sendKeys("암호");
		driver.findElement(By.id(".save")).click();
 
		//create new message
		driver.findElement(By.id("compose_button_label")).click();
		wait.until(new VisibilityOfElementLocated(By.xpath("id('_testTo_label')/ancestor::tr[1]//textarea")));
 
		//send test message
		driver.findElement(By.xpath("id('_testTo_label')/ancestor::tr[1]//textarea")).sendKeys(to);
		driver.findElement(By.xpath("id('_testSubject_label')/ancestor::tr[1]//input")).sendKeys(subject);
		driver.switchTo().frame("compArea_test_");
		driver.findElement(By.xpath("//div")).sendKeys(message);
		driver.switchTo().defaultContent();
		driver.findElement(By.id("SendMessageButton_label")).click();
		//WARNING! sometimes a captcha is displayed here
		wait.until(new VisibilityOfElementLocated(By.xpath("//nobr[contains(text(), 'Message Sent')]")));
	}
 
	@Test(description = "Sends an e-mail from Hotmail account")
	public void sendFromHotmail() {
		//new message variables
		String to = YAHOO_EMAIL;
		String subject = "Test Sending Email Message From Hotmail";
		String message = "This is a test e-mail from Hotmail";
 
		//login to hotmail
		driver.get("http://mail.live.com/");
		driver.findElement(By.name("login")).sendKeys(HOTMAIL_EMAIL);
		driver.findElement(By.name("passwd")).sendKeys("암호");
		if (driver.findElement(By.name("remMe")).isSelected()) {
			driver.findElement(By.name("remMe")).click();
		}
		driver.findElement(By.name("SI")).click();
 
		//create new message
		driver.findElement(By.id("NewMessage")).click();
 
		//send test message
		driver.switchTo().frame("UIFrame");
		driver.findElement(By.id("AutoCompleteTo$InputBox")).sendKeys(to);
		driver.findElement(By.id("fSubject")).sendKeys(subject);
		driver.switchTo().frame("UIFrame.1");
		driver.findElement(By.xpath("//body")).sendKeys(message);
		driver.switchTo().frame("UIFrame");
		driver.findElement(By.id("SendMessage")).click();
		
		assertEquals(driver.findElement(By.cssSelector("h1.SmcHeaderColor")).getText(), "메시지 전송 완료");
	}
 
}