Skip to content

Commit 5aac1e2

Browse files
committed
Implementing proper assumes for native events. Skipped tests should not be
counted as passed
1 parent f122b5e commit 5aac1e2

File tree

6 files changed

+43
-100
lines changed

6 files changed

+43
-100
lines changed

java/client/test/org/openqa/selenium/RenderedWebElementTest.java

+8-28
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ public void testShouldAllowInheritedStylesToBeUsed() {
127127
reason = "HtmlUnit: Advanced mouse actions only implemented in rendered browsers. Firefox: hover is broken again.")
128128
@Test
129129
public void testShouldAllowUsersToHoverOverElements() {
130-
if (!hasInputDevices()) {
131-
return;
132-
}
130+
assumeTrue(hasInputDevices());
133131

134132
driver.get(pages.javascriptPage);
135133

@@ -157,9 +155,7 @@ public Boolean call() throws Exception {
157155
reason = "HtmlUnit: Advanced mouse actions only implemented in rendered browsers")
158156
@Test
159157
public void testHoverPersists() throws Exception {
160-
if (!hasInputDevices()) {
161-
return;
162-
}
158+
assumeTrue(hasInputDevices());
163159

164160
// This test passes on IE. When running in Firefox on Windows, the test
165161
// will fail if the mouse cursor is not in the window. Solution: Maximize.
@@ -203,9 +199,7 @@ public Boolean call() throws Exception {
203199
@NeedsLocalEnvironment
204200
@Test
205201
public void testPersistentHoverCanBeTurnedOff() throws Exception {
206-
if (!hasInputDevices()) {
207-
return;
208-
}
202+
assumeTrue(hasInputDevices());
209203

210204
assumeTrue(TestUtilities.isInternetExplorer(driver));
211205
// Destroy the previous driver to make sure the hovering thread is
@@ -314,9 +308,7 @@ public void testCorrectlyDetectMapElementsAreShown() {
314308
@JavascriptEnabled
315309
@Test
316310
public void testCanClickOnSuckerFishMenuItem() throws Exception {
317-
if (!hasInputDevices()) {
318-
return;
319-
}
311+
assumeTrue(hasInputDevices());
320312

321313
driver.get(pages.javascriptPage);
322314

@@ -338,10 +330,7 @@ public void testCanClickOnSuckerFishMenuItem() throws Exception {
338330
reason = "Advanced mouse actions only implemented in rendered browsers")
339331
@Test
340332
public void testMovingMouseByRelativeOffset() {
341-
if (!hasInputDevices()) {
342-
System.out.println("Skipping move by offset test: no input devices");
343-
return;
344-
}
333+
assumeTrue(hasInputDevices());
345334

346335
driver.get(pages.mouseTrackerPage);
347336

@@ -362,10 +351,7 @@ public void testMovingMouseByRelativeOffset() {
362351
reason = "Advanced mouse actions only implemented in rendered browsers")
363352
@Test
364353
public void testMovingMouseToRelativeElementOffset() {
365-
if (!hasInputDevices()) {
366-
System.out.println("Skipping move to offset test: no input devices: %s");
367-
return;
368-
}
354+
assumeTrue(hasInputDevices());
369355

370356
driver.get(pages.mouseTrackerPage);
371357

@@ -383,10 +369,7 @@ public void testMovingMouseToRelativeElementOffset() {
383369
reason = "Advanced mouse actions only implemented in rendered browsers")
384370
@Test
385371
public void testMovingMouseToRelativeZeroElementOffset() {
386-
if (!hasInputDevices()) {
387-
System.out.println("Skipping move to offset test: no input devices");
388-
return;
389-
}
372+
assumeTrue(hasInputDevices());
390373

391374
driver.get(pages.mouseTrackerPage);
392375

@@ -404,10 +387,7 @@ public void testMovingMouseToRelativeZeroElementOffset() {
404387
@Ignore(value = {HTMLUNIT, OPERA}, reason = "Advanced mouse actions only implemented in rendered browsers")
405388
@Test
406389
public void testMoveRelativeToBody() {
407-
if (!hasInputDevices()) {
408-
System.out.println(String.format("Skipping move to offset test: no input devices"));
409-
return;
410-
}
390+
assumeTrue(hasInputDevices());
411391

412392
try {
413393
driver.get(pages.mouseTrackerPage);

java/client/test/org/openqa/selenium/SvgElementTest.java

+4-16
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
package org.openqa.selenium;
1919

20-
import org.junit.Before;
2120
import org.junit.Test;
22-
import org.openqa.selenium.internal.FindsByCssSelector;
2321
import org.openqa.selenium.testing.Ignore;
2422
import org.openqa.selenium.testing.JUnit4TestBase;
2523

@@ -28,11 +26,9 @@
2826
import static org.junit.Assert.assertEquals;
2927
import static org.junit.Assert.assertNotNull;
3028
import static org.junit.Assume.assumeFalse;
31-
import static org.junit.Assume.assumeTrue;
3229
import static org.openqa.selenium.TestWaiter.waitFor;
3330
import static org.openqa.selenium.WaitingConditions.elementTextToEqual;
3431
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
35-
import static org.openqa.selenium.testing.Ignore.Driver.IE;
3632
import static org.openqa.selenium.testing.Ignore.Driver.OPERA;
3733
import static org.openqa.selenium.testing.Ignore.Driver.OPERA_MOBILE;
3834
import static org.openqa.selenium.testing.TestUtilities.isFirefox30;
@@ -46,16 +42,12 @@ public class SvgElementTest extends JUnit4TestBase {
4642
@Test
4743
public void testShouldClickOnGraphVisualElements() {
4844
assumeFalse("IE version < 9 doesn't support SVG", isOldIe(driver));
45+
assumeFalse("Firefox 3.0 with native events doesn't support SVG",
46+
isFirefox30(driver) && isNativeEventsEnabled(driver));
4947

5048
driver.get(pages.svgPage);
5149
WebElement svg = driver.findElement(By.cssSelector("svg"));
5250

53-
if (isFirefox30(driver) && isNativeEventsEnabled(driver)) {
54-
System.out.println("Not testing SVG elements with Firefox 3.0 and native events as" +
55-
" this functionality is not working.");
56-
return;
57-
}
58-
5951
List<WebElement> groupElements = svg.findElements(By.cssSelector("g"));
6052
assertEquals(5, groupElements.size());
6153

@@ -85,17 +77,13 @@ private static WebElement findAppleElement(List<WebElement> textElements) {
8577
@Test
8678
public void testShouldClickOnGraphTextElements() {
8779
assumeFalse("IE version < 9 doesn't support SVG", isOldIe(driver));
80+
assumeFalse("Firefox 3.0 with native events doesn't support SVG",
81+
isFirefox30(driver) && isNativeEventsEnabled(driver));
8882

8983
driver.get(pages.svgPage);
9084
WebElement svg = driver.findElement(By.cssSelector("svg"));
9185
List<WebElement> textElements = svg.findElements(By.cssSelector("text"));
9286

93-
if (isFirefox30(driver) && isNativeEventsEnabled(driver)) {
94-
System.out.println("Not testing SVG elements with Firefox 3.0 and native events as" +
95-
" this functionality is not working.");
96-
return;
97-
}
98-
9987
WebElement appleElement = findAppleElement(textElements);
10088
assertNotNull(appleElement);
10189

java/client/test/org/openqa/selenium/firefox/FirefoxDriverTest.java

+14-20
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
import static org.junit.Assert.assertThat;
6666
import static org.junit.Assert.assertTrue;
6767
import static org.junit.Assert.fail;
68+
import static org.junit.Assume.assumeFalse;
69+
import static org.junit.Assume.assumeTrue;
6870
import static org.openqa.selenium.TestWaiter.waitFor;
6971
import static org.openqa.selenium.WaitingConditions.elementValueToEqual;
7072
import static org.openqa.selenium.WaitingConditions.pageTitleToBe;
@@ -103,11 +105,10 @@ protected ExtensionConnection connectTo(FirefoxBinary binary, FirefoxProfile pro
103105

104106
@Test
105107
public void shouldGetMeaningfulExceptionOnBrowserDeath() {
106-
if (TestUtilities.getEffectivePlatform().is(Platform.LINUX) &&
107-
(TestUtilities.isFirefox30(driver) || TestUtilities.isFirefox35(driver))) {
108-
// This test does not work on firefox 3.0, 3.5 on linux.
109-
return;
110-
}
108+
assumeFalse("This test does not work on firefox 3.0, 3.5 on linux",
109+
TestUtilities.getEffectivePlatform().is(Platform.LINUX) &&
110+
(TestUtilities.isFirefox30(driver) || TestUtilities.isFirefox35(driver)));
111+
111112
ConnectionCapturingDriver driver2 = new ConnectionCapturingDriver();
112113
driver2.get(pages.formPage);
113114

@@ -261,9 +262,8 @@ private void sleepBecauseWindowsTakeTimeToOpen() {
261262
@NoDriverAfterTest
262263
@Test
263264
public void focusRemainsInOriginalWindowWhenOpeningNewWindow() {
264-
if (platformHasNativeEvents() == false) {
265-
return;
266-
}
265+
assumeTrue(platformHasNativeEvents());
266+
267267
// Scenario: Open a new window, make sure the current window still gets
268268
// native events (keyboard events in this case).
269269

@@ -285,9 +285,8 @@ public void focusRemainsInOriginalWindowWhenOpeningNewWindow() {
285285
@NoDriverAfterTest
286286
@Test
287287
public void switchingWindowSwitchesFocus() {
288-
if (platformHasNativeEvents() == false) {
289-
return;
290-
}
288+
assumeTrue(platformHasNativeEvents());
289+
291290
// Scenario: Open a new window, switch to it, make sure it gets native events.
292291
// Then switch back to the original window, make sure it gets native events.
293292

@@ -330,9 +329,8 @@ public void switchingWindowSwitchesFocus() {
330329
@NoDriverAfterTest
331330
@Test
332331
public void closingWindowAndSwitchingToOriginalSwitchesFocus() {
333-
if (platformHasNativeEvents() == false) {
334-
return;
335-
}
332+
assumeTrue(platformHasNativeEvents());
333+
336334
// Scenario: Open a new window, switch to it, close it, switch back to the
337335
// original window - make sure it gets native events.
338336

@@ -481,12 +479,8 @@ private static String randomString() {
481479

482480
@Test
483481
public void multipleFirefoxDriversRunningConcurrently() throws Exception {
484-
// Unfortunately native events on linux mean mucking around with the
485-
// window's focus. this breaks multiple drivers.
486-
if (TestUtilities.isNativeEventsEnabled(driver) &&
487-
Platform.getCurrent().is(Platform.LINUX)) {
488-
return;
489-
}
482+
assumeFalse("Unfortunately native events on linux mean mucking around with the window's focus",
483+
Platform.getCurrent().is(Platform.LINUX) && TestUtilities.isNativeEventsEnabled(driver));
490484

491485
int numThreads;
492486
if (!SauceDriver.shouldUseSauce()) {

java/client/test/org/openqa/selenium/interactions/BasicMouseInterfaceTest.java

+7-15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import static org.junit.Assert.assertEquals;
3434
import static org.junit.Assert.assertTrue;
3535
import static org.junit.Assert.fail;
36+
import static org.junit.Assume.assumeFalse;
37+
import static org.junit.Assume.assumeTrue;
3638
import static org.openqa.selenium.TestWaiter.waitFor;
3739
import static org.openqa.selenium.WaitingConditions.elementTextToContain;
3840
import static org.openqa.selenium.WaitingConditions.elementTextToEqual;
@@ -272,13 +274,11 @@ public void testMousePositionIsNotPreservedInActionsChain() {
272274
reason = "Behaviour not finalized yet regarding linked images.")
273275
@Test
274276
public void testMovingIntoAnImageEnclosedInALink() {
277+
assumeFalse("No way to compensate for accessibility-provided offsets on Firefox 3.0 or 3.5",
278+
isFirefox30(driver) || isFirefox35(driver));
279+
275280
driver.get(pages.linkedImage);
276281

277-
if (isFirefox30(driver) || isFirefox35(driver)) {
278-
System.out.println("Not performing testMovingIntoAnImageEnclosedInALink - no way to " +
279-
"compensate for accessibility-provided offsets on Firefox 3.0 or 3.5");
280-
return;
281-
}
282282
// Note: For some reason, the Accessibility API in Firefox will not be available before we
283283
// click on something. As a work-around, click on a different element just to get going.
284284
driver.findElement(By.id("linkToAnchorOnThisPage")).click();
@@ -316,10 +316,7 @@ private int getFieldValue(Map<String, Object> sizeRect, String fieldName) {
316316
reason = "Not implemented yet.")
317317
@Test
318318
public void testMovingMousePastViewPort() {
319-
if (!isNativeEventsEnabled(driver)) {
320-
System.out.println("Skipping testMovingMousePastViewPort: Native events are disabled.");
321-
return;
322-
}
319+
assumeTrue(isNativeEventsEnabled(driver));
323320

324321
driver.get(pages.javascriptPage);
325322

@@ -355,12 +352,7 @@ public void testMovingMousePastViewPort() {
355352
reason = "Not implemented yet.")
356353
@Test
357354
public void testMovingMouseBackAndForthPastViewPort() {
358-
359-
if (isFirefox(driver) && !isNativeEventsEnabled(driver)) {
360-
System.out.println("Skipping testMovingMouseBackAndForthPastViewPort: " +
361-
"Native events are disabled.");
362-
return;
363-
}
355+
assumeTrue(!isFirefox(driver) || isNativeEventsEnabled(driver));
364356

365357
driver.get(pages.veryLargeCanvas);
366358

java/client/test/org/openqa/selenium/interactions/CombinedInputActionsTest.java

+10-20
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static org.hamcrest.Matchers.equalTo;
3232
import static org.junit.Assert.assertEquals;
3333
import static org.junit.Assert.assertThat;
34+
import static org.junit.Assume.assumeTrue;
3435
import static org.openqa.selenium.TestWaiter.waitFor;
3536
import static org.openqa.selenium.WaitingConditions.elementToExist;
3637
import static org.openqa.selenium.testing.Ignore.Driver.ANDROID;
@@ -59,11 +60,9 @@ public class CombinedInputActionsTest extends JUnit4TestBase {
5960
@JavascriptEnabled
6061
@Test
6162
public void testClickingOnFormElements() {
62-
if (!isNativeEventsEnabled(driver) || (!getEffectivePlatform().is(Platform.LINUX))) {
63-
System.out.println("Skipping testClickingOnFormElements: Only works with native events" +
64-
" on Linux.");
65-
return;
66-
}
63+
assumeTrue("Only works with native events on Linux",
64+
isNativeEventsEnabled(driver) && getEffectivePlatform().is(Platform.LINUX));
65+
6766
driver.get(pages.formSelectionPage);
6867

6968
List<WebElement> options = driver.findElements(By.tagName("option"));
@@ -90,11 +89,8 @@ public void testClickingOnFormElements() {
9089
@Ignore({ANDROID, IE, REMOTE, IPHONE, OPERA})
9190
@Test
9291
public void testSelectingMultipleItems() {
93-
if (!isNativeEventsEnabled(driver) || (!getEffectivePlatform().is(Platform.LINUX))) {
94-
System.out.println("Skipping testClickingOnFormElements: Only works with native events" +
95-
" on Linux.");
96-
return;
97-
}
92+
assumeTrue("Only works with native events on Linux",
93+
isNativeEventsEnabled(driver) && getEffectivePlatform().is(Platform.LINUX));
9894

9995
driver.get(pages.selectableItemsPage);
10096

@@ -227,11 +223,8 @@ public void testChordControlCutAndPaste() {
227223
@Ignore({HTMLUNIT, OPERA, IE})
228224
@Test
229225
public void testCombiningShiftAndClickResultsInANewWindow() {
230-
if (!isNativeEventsEnabled(driver) || (!getEffectivePlatform().is(Platform.LINUX))) {
231-
System.out.println("Skipping testCombiningShiftAndClickResultsInANewWindow: " +
232-
"Only works with native events on Linux.");
233-
return;
234-
}
226+
assumeTrue("Only works with native events on Linux",
227+
isNativeEventsEnabled(driver) && getEffectivePlatform().is(Platform.LINUX));
235228

236229
driver.get(pages.linkedImage);
237230
WebElement link = driver.findElement(By.id("link"));
@@ -253,11 +246,8 @@ public void testCombiningShiftAndClickResultsInANewWindow() {
253246
@Ignore({HTMLUNIT, OPERA, OPERA_MOBILE, IPHONE, IE})
254247
@Test
255248
public void testHoldingDownShiftKeyWhileClicking() {
256-
if (!isNativeEventsEnabled(driver) || (!getEffectivePlatform().is(Platform.LINUX))) {
257-
System.out.println("Skipping testHoldingDownShiftKeyWhileClicking: " +
258-
"Only works with native events on Linux.");
259-
return;
260-
}
249+
assumeTrue("Only works with native events on Linux",
250+
isNativeEventsEnabled(driver) && getEffectivePlatform().is(Platform.LINUX));
261251

262252
driver.get(pages.clickEventPage);
263253

java/client/test/org/openqa/selenium/testing/TestUtilities.java

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.regex.Matcher;
2222
import java.util.regex.Pattern;
2323

24-
import org.junit.Before;
2524
import org.openqa.selenium.Capabilities;
2625
import org.openqa.selenium.HasCapabilities;
2726
import org.openqa.selenium.JavascriptExecutor;

0 commit comments

Comments
 (0)