Skip to content

Commit 653b634

Browse files
committed
Ensure all tests that end with a nested frame being the current context
to close the session. Because it was regressed in some drivers: https://code.google.com/p/chromedriver/issues/detail?id=1106 (fixed in code; not released) Ignore tests that fail due to bugs: https://code.google.com/p/chromedriver/issues/detail?id=1125
1 parent e9b6817 commit 653b634

17 files changed

+129
-110
lines changed

Diff for: java/client/test/org/openqa/selenium/AlertsTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public void testAlertShouldNotAllowAdditionalCommandsIfDismissed() {
219219

220220
@Ignore(MARIONETTE)
221221
@JavascriptEnabled
222+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
222223
@Test
223224
public void testShouldAllowUsersToAcceptAnAlertInAFrame() {
224225
driver.switchTo().frame("iframeWithAlert");
@@ -234,6 +235,7 @@ public void testShouldAllowUsersToAcceptAnAlertInAFrame() {
234235

235236
@Ignore(MARIONETTE)
236237
@JavascriptEnabled
238+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
237239
@Test
238240
public void testShouldAllowUsersToAcceptAnAlertInANestedFrame() {
239241
driver.switchTo().frame("iframeWithIframe").switchTo().frame("iframeWithAlert");

Diff for: java/client/test/org/openqa/selenium/ClickScrollingTest.java

+43-64
Original file line numberDiff line numberDiff line change
@@ -148,89 +148,71 @@ public void testShouldScrollOverflowElementsIfClickPointIsOutOfViewButElementIsI
148148
assertEquals("clicked", driver.findElement(By.id("clicked")).getText());
149149
}
150150

151+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
151152
@Test
152153
@Ignore(value = {SAFARI, MARIONETTE}, reason = "others: not tested")
153154
public void testShouldBeAbleToClickElementInAFrameThatIsOutOfView() {
154-
try {
155-
driver.get(appServer.whereIs("scrolling_tests/page_with_frame_out_of_view.html"));
156-
driver.switchTo().frame("frame");
157-
WebElement element = driver.findElement(By.name("checkbox"));
158-
element.click();
159-
assertTrue(element.isSelected());
160-
} finally {
161-
driver.switchTo().defaultContent();
162-
}
155+
driver.get(appServer.whereIs("scrolling_tests/page_with_frame_out_of_view.html"));
156+
driver.switchTo().frame("frame");
157+
WebElement element = driver.findElement(By.name("checkbox"));
158+
element.click();
159+
assertTrue(element.isSelected());
163160
}
164161

162+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
165163
@Test
166164
@Ignore(value = {SAFARI, MARIONETTE}, reason = "not tested")
167165
public void testShouldBeAbleToClickElementThatIsOutOfViewInAFrame() {
168-
try {
169-
driver.get(appServer.whereIs("scrolling_tests/page_with_scrolling_frame.html"));
170-
driver.switchTo().frame("scrolling_frame");
171-
WebElement element = driver.findElement(By.name("scroll_checkbox"));
172-
element.click();
173-
assertTrue(element.isSelected());
174-
} finally {
175-
driver.switchTo().defaultContent();
176-
}
166+
driver.get(appServer.whereIs("scrolling_tests/page_with_scrolling_frame.html"));
167+
driver.switchTo().frame("scrolling_frame");
168+
WebElement element = driver.findElement(By.name("scroll_checkbox"));
169+
element.click();
170+
assertTrue(element.isSelected());
177171
}
178172

173+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
179174
@Test(expected = MoveTargetOutOfBoundsException.class)
180175
@Ignore(reason = "All tested browses scroll non-scrollable frames")
181176
public void testShouldNotBeAbleToClickElementThatIsOutOfViewInANonScrollableFrame() {
182-
try {
183-
driver.get(appServer.whereIs("scrolling_tests/page_with_non_scrolling_frame.html"));
184-
driver.switchTo().frame("scrolling_frame");
185-
WebElement element = driver.findElement(By.name("scroll_checkbox"));
186-
element.click();
187-
} finally {
188-
driver.switchTo().defaultContent();
189-
}
177+
driver.get(appServer.whereIs("scrolling_tests/page_with_non_scrolling_frame.html"));
178+
driver.switchTo().frame("scrolling_frame");
179+
WebElement element = driver.findElement(By.name("scroll_checkbox"));
180+
element.click();
190181
}
191182

183+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
192184
@Test
193185
@Ignore(value = {SAFARI, MARIONETTE}, reason = "not tested")
194186
public void testShouldBeAbleToClickElementThatIsOutOfViewInAFrameThatIsOutOfView() {
195-
try {
196-
driver.get(appServer.whereIs("scrolling_tests/page_with_scrolling_frame_out_of_view.html"));
197-
driver.switchTo().frame("scrolling_frame");
198-
WebElement element = driver.findElement(By.name("scroll_checkbox"));
199-
element.click();
200-
assertTrue(element.isSelected());
201-
} finally {
202-
driver.switchTo().defaultContent();
203-
}
187+
driver.get(appServer.whereIs("scrolling_tests/page_with_scrolling_frame_out_of_view.html"));
188+
driver.switchTo().frame("scrolling_frame");
189+
WebElement element = driver.findElement(By.name("scroll_checkbox"));
190+
element.click();
191+
assertTrue(element.isSelected());
204192
}
205193

194+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
206195
@Test
207196
@Ignore(value = {SAFARI, MARIONETTE}, reason = "not tested")
208197
public void testShouldBeAbleToClickElementThatIsOutOfViewInANestedFrame() {
209-
try {
210-
driver.get(appServer.whereIs("scrolling_tests/page_with_nested_scrolling_frames.html"));
211-
driver.switchTo().frame("scrolling_frame");
212-
driver.switchTo().frame("nested_scrolling_frame");
213-
WebElement element = driver.findElement(By.name("scroll_checkbox"));
214-
element.click();
215-
assertTrue(element.isSelected());
216-
} finally {
217-
driver.switchTo().defaultContent();
218-
}
198+
driver.get(appServer.whereIs("scrolling_tests/page_with_nested_scrolling_frames.html"));
199+
driver.switchTo().frame("scrolling_frame");
200+
driver.switchTo().frame("nested_scrolling_frame");
201+
WebElement element = driver.findElement(By.name("scroll_checkbox"));
202+
element.click();
203+
assertTrue(element.isSelected());
219204
}
220205

206+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
221207
@Test
222208
@Ignore(value = {SAFARI, MARIONETTE}, reason = "not tested")
223209
public void testShouldBeAbleToClickElementThatIsOutOfViewInANestedFrameThatIsOutOfView() {
224-
try {
225-
driver.get(appServer.whereIs("scrolling_tests/page_with_nested_scrolling_frames_out_of_view.html"));
226-
driver.switchTo().frame("scrolling_frame");
227-
driver.switchTo().frame("nested_scrolling_frame");
228-
WebElement element = driver.findElement(By.name("scroll_checkbox"));
229-
element.click();
230-
assertTrue(element.isSelected());
231-
} finally {
232-
driver.switchTo().defaultContent();
233-
}
210+
driver.get(appServer.whereIs("scrolling_tests/page_with_nested_scrolling_frames_out_of_view.html"));
211+
driver.switchTo().frame("scrolling_frame");
212+
driver.switchTo().frame("nested_scrolling_frame");
213+
WebElement element = driver.findElement(By.name("scroll_checkbox"));
214+
element.click();
215+
assertTrue(element.isSelected());
234216
}
235217

236218
@JavascriptEnabled
@@ -246,18 +228,15 @@ private long getScrollTop() {
246228
return (Long)((JavascriptExecutor)driver).executeScript("return document.body.scrollTop;");
247229
}
248230

231+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
249232
@Test
250233
@Ignore(value = {SAFARI, MARIONETTE}, reason = "Not tested")
251234
public void testShouldBeAbleToClickElementInATallFrame() {
252-
try {
253-
driver.get(appServer.whereIs("scrolling_tests/page_with_tall_frame.html"));
254-
driver.switchTo().frame("tall_frame");
255-
WebElement element = driver.findElement(By.name("checkbox"));
256-
element.click();
257-
assertTrue(element.isSelected());
258-
} finally {
259-
driver.switchTo().defaultContent();
260-
}
235+
driver.get(appServer.whereIs("scrolling_tests/page_with_tall_frame.html"));
236+
driver.switchTo().frame("tall_frame");
237+
WebElement element = driver.findElement(By.name("checkbox"));
238+
element.click();
239+
assertTrue(element.isSelected());
261240
}
262241

263242
}

Diff for: java/client/test/org/openqa/selenium/ClickTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public void testCanClickOnAnAnchorAndNotReloadThePage() {
8585
assertEquals("Latch was reset", Boolean.TRUE, samePage);
8686
}
8787

88+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
8889
@Test
8990
public void testCanClickOnALinkThatUpdatesAnotherFrame() {
9091
driver.switchTo().frame("source");
@@ -96,6 +97,7 @@ public void testCanClickOnALinkThatUpdatesAnotherFrame() {
9697
}
9798

9899
@JavascriptEnabled
100+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
99101
@Test
100102
public void testElementsFoundByJsCanLoadUpdatesInAnotherFrame() {
101103
driver.switchTo().frame("source");

Diff for: java/client/test/org/openqa/selenium/CookieImplementationTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public void testAddCookiesWithDifferentPathsThatAreRelatedToOurs() {
208208
}
209209

210210
@Ignore(value = {CHROME, PHANTOMJS, SAFARI})
211+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
211212
@Test
212213
public void testGetCookiesInAFrame() {
213214
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));

Diff for: java/client/test/org/openqa/selenium/ElementEqualityTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void testSameElementLookedUpDifferentWaysUsingFindElementsShouldHaveSameH
7171
}
7272

7373
@JavascriptEnabled
74+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
7475
@Test
7576
public void testAnElementFoundInADifferentFrameViaJsShouldHaveSameId() {
7677
driver.get(pages.missedJsReferencePage);

Diff for: java/client/test/org/openqa/selenium/ElementFindingTest.java

+11-13
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ public void testShouldNotBeAbleToLocateASingleElementOnABlankPage() {
739739
driver.findElement(By.id("nonExistantButton"));
740740
}
741741

742+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
742743
@Test
743744
public void testAnElementFoundInADifferentFrameIsStale() {
744745
driver.get(pages.missedJsReferencePage);
@@ -755,27 +756,24 @@ public void testAnElementFoundInADifferentFrameIsStale() {
755756

756757
@JavascriptEnabled
757758
@Test
759+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
758760
public void testAnElementFoundInADifferentFrameViaJsCanBeUsed() {
759761
driver.get(pages.missedJsReferencePage);
760762

761-
try {
762-
driver.switchTo().frame("inner");
763-
WebElement first = driver.findElement(By.id("oneline"));
763+
driver.switchTo().frame("inner");
764+
WebElement first = driver.findElement(By.id("oneline"));
764765

765-
driver.switchTo().defaultContent();
766-
WebElement element = (WebElement) ((JavascriptExecutor) driver).executeScript(
767-
"return frames[0].document.getElementById('oneline');");
766+
driver.switchTo().defaultContent();
767+
WebElement element = (WebElement) ((JavascriptExecutor) driver).executeScript(
768+
"return frames[0].document.getElementById('oneline');");
768769

769770

770-
driver.switchTo().frame("inner");
771+
driver.switchTo().frame("inner");
771772

772-
WebElement second = driver.findElement(By.id("oneline"));
773+
WebElement second = driver.findElement(By.id("oneline"));
773774

774-
assertEquals(first, element);
775-
assertEquals(second, element);
776-
} finally {
777-
driver.switchTo().defaultContent();
778-
}
775+
assertEquals(first, element);
776+
assertEquals(second, element);
779777
}
780778

781779
}

Diff for: java/client/test/org/openqa/selenium/FrameSwitchingTest.java

+32
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.junit.Assert.assertThat;
2525
import static org.junit.Assert.assertTrue;
2626
import static org.junit.Assert.fail;
27+
import static org.junit.Assume.assumeFalse;
2728
import static org.openqa.selenium.support.ui.ExpectedConditions.frameToBeAvailableAndSwitchToIt;
2829
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
2930
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
@@ -517,6 +518,37 @@ public void testShouldNotSwitchMagicallyToTheTopWindow() {
517518
}
518519
}
519520

521+
@Ignore(MARIONETTE) // Marionette not tested.
522+
@NoDriverAfterTest // Subsequent tests sometimes fail on Firefox.
523+
@Test
524+
public void testGetShouldSwitchToDefaultContext() {
525+
// Fails on Chrome 44 (and higher?) https://code.google.com/p/chromedriver/issues/detail?id=1106
526+
assumeFalse(
527+
"chrome".equals(((HasCapabilities) driver).getCapabilities().getBrowserName())
528+
&& "44".compareTo(((HasCapabilities) driver).getCapabilities().getVersion()) <= 0);
529+
530+
driver.get(pages.iframePage);
531+
try {
532+
driver.findElement(By.id("iframe1"));
533+
} catch (NoSuchElementException e) {
534+
fail("Expected to be on iframes.html, but " + e.getMessage());
535+
}
536+
537+
driver.switchTo().frame(driver.findElement(By.id("iframe1")));
538+
try {
539+
driver.findElement(By.id("cheese")); // Found on formPage.html but not on iframes.html.
540+
} catch (NoSuchElementException e) {
541+
fail("Expected to be on formPage.html, but " + e.getMessage());
542+
}
543+
544+
driver.get(pages.iframePage); // This must effectively switchTo().defaultContent(), too.
545+
try {
546+
driver.findElement(By.id("iframe1"));
547+
} catch (NoSuchElementException e) {
548+
fail("Expected to be on iframes.html, but " + e.getMessage());
549+
}
550+
}
551+
520552
private void assertFrameNotPresent(String locator) {
521553
driver.switchTo().defaultContent();
522554
wait.until(not(frameToBeAvailableAndSwitchToIt(locator)));

Diff for: java/client/test/org/openqa/selenium/PageLoadingTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public void testShouldReturnURLOnNotExistedPage() {
238238
}
239239

240240
@Ignore({MARIONETTE})
241+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
241242
@Test
242243
public void testShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoaded() {
243244
driver.get(pages.framesetPage);
@@ -418,6 +419,10 @@ public void testShouldTimeoutIfAPageTakesTooLongToLoad() {
418419
@Test
419420
public void testShouldTimeoutIfAPageTakesTooLongToLoadAfterClick() {
420421
assumeFalse(isFirefox(driver) && isNativeEventsEnabled(driver));
422+
// Fails on Chrome 44 (and higher?) https://code.google.com/p/chromedriver/issues/detail?id=1125
423+
assumeFalse(
424+
"chrome".equals(((HasCapabilities) driver).getCapabilities().getBrowserName())
425+
&& "44".compareTo(((HasCapabilities) driver).getCapabilities().getVersion()) <= 0);
421426

422427
driver.manage().timeouts().pageLoadTimeout(2, SECONDS);
423428

Diff for: java/client/test/org/openqa/selenium/PositionAndSizeTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static org.junit.Assert.assertThat;
2626
import static org.junit.Assert.assertTrue;
2727
import static org.junit.Assume.assumeFalse;
28-
import static org.junit.Assume.assumeTrue;
2928
import static org.openqa.selenium.Platform.ANDROID;
3029
import static org.openqa.selenium.testing.Ignore.Driver.CHROME;
3130
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
@@ -98,6 +97,7 @@ public void testShouldScrollPageAndGetCoordinatesOfAnElementThatIsOutOfViewPort(
9897
assertThat(getLocationOnPage(By.id("box")), is(new Point(10, 5010)));
9998
}
10099

100+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
101101
@Test
102102
public void testShouldGetCoordinatesOfAnElementInAFrame() {
103103
driver.get(appServer.whereIs("coordinates_tests/element_in_frame.html"));
@@ -108,6 +108,7 @@ public void testShouldGetCoordinatesOfAnElementInAFrame() {
108108
}
109109

110110
@Ignore({SAFARI})
111+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
111112
@Test
112113
public void testShouldGetCoordinatesInViewPortOfAnElementInAFrame() {
113114
driver.get(appServer.whereIs("coordinates_tests/element_in_frame.html"));
@@ -117,6 +118,7 @@ public void testShouldGetCoordinatesInViewPortOfAnElementInAFrame() {
117118
}
118119

119120
@Ignore({SAFARI})
121+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
120122
@Test
121123
public void testShouldGetCoordinatesInViewPortOfAnElementInANestedFrame() {
122124
driver.get(appServer.whereIs("coordinates_tests/element_in_nested_frame.html"));

Diff for: java/client/test/org/openqa/selenium/TakesScreenshotTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ public void testShouldCaptureScreenshotAtIFramePage() throws Exception {
309309
compareColors(expectedColors, actualColors);
310310
}
311311

312+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
312313
@Test
313314
@Ignore(
314315
value = {IE, MARIONETTE},
@@ -340,6 +341,7 @@ public void testShouldCaptureScreenshotAtFramePageAfterSwitching() throws Except
340341
compareColors(expectedColors, actualColors);
341342
}
342343

344+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
343345
@Test
344346
@Ignore(
345347
value = {IE, CHROME, MARIONETTE},

Diff for: java/client/test/org/openqa/selenium/TypingTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ public void testGenerateKeyPressEventEvenWhenElementPreventsDefault() {
669669
@JavascriptEnabled
670670
@Ignore(value = {SAFARI, MARIONETTE},
671671
reason = "Safari: cannot type on contentEditable with synthetic events")
672+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
672673
@Test
673674
public void testTypingIntoAnIFrameWithContentEditableOrDesignModeSet() {
674675
driver.get(pages.richTextPage);
@@ -691,6 +692,7 @@ public void testTypingIntoAnIFrameWithContentEditableOrDesignModeSet() {
691692

692693
@JavascriptEnabled
693694
@Ignore(value = {HTMLUNIT, MARIONETTE}, issues = {6711})
695+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
694696
@Test
695697
public void testNonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() {
696698
assumeFalse("FIXME: Fails in Firefox on Linux with synthesized events",
@@ -756,6 +758,7 @@ public void testShouldBeAbleToTypeIntoContentEditableElementWithExistingValue()
756758
reason = "Untested browsers;" +
757759
" Safari: cannot type on contentEditable with synthetic events",
758760
issues = {3127})
761+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
759762
@Test
760763
public void testShouldBeAbleToTypeIntoTinyMCE() {
761764
driver.get(appServer.whereIs("tinymce.html"));

Diff for: java/client/test/org/openqa/selenium/UploadTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void setUp() throws Exception {
6060
}
6161

6262
@JavascriptEnabled
63+
@NoDriverAfterTest // So that next test never starts with "inside a frame" base state.
6364
@Test
6465
public void testFileUploading() throws Exception {
6566
assumeFalse(

0 commit comments

Comments
 (0)