Skip to content

Commit 14d4c43

Browse files
committed
Added TouchTests
1 parent 73b63e6 commit 14d4c43

File tree

5 files changed

+274
-19
lines changed

5 files changed

+274
-19
lines changed

java/client/src/org/openqa/selenium/qtwebkit/QtWebKitDriver.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,27 @@
1818

1919
package org.openqa.selenium.qtwebkit;
2020

21+
import org.openqa.selenium.*;
2122
import org.openqa.selenium.html5.*;
22-
import org.openqa.selenium.Capabilities;
23-
import org.openqa.selenium.OutputType;
24-
import org.openqa.selenium.TakesScreenshot;
2523
import org.openqa.selenium.remote.DriverCommand;
24+
import org.openqa.selenium.remote.RemoteTouchScreen;
2625
import org.openqa.selenium.remote.RemoteWebDriver;
2726
import org.openqa.selenium.remote.html5.RemoteLocalStorage;
2827
import org.openqa.selenium.remote.html5.RemoteSessionStorage;
2928

3029

3130

32-
public class QtWebKitDriver extends RemoteWebDriver implements TakesScreenshot, WebStorage {
31+
public class QtWebKitDriver extends RemoteWebDriver implements TakesScreenshot, WebStorage, HasTouchScreen {
3332

3433
private RemoteLocalStorage localStorage;
3534
private RemoteSessionStorage sessionStorage;
35+
private TouchScreen touchScreen;
3636

3737
public QtWebKitDriver(Capabilities capabilities) {
3838
super(QtWebKitDriverService.getCommandExecutor(), capabilities);
3939
localStorage = new RemoteLocalStorage(getExecuteMethod());
4040
sessionStorage = new RemoteSessionStorage(getExecuteMethod());
41+
touchScreen = new RemoteTouchScreen(getExecuteMethod());
4142
}
4243

4344

@@ -57,5 +58,10 @@ public LocalStorage getLocalStorage() {
5758
public SessionStorage getSessionStorage() {
5859
return sessionStorage;
5960
}
61+
62+
@Override
63+
public TouchScreen getTouch() {
64+
return touchScreen;
65+
}
6066
}
6167

java/client/test/org/openqa/selenium/interactions/touch/TouchDoubleTapTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
import org.openqa.selenium.WebDriver;
2424
import org.openqa.selenium.WebElement;
2525
import org.openqa.selenium.interactions.Action;
26+
import org.openqa.selenium.testing.Ignore;
27+
import static org.openqa.selenium.testing.Ignore.Driver.QTWEBKIT;
2628

2729
/**
2830
* Tests the basic double tap operations.
2931
*/
32+
@Ignore (QTWEBKIT)
3033
public class TouchDoubleTapTest extends TouchTestBase {
3134

3235
private TouchActions getBuilder(WebDriver driver) {

java/client/test/org/openqa/selenium/interactions/touch/TouchFlickTest.java

Lines changed: 167 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@
1818
package org.openqa.selenium.interactions.touch;
1919

2020
import org.junit.Test;
21-
import org.openqa.selenium.By;
22-
import org.openqa.selenium.NeedsFreshDriver;
23-
import org.openqa.selenium.WebDriver;
24-
import org.openqa.selenium.WebElement;
21+
import org.openqa.selenium.*;
2522
import org.openqa.selenium.interactions.Action;
2623
import org.openqa.selenium.testing.Ignore;
2724

2825
import static org.junit.Assert.assertTrue;
29-
import static org.openqa.selenium.testing.Ignore.Driver.ANDROID;
30-
import static org.openqa.selenium.testing.Ignore.Driver.OPERA;
31-
import static org.openqa.selenium.testing.Ignore.Driver.OPERA_MOBILE;
26+
import static org.openqa.selenium.testing.Ignore.Driver.*;
3227

3328
/**
3429
* Tests the basic flick operations on touch enabled devices.
@@ -40,6 +35,7 @@ private TouchActions getBuilder(WebDriver driver) {
4035
return new TouchActions(driver);
4136
}
4237

38+
@Ignore(QTWEBKIT)
4339
@NeedsFreshDriver
4440
@Test
4541
public void testCanFlickHorizontallyFromWebElement() {
@@ -61,6 +57,7 @@ public void testCanFlickHorizontallyFromWebElement() {
6157
assertTrue("Expected x < 1500, but got x = " + x, x < 1500);
6258
}
6359

60+
@Ignore(QTWEBKIT)
6461
@NeedsFreshDriver
6562
@Test
6663
public void testCanFlickHorizontallyFastFromWebElement() {
@@ -81,6 +78,7 @@ public void testCanFlickHorizontallyFastFromWebElement() {
8178
assertTrue("Expected x < 3500, but got: " + x, x < 3500);
8279
}
8380

81+
@Ignore(QTWEBKIT)
8482
@NeedsFreshDriver
8583
@Test
8684
public void testCanFlickHorizontally() {
@@ -100,7 +98,7 @@ public void testCanFlickHorizontally() {
10098
assertTrue("Expected x < 1500, but got x = " + x, x < 1500);
10199
}
102100

103-
@Ignore(value = {ANDROID},
101+
@Ignore(value = {ANDROID, QTWEBKIT},
104102
reason = "Android flick's can result in different offsets")
105103
@NeedsFreshDriver
106104
@Test
@@ -120,6 +118,7 @@ public void testCanFlickHorizontallyFast() {
120118
assertTrue("Got: " + x, x < 3000);
121119
}
122120

121+
@Ignore(QTWEBKIT)
123122
@NeedsFreshDriver
124123
@Test
125124
public void testCanFlickVerticallyFromWebElement() {
@@ -140,6 +139,7 @@ public void testCanFlickVerticallyFromWebElement() {
140139
assertTrue("Expected y < 4000, but got: " + y, y < 4000);
141140
}
142141

142+
@Ignore(QTWEBKIT)
143143
@NeedsFreshDriver
144144
@Test
145145
public void testCanFlickVerticallyFastFromWebElement() {
@@ -160,6 +160,7 @@ public void testCanFlickVerticallyFastFromWebElement() {
160160
assertTrue("Expected y < 8700, but got: " + y, y < 8700);
161161
}
162162

163+
@Ignore(QTWEBKIT)
163164
@NeedsFreshDriver
164165
@Test
165166
public void testCanFlickVertically() {
@@ -179,6 +180,7 @@ public void testCanFlickVertically() {
179180
assertTrue("Got: " + y, y < 4200);
180181
}
181182

183+
@Ignore(QTWEBKIT)
182184
@NeedsFreshDriver
183185
@Test
184186
public void testCanFlickVerticallyFast() {
@@ -197,4 +199,161 @@ public void testCanFlickVerticallyFast() {
197199
assertTrue("Got: " + y, y < 4000);
198200
}
199201

202+
@NeedsFreshDriver
203+
@Test
204+
public void testCanFlickHorizontallyFromWebElementQt() {
205+
driver.get(pages.longContentPage);
206+
207+
WebElement toFlick = driver.findElement(By.id("imagestart"));
208+
WebElement link = driver.findElement(By.id("link1"));
209+
int x = link.getLocation().x;
210+
// The element is located at the right of the page,
211+
// so it is not initially visible on the screen.
212+
assertTrue("Expected x > 1500, but got x = " + x, x > 1500);
213+
214+
Action flick = getBuilder(driver).flick(toFlick, -1000, 0, FlickAction.SPEED_NORMAL)
215+
.build();
216+
flick.perform();
217+
218+
x = ((Long)((JavascriptExecutor) driver).executeScript("return document.body.scrollLeft")).intValue();
219+
//If speed normal we scroll xoffset pixel
220+
assertTrue("Expected x == 1000, but got x = " + x, x == 1000);
221+
}
222+
223+
@NeedsFreshDriver
224+
@Test
225+
public void testCanFlickHorizontallyFastFromWebElementQt() {
226+
driver.get(pages.longContentPage);
227+
228+
WebElement toFlick = driver.findElement(By.id("imagestart"));
229+
WebElement link = driver.findElement(By.id("link2"));
230+
int x = link.getLocation().x;
231+
// The element is located at the right of the page,
232+
// so it is not initially visible on the screen.
233+
assertTrue(x > 3500);
234+
235+
Action flick = getBuilder(driver).flick(toFlick, -400, 0, FlickAction.SPEED_FAST)
236+
.build();
237+
flick.perform();
238+
x = ((Long)((JavascriptExecutor) driver).executeScript("return document.body.scrollLeft")).intValue();
239+
//If speed fast we scroll 2*xoffset pixel
240+
assertTrue("Expected x == 800, but got: " + x, x == 800);
241+
}
242+
243+
@NeedsFreshDriver
244+
@Test
245+
public void testCanFlickHorizontallyQt() {
246+
driver.get(pages.clicksPage);
247+
driver.get(pages.longContentPage);
248+
249+
WebElement link = driver.findElement(By.id("link1"));
250+
int x = link.getLocation().x;
251+
// The element is located at the right of the page,
252+
// so it is not initially visible on the screen.
253+
assertTrue("Expected x == 1500, but got x = " + x, x > 1500);
254+
255+
Action flick = getBuilder(driver).flick(200, 0).build();
256+
flick.perform();
257+
x = ((Long)((JavascriptExecutor) driver).executeScript("return document.body.scrollLeft")).intValue();
258+
//Scroll 3*xspeed pixel
259+
assertTrue("Expected x == 600, but got x = " + x, x == 600);
260+
}
261+
262+
@Ignore(value = {ANDROID},
263+
reason = "Android flick's can result in different offsets")
264+
@NeedsFreshDriver
265+
@Test
266+
public void testCanFlickHorizontallyFastQt() {
267+
driver.get(pages.longContentPage);
268+
269+
WebElement link = driver.findElement(By.id("link2"));
270+
int x = link.getLocation().x;
271+
// The element is located at the right of the page,
272+
// so it is not initially visible on the screen.
273+
assertTrue(x > 3500);
274+
275+
Action flick = getBuilder(driver).flick(750, 0).build();
276+
flick.perform();
277+
x = ((Long)((JavascriptExecutor) driver).executeScript("return document.body.scrollLeft")).intValue();
278+
//Scroll 3*xspeed pixel
279+
assertTrue("Got: " + x, x == 2250);
280+
}
281+
282+
@NeedsFreshDriver
283+
@Test
284+
public void testCanFlickVerticallyFromWebElementQt() {
285+
driver.get(pages.longContentPage);
286+
287+
WebElement link = driver.findElement(By.id("link3"));
288+
int y = link.getLocation().y;
289+
// The element is located at the bottom of the page,
290+
// so it is not initially visible on the screen.
291+
assertTrue(y > 4200);
292+
293+
WebElement toFlick = driver.findElement(By.id("imagestart"));
294+
Action flick = getBuilder(driver).flick(toFlick, 0, -600, FlickAction.SPEED_NORMAL)
295+
.build();
296+
flick.perform();
297+
y = ((Long)((JavascriptExecutor) driver).executeScript("return document.body.scrollTop")).intValue();
298+
//If speed normal we scroll yoffset pixel
299+
assertTrue("Expected y == 600, but got: " + y, y == 600);
300+
}
301+
302+
@NeedsFreshDriver
303+
@Test
304+
public void testCanFlickVerticallyFastFromWebElementQt() {
305+
driver.get(pages.longContentPage);
306+
307+
WebElement link = driver.findElement(By.id("link4"));
308+
int y = link.getLocation().y;
309+
// The element is located at the bottom of the page,
310+
// so it is not initially visible on the screen.
311+
assertTrue(y > 8700);
312+
313+
WebElement toFlick = driver.findElement(By.id("imagestart"));
314+
Action flick = getBuilder(driver).flick(toFlick, 0, -600, FlickAction.SPEED_FAST)
315+
.build();
316+
flick.perform();
317+
y = ((Long)((JavascriptExecutor) driver).executeScript("return document.body.scrollTop")).intValue();
318+
//If speed normal we scroll 2*yoffset pixel
319+
assertTrue("Expected y == 1200, but got: " + y, y == 1200);
320+
}
321+
322+
@NeedsFreshDriver
323+
@Test
324+
public void testCanFlickVerticallyQt() {
325+
driver.get(pages.longContentPage);
326+
327+
WebElement link = driver.findElement(By.id("link3"));
328+
int y = link.getLocation().y;
329+
// The element is located at the bottom of the page,
330+
// so it is not initially visible on the screen.
331+
assertTrue(y > 4200);
332+
333+
Action flick = getBuilder(driver).flick(0, 750).build();
334+
flick.perform();
335+
y = ((Long)((JavascriptExecutor) driver).executeScript("return document.body.scrollTop")).intValue();
336+
337+
//Scroll 3*yspeed pixel
338+
assertTrue("Got: " + y, y == 2250);
339+
}
340+
341+
@NeedsFreshDriver
342+
@Test
343+
public void testCanFlickVerticallyFastQt() {
344+
driver.get(pages.longContentPage);
345+
346+
WebElement link = driver.findElement(By.id("link4"));
347+
int y = link.getLocation().y;
348+
// The element is located at the bottom of the page,
349+
// so it is not initially visible on the screen.
350+
assertTrue(y > 8700);
351+
352+
Action flick = getBuilder(driver).flick(0, 1500).build();
353+
flick.perform();
354+
y = ((Long)((JavascriptExecutor) driver).executeScript("return document.body.scrollTop")).intValue();
355+
//Scroll 3*yspeed pixel
356+
assertTrue("Got: " + y, y == 4500);
357+
}
358+
200359
}

0 commit comments

Comments
 (0)