1 | package org.expressolivre.cte.pages.calendar; |
---|
2 | |
---|
3 | import java.util.Set; |
---|
4 | |
---|
5 | import org.expressolivre.cte.pages.email.MailPage; |
---|
6 | import org.openqa.selenium.By; |
---|
7 | import org.openqa.selenium.WebDriver; |
---|
8 | import org.openqa.selenium.WebElement; |
---|
9 | import org.openqa.selenium.support.FindBy; |
---|
10 | import org.openqa.selenium.support.PageFactory; |
---|
11 | import org.openqa.selenium.support.ui.ExpectedCondition; |
---|
12 | import org.openqa.selenium.support.ui.WebDriverWait; |
---|
13 | |
---|
14 | /** |
---|
15 | * @author L.F.Estivalet (Serpro) |
---|
16 | * |
---|
17 | * Created on Aug 18, 2011 at 1:55:51 PM |
---|
18 | * |
---|
19 | */ |
---|
20 | public class AppointmentEmailPage extends MailPage { |
---|
21 | |
---|
22 | @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") |
---|
23 | private WebElement delegateAppointmentButton; |
---|
24 | |
---|
25 | @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") |
---|
26 | private WebElement appointmentAlarmManagerButton; |
---|
27 | |
---|
28 | public AppointmentEmailPage(WebDriver driver) { |
---|
29 | super(driver); |
---|
30 | // TODO Auto-generated constructor stub |
---|
31 | } |
---|
32 | |
---|
33 | public AppointmentStatusPage accept(String id) { |
---|
34 | // Get current windows |
---|
35 | final Set<String> beforeHandles = driver.getWindowHandles(); |
---|
36 | |
---|
37 | // click action that cause new window to open |
---|
38 | driver.findElement( |
---|
39 | By.xpath("//div[@id='body_" + id |
---|
40 | + "_r']/span/table[2]/tbody/tr[2]/td[2]/input")) |
---|
41 | .click(); |
---|
42 | |
---|
43 | // wait for the new window to open |
---|
44 | new WebDriverWait(driver, 100) { |
---|
45 | }.until(new ExpectedCondition<Boolean>() { |
---|
46 | public Boolean apply(WebDriver driver) { |
---|
47 | return (driver.getWindowHandles().size() > beforeHandles.size()) ? true |
---|
48 | : false; |
---|
49 | } |
---|
50 | }); |
---|
51 | |
---|
52 | // Get after handles |
---|
53 | Set<String> afterHandles = driver.getWindowHandles(); |
---|
54 | // remove all before handles from after. Leaves you with new window |
---|
55 | // handle |
---|
56 | afterHandles.removeAll(beforeHandles); |
---|
57 | // Switch to the new window |
---|
58 | String newWindowHandle = afterHandles.iterator().next(); |
---|
59 | driver.switchTo().window(newWindowHandle); |
---|
60 | driver.switchTo().defaultContent(); |
---|
61 | |
---|
62 | return PageFactory.initElements(driver, AppointmentStatusPage.class); |
---|
63 | } |
---|
64 | |
---|
65 | public AppointmentStatusPage reject(String id) { |
---|
66 | // Get current windows |
---|
67 | final Set<String> beforeHandles = driver.getWindowHandles(); |
---|
68 | |
---|
69 | // click action that cause new window to open |
---|
70 | driver.findElement( |
---|
71 | By.xpath("//div[@id='body_" + id |
---|
72 | + "_r']/span/table[2]/tbody/tr[2]/td[3]/input")) |
---|
73 | .click(); |
---|
74 | |
---|
75 | // wait for the new window to open |
---|
76 | new WebDriverWait(driver, 100) { |
---|
77 | }.until(new ExpectedCondition<Boolean>() { |
---|
78 | public Boolean apply(WebDriver driver) { |
---|
79 | return (driver.getWindowHandles().size() > beforeHandles.size()) ? true |
---|
80 | : false; |
---|
81 | } |
---|
82 | }); |
---|
83 | |
---|
84 | // Get after handles |
---|
85 | Set<String> afterHandles = driver.getWindowHandles(); |
---|
86 | // remove all before handles from after. Leaves you with new window |
---|
87 | // handle |
---|
88 | afterHandles.removeAll(beforeHandles); |
---|
89 | // Switch to the new window |
---|
90 | String newWindowHandle = afterHandles.iterator().next(); |
---|
91 | driver.switchTo().window(newWindowHandle); |
---|
92 | driver.switchTo().defaultContent(); |
---|
93 | |
---|
94 | return PageFactory.initElements(driver, AppointmentStatusPage.class); |
---|
95 | } |
---|
96 | |
---|
97 | public AppointmentStatusPage tentative(String id) { |
---|
98 | // Get current windows |
---|
99 | final Set<String> beforeHandles = driver.getWindowHandles(); |
---|
100 | |
---|
101 | // click action that cause new window to open |
---|
102 | driver.findElement( |
---|
103 | By.xpath("//div[@id='body_" + id |
---|
104 | + "_r']/span/table[2]/tbody/tr[2]/td[4]/input")) |
---|
105 | .click(); |
---|
106 | |
---|
107 | // wait for the new window to open |
---|
108 | new WebDriverWait(driver, 100) { |
---|
109 | }.until(new ExpectedCondition<Boolean>() { |
---|
110 | public Boolean apply(WebDriver driver) { |
---|
111 | return (driver.getWindowHandles().size() > beforeHandles.size()) ? true |
---|
112 | : false; |
---|
113 | } |
---|
114 | }); |
---|
115 | |
---|
116 | // Get after handles |
---|
117 | Set<String> afterHandles = driver.getWindowHandles(); |
---|
118 | // remove all before handles from after. Leaves you with new window |
---|
119 | // handle |
---|
120 | afterHandles.removeAll(beforeHandles); |
---|
121 | // Switch to the new window |
---|
122 | String newWindowHandle = afterHandles.iterator().next(); |
---|
123 | driver.switchTo().window(newWindowHandle); |
---|
124 | driver.switchTo().defaultContent(); |
---|
125 | |
---|
126 | return PageFactory.initElements(driver, AppointmentStatusPage.class); |
---|
127 | } |
---|
128 | |
---|
129 | public AppointmentViewPage viewAppointment(String id) { |
---|
130 | driver.findElement( |
---|
131 | By.xpath("//div[@id='body_" + id |
---|
132 | + "_r']/span/table[2]/tbody/tr[2]/td[1]/form/input")) |
---|
133 | .click(); |
---|
134 | return PageFactory.initElements(driver, AppointmentViewPage.class); |
---|
135 | } |
---|
136 | |
---|
137 | } |
---|