1 package com.atlassian.pageobjects.elements;
2
3 import com.atlassian.webdriver.AtlassianWebDriver;
4 import org.openqa.selenium.Keys;
5 import org.openqa.selenium.interactions.Action;
6 import org.openqa.selenium.interactions.Actions;
7
8 import javax.inject.Inject;
9
10 import static com.atlassian.pageobjects.elements.WebDriverElement.getWebElement;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class PageElementActions
26 {
27
28 @Inject
29 private AtlassianWebDriver webDriver;
30
31 private Actions actions;
32
33 private Actions getActions()
34 {
35 if (actions == null)
36 {
37 actions = new Actions(webDriver.getDriver());
38 }
39 return actions;
40 }
41
42
43
44
45 public PageElementActions keyDown(Keys theKey)
46 {
47 getActions().keyDown(theKey);
48 return this;
49 }
50
51
52
53
54 public PageElementActions keyDown(PageElement element, Keys theKey)
55 {
56 getActions().keyDown(getWebElement(element), theKey);
57 return this;
58 }
59
60
61
62
63 public PageElementActions keyUp(Keys theKey)
64 {
65 getActions().keyUp(theKey);
66 return this;
67 }
68
69
70
71
72 public PageElementActions keyUp(PageElement element, Keys theKey)
73 {
74 getActions().keyUp(getWebElement(element), theKey);
75 return this;
76 }
77
78
79
80
81 public PageElementActions sendKeys(CharSequence... keysToSend)
82 {
83 getActions().sendKeys(keysToSend);
84 return this;
85 }
86
87
88
89
90 public PageElementActions sendKeys(PageElement element, CharSequence... keysToSend)
91 {
92 getActions().sendKeys(getWebElement(element), keysToSend);
93 return this;
94 }
95
96
97
98
99 public PageElementActions clickAndHold(PageElement onElement)
100 {
101 getActions().clickAndHold(getWebElement(onElement));
102 return this;
103 }
104
105
106
107
108 public PageElementActions clickAndHold()
109 {
110 getActions().clickAndHold();
111 return this;
112 }
113
114
115
116
117 public PageElementActions release(PageElement onElement)
118 {
119 getActions().release(getWebElement(onElement));
120 return this;
121 }
122
123
124
125
126 public PageElementActions release()
127 {
128 getActions().release();
129 return this;
130 }
131
132
133
134
135 public PageElementActions click(PageElement onElement)
136 {
137 getActions().click(getWebElement(onElement));
138 return this;
139 }
140
141
142
143
144 public PageElementActions click() {
145 getActions().click();
146 return this;
147 }
148
149
150
151
152 public PageElementActions doubleClick(PageElement onElement)
153 {
154 getActions().doubleClick(getWebElement(onElement));
155 return this;
156 }
157
158
159
160
161 public PageElementActions doubleClick()
162 {
163 getActions().doubleClick();
164 return this;
165 }
166
167
168
169
170 public PageElementActions moveToElement(PageElement toElement)
171 {
172 getActions().moveToElement(getWebElement(toElement));
173 return this;
174 }
175
176
177
178
179 public PageElementActions moveToElement(PageElement toElement, int xOffset, int yOffset)
180 {
181 getActions().moveToElement(getWebElement(toElement), xOffset, yOffset);
182 return this;
183 }
184
185
186
187
188 public PageElementActions moveByOffset(int xOffset, int yOffset)
189 {
190 getActions().moveByOffset(xOffset, yOffset);
191 return this;
192 }
193
194
195
196
197 public PageElementActions contextClick(PageElement onElement)
198 {
199 getActions().contextClick(getWebElement(onElement));
200 return this;
201 }
202
203
204
205
206 public PageElementActions dragAndDrop(PageElement source, PageElement target)
207 {
208 getActions().dragAndDrop(getWebElement(source), getWebElement(target));
209 return this;
210 }
211
212
213
214
215 public PageElementActions dragAndDropBy(PageElement source, int xOffset, int yOffset) {
216 getActions().dragAndDropBy(getWebElement(source), xOffset, yOffset);
217 return this;
218 }
219
220
221
222
223
224
225 Action build()
226 {
227 return getActions().build();
228 }
229
230
231
232
233 public void perform()
234 {
235 getActions().perform();
236 }
237
238
239
240
241
242
243 public PageElementActions reset()
244 {
245 getActions().build();
246 return this;
247 }
248 }