package org.expressolivre.cte.pages.calendar; import java.util.Set; import org.expressolivre.cte.pages.email.MailPage; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; /** * @author L.F.Estivalet (Serpro) * * Created on Aug 18, 2011 at 1:55:51 PM * */ public class AppointmentEmailPage extends MailPage { @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[2]/td/div[1]/div[1]/span/table[2]/tbody/tr[2]/td[5]/form/input") private WebElement delegateAppointmentButton; @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[2]/td/div[1]/div[1]/span/table[2]/tbody/tr[2]/td[6]/form/input") private WebElement appointmentAlarmManagerButton; public AppointmentEmailPage(WebDriver driver) { super(driver); // TODO Auto-generated constructor stub } public AppointmentStatusPage accept(String id) { // Get current windows final Set beforeHandles = driver.getWindowHandles(); // click action that cause new window to open driver.findElement( By.xpath("//div[@id='body_" + id + "_r']/span/table[2]/tbody/tr[2]/td[2]/input")) .click(); // wait for the new window to open new WebDriverWait(driver, 100) { }.until(new ExpectedCondition() { public Boolean apply(WebDriver driver) { return (driver.getWindowHandles().size() > beforeHandles.size()) ? true : false; } }); // Get after handles Set afterHandles = driver.getWindowHandles(); // remove all before handles from after. Leaves you with new window // handle afterHandles.removeAll(beforeHandles); // Switch to the new window String newWindowHandle = afterHandles.iterator().next(); driver.switchTo().window(newWindowHandle); driver.switchTo().defaultContent(); return PageFactory.initElements(driver, AppointmentStatusPage.class); } public AppointmentStatusPage reject(String id) { // Get current windows final Set beforeHandles = driver.getWindowHandles(); // click action that cause new window to open driver.findElement( By.xpath("//div[@id='body_" + id + "_r']/span/table[2]/tbody/tr[2]/td[3]/input")) .click(); // wait for the new window to open new WebDriverWait(driver, 100) { }.until(new ExpectedCondition() { public Boolean apply(WebDriver driver) { return (driver.getWindowHandles().size() > beforeHandles.size()) ? true : false; } }); // Get after handles Set afterHandles = driver.getWindowHandles(); // remove all before handles from after. Leaves you with new window // handle afterHandles.removeAll(beforeHandles); // Switch to the new window String newWindowHandle = afterHandles.iterator().next(); driver.switchTo().window(newWindowHandle); driver.switchTo().defaultContent(); return PageFactory.initElements(driver, AppointmentStatusPage.class); } public AppointmentStatusPage tentative(String id) { // Get current windows final Set beforeHandles = driver.getWindowHandles(); // click action that cause new window to open driver.findElement( By.xpath("//div[@id='body_" + id + "_r']/span/table[2]/tbody/tr[2]/td[4]/input")) .click(); // wait for the new window to open new WebDriverWait(driver, 100) { }.until(new ExpectedCondition() { public Boolean apply(WebDriver driver) { return (driver.getWindowHandles().size() > beforeHandles.size()) ? true : false; } }); // Get after handles Set afterHandles = driver.getWindowHandles(); // remove all before handles from after. Leaves you with new window // handle afterHandles.removeAll(beforeHandles); // Switch to the new window String newWindowHandle = afterHandles.iterator().next(); driver.switchTo().window(newWindowHandle); driver.switchTo().defaultContent(); return PageFactory.initElements(driver, AppointmentStatusPage.class); } public AppointmentViewPage viewAppointment(String id) { driver.findElement( By.xpath("//div[@id='body_" + id + "_r']/span/table[2]/tbody/tr[2]/td[1]/form/input")) .click(); return PageFactory.initElements(driver, AppointmentViewPage.class); } }