Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GEB-222 Restore page after withFrame calls

  • Loading branch information...
commit 42aaa8318db7ffbb05691acfe0ecbb13f4c173f1 1 parent 85b03c9
@erdi erdi authored
View
2  doc/manual/src/chapters/040-pages.md
@@ -572,7 +572,7 @@ Frames might seem a thing of the past but if you're accessing or testing some le
### Executing code in the context of a frame
-There are multiple flavours of the `withFrame()` method, but the for all of them the closure parameter is executed in the context of a frame specified by the first parameter:
+There are multiple flavours of the `withFrame()` method, but the for all of them the closure parameter is executed in the context of a frame specified by the first parameter and after the execution the browser page is restored to what it was before the call:
* `withFrame(String, Closure)` - String parameter contains the name or id of a frame element
* `withFrame(int, Closure)` - int parameter contains the index of the frame element, that is, if a page has three frames, the first frame would be at index “0”, the second at index “1” and the third at index “2”
View
1  doc/manual/src/chapters/130-project.md
@@ -49,6 +49,7 @@ This page lists the high level changes between versions of Geb.
* `getAttribute(String)` on `Navigator` now returns `null` for boolean attributes that are not present.
* `at()` and `toAt()` methods on `Browser` now return a page instance if they succeed and `to()` method always returns a page instance \[[GEB-217](http://jira.codehaus.org/browse/GEB-217)\].
+* `withFrame()` calls that don't take a page argument now change the browser page to what it was before the call, after the call \[[GEB-222](http://jira.codehaus.org/browse/GEB-222)\].
### 0.7.2
View
9 module/geb-core-tests/src/test/groovy/geb/frame/FrameSupportSpec.groovy
@@ -185,17 +185,18 @@ class FrameSupportSpec extends GebSpecWithServer {
}
@Unroll
- def "passing a page class to withFrame changes the page only for the closure body"() {
+ def "page is restored to what it was before a withFrame call"() {
when:
- withFrame(frameFactory.call(), FrameSupportSpecFramePage) {
- assert page in FrameSupportSpecFramePage
+ withFrame(frameFactory.call()) {
+ page FrameSupportSpecFramePage
}
then:
page in FrameSupportSpecPage
when:
- withFrame(frameFactory.call(), FrameSupportSpecFramePage) {
+ withFrame(frameFactory.call()) {
+ page FrameSupportSpecFramePage
throw new Exception()
}
View
7 module/geb-core/src/main/groovy/geb/frame/FrameSupport.groovy
@@ -20,18 +20,15 @@ class FrameSupport {
}
def withFrame(frame, Class<? extends Page> page, Closure block) {
- def currentPage
+ def originalPage = browser.page
browser.driver.switchTo().frame(frame)
if (page) {
- currentPage = browser.page
browser.page(page)
}
try {
block.call()
} finally {
- if (currentPage) {
- browser.page(currentPage)
- }
+ browser.page(originalPage)
browser.driver.switchTo().defaultContent()
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.