Skip to content

Commit 25bf6d8

Browse files
committed
Implementing switchToParentFrame support in atoms
1 parent 23b46d7 commit 25bf6d8

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

javascript/atoms/frame.js

+13
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ bot.frame.activeElement = function() {
4242
};
4343

4444

45+
/**
46+
* Gets the parent frame of the specified frame.
47+
*
48+
* @param {!Window=} opt_root The window get the parent of.
49+
* Defaults to {@code bot.getWindow()}.
50+
* @return {Window} The frame if found, null otherwise.
51+
*/
52+
bot.frame.parentFrame = function(opt_root) {
53+
var domWindow = opt_root || bot.getWindow();
54+
return domWindow.parent;
55+
};
56+
57+
4558
/**
4659
* Returns a reference to the window object corresponding to the given element.
4760
* Note that the element must be a frame or an iframe.

javascript/atoms/test/frame_test.html

+10
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@
160160
var index = bot.frame.getFrameIndex(el, frameWin);
161161
assertEquals(1, index);
162162
}
163+
164+
function testFindParentFrame() {
165+
var frameWin = bot.frame.parentFrame(window.frames[1]);
166+
assertEquals(frameWin, window);
167+
}
168+
169+
function testParentFrameOnTopLevelIsNoOp() {
170+
var frameWin = bot.frame.parentFrame(window);
171+
assertEquals(frameWin, window);
172+
}
163173
</script>
164174
</head>
165175
<frameset rows="*,*,*" >

javascript/webdriver/atoms/fragments/inject/build.desc

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ js_fragment(name = "default_content",
8383
function = "webdriver.atoms.inject.frame.defaultContent",
8484
deps = ["//javascript/webdriver/atoms/inject:deps"])
8585

86+
js_fragment(name = "get_parent_frame",
87+
module = "webdriver.atoms.inject.frame",
88+
function = "webdriver.atoms.inject.frame.parentFrame",
89+
deps = ["//javascript/webdriver/atoms/inject:deps"])
90+
8691
js_fragment(name = "get_frame_window",
8792
module = "webdriver.atoms.inject.frame",
8893
function = "webdriver.atoms.inject.frame.getFrameWindow",

javascript/webdriver/atoms/inject/frame.js

+14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ webdriver.atoms.inject.frame.activeElement = function() {
4848
};
4949

5050

51+
/**
52+
* Finds the parent frame of the specified frame.
53+
*
54+
* @param {!Window=} opt_root The window to perform the search under.
55+
* If not specified window is used as the default.
56+
* @return {string} A frame element wrapped in a JSON string as defined by
57+
* the wire protocol.
58+
*/
59+
webdriver.atoms.inject.frame.parentFrame = function (opt_root) {
60+
return webdriver.atoms.inject.executeScript(bot.frame.parentFrame,
61+
[opt_root]);
62+
};
63+
64+
5165
/**
5266
* Finds a frame by index.
5367
*

0 commit comments

Comments
 (0)