1 | package org.expressolivre.cte.pages.calendar; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | import java.util.Set; |
---|
5 | |
---|
6 | import org.expressolivre.cte.pages.common.Page; |
---|
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 17, 2011 at 9:16:01 AM |
---|
18 | * |
---|
19 | */ |
---|
20 | public class AgendaPermissionPage extends Page { |
---|
21 | |
---|
22 | /** Permitir acesso para ler compromissos da agenda. */ |
---|
23 | @FindBy(id = "user_list") |
---|
24 | private WebElement userList; |
---|
25 | |
---|
26 | /** Permitir acesso para ler compromissos da agenda. */ |
---|
27 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[2]/td[3]/table/tbody/tr[1]/td[1]/input") |
---|
28 | private WebElement read; |
---|
29 | |
---|
30 | /** Permitir acesso para adicionar compromissos da agenda. */ |
---|
31 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td[1]/input") |
---|
32 | private WebElement add; |
---|
33 | |
---|
34 | /** Permitir acesso para editar compromissos da agenda. */ |
---|
35 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[2]/td[3]/table/tbody/tr[3]/td[1]/input") |
---|
36 | private WebElement edit; |
---|
37 | |
---|
38 | /** Permitir acesso para remover compromissos da agenda. */ |
---|
39 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[2]/td[3]/table/tbody/tr[4]/td[1]/input") |
---|
40 | private WebElement remove; |
---|
41 | |
---|
42 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[2]/td[3]/table/tbody/tr[5]/td[1]/input") |
---|
43 | private WebElement restrict; |
---|
44 | |
---|
45 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[4]/td[2]/center/input[1]") |
---|
46 | private WebElement okButton; |
---|
47 | |
---|
48 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[4]/td[2]/center/input[2]") |
---|
49 | private WebElement addButton; |
---|
50 | |
---|
51 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[4]/td[2]/center/input[3]") |
---|
52 | private WebElement removeButton; |
---|
53 | |
---|
54 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/form/center/table/tbody/tr[4]/td[2]/center/input[4]") |
---|
55 | private WebElement cancelButton; |
---|
56 | |
---|
57 | public AgendaPermissionPage(WebDriver driver) { |
---|
58 | super(driver); |
---|
59 | // TODO Auto-generated constructor stub |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * Verifica se o usuario ja esta na lista de permissoes. |
---|
64 | * |
---|
65 | * @param userName |
---|
66 | * @return |
---|
67 | */ |
---|
68 | public Boolean isUserInList(String userName) { |
---|
69 | return super.isValueInCombo(this.userList, userName, true); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * Remove todos os usuarios do compartilhamento. |
---|
74 | */ |
---|
75 | public void removeAllUsers() { |
---|
76 | List<WebElement> users = super.getComboElements(this.userList); |
---|
77 | for (WebElement user : users) { |
---|
78 | user.setSelected(); |
---|
79 | this.removeButton.click(); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | * Adaptacao da solucao para lidar com janelas popups obtida em <a |
---|
85 | * href="http://groups.google.com/group |
---|
86 | * /webdriver/browse_thread/thread/038a911803f26dcd">link</a> |
---|
87 | * |
---|
88 | * @return |
---|
89 | */ |
---|
90 | public AgendaAddACLUserPage addUserACL() { |
---|
91 | // Get current windows |
---|
92 | final Set<String> beforeHandles = driver.getWindowHandles(); |
---|
93 | // click action that cause new window to open |
---|
94 | this.addButton.click(); |
---|
95 | // wait for the new window to open |
---|
96 | new WebDriverWait(driver, 30) { |
---|
97 | }.until(new ExpectedCondition<Boolean>() { |
---|
98 | public Boolean apply(WebDriver driver) { |
---|
99 | return (driver.getWindowHandles().size() > beforeHandles.size()) ? true |
---|
100 | : false; |
---|
101 | } |
---|
102 | }); |
---|
103 | |
---|
104 | // Get after handles |
---|
105 | Set<String> afterHandles = driver.getWindowHandles(); |
---|
106 | // remove all before handles from after. Leaves you with new window |
---|
107 | // handle |
---|
108 | afterHandles.removeAll(beforeHandles); |
---|
109 | // Switch to the new window |
---|
110 | String newWindowHandle = afterHandles.iterator().next(); |
---|
111 | driver.switchTo().window(newWindowHandle); |
---|
112 | |
---|
113 | return PageFactory.initElements(driver, AgendaAddACLUserPage.class); |
---|
114 | } |
---|
115 | |
---|
116 | public void setReadPermission(boolean read) { |
---|
117 | if (read && !this.read.isSelected()) { |
---|
118 | this.read.click(); |
---|
119 | } else if (!read && this.read.isSelected()) { |
---|
120 | this.read.click(); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | public void setEditPermission(boolean edit) { |
---|
125 | if (edit && !this.edit.isSelected()) { |
---|
126 | this.edit.click(); |
---|
127 | } else if (!edit && this.edit.isSelected()) { |
---|
128 | this.edit.click(); |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | public void setAddPermission(boolean add) { |
---|
133 | if (add && !this.add.isSelected()) { |
---|
134 | this.add.click(); |
---|
135 | } else if (!add && this.add.isSelected()) { |
---|
136 | this.add.click(); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | public void setRemovePermission(boolean remove) { |
---|
141 | if (remove && !this.remove.isSelected()) { |
---|
142 | this.remove.click(); |
---|
143 | } else if (!remove && this.remove.isSelected()) { |
---|
144 | this.remove.click(); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | public void setRestrictPermission(boolean restrict) { |
---|
149 | if (restrict && !this.restrict.isSelected()) { |
---|
150 | this.restrict.click(); |
---|
151 | } else if (!restrict && this.restrict.isSelected()) { |
---|
152 | this.restrict.click(); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | public void clearPemissions() { |
---|
157 | this.setReadPermission(false); |
---|
158 | this.setEditPermission(false); |
---|
159 | this.setRemovePermission(false); |
---|
160 | this.setAddPermission(false); |
---|
161 | this.setRestrictPermission(false); |
---|
162 | } |
---|
163 | |
---|
164 | public void cancel() { |
---|
165 | this.cancelButton.click(); |
---|
166 | } |
---|
167 | |
---|
168 | public void apply() { |
---|
169 | this.okButton.click(); |
---|
170 | } |
---|
171 | } |
---|