Skip to content

Commit

Permalink
Implementing switchToParentFrame support in atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jun 18, 2014
1 parent 23b46d7 commit 25bf6d8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions javascript/atoms/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ bot.frame.activeElement = function() {
};


/**
* Gets the parent frame of the specified frame.
*
* @param {!Window=} opt_root The window get the parent of.
* Defaults to {@code bot.getWindow()}.
* @return {Window} The frame if found, null otherwise.
*/
bot.frame.parentFrame = function(opt_root) {
var domWindow = opt_root || bot.getWindow();
return domWindow.parent;
};


/**
* Returns a reference to the window object corresponding to the given element.
* Note that the element must be a frame or an iframe.
Expand Down
10 changes: 10 additions & 0 deletions javascript/atoms/test/frame_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@
var index = bot.frame.getFrameIndex(el, frameWin);
assertEquals(1, index);
}

function testFindParentFrame() {
var frameWin = bot.frame.parentFrame(window.frames[1]);
assertEquals(frameWin, window);
}

function testParentFrameOnTopLevelIsNoOp() {
var frameWin = bot.frame.parentFrame(window);
assertEquals(frameWin, window);
}
</script>
</head>
<frameset rows="*,*,*" >
Expand Down
5 changes: 5 additions & 0 deletions javascript/webdriver/atoms/fragments/inject/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ js_fragment(name = "default_content",
function = "webdriver.atoms.inject.frame.defaultContent",
deps = ["//javascript/webdriver/atoms/inject:deps"])

js_fragment(name = "get_parent_frame",
module = "webdriver.atoms.inject.frame",
function = "webdriver.atoms.inject.frame.parentFrame",
deps = ["//javascript/webdriver/atoms/inject:deps"])

js_fragment(name = "get_frame_window",
module = "webdriver.atoms.inject.frame",
function = "webdriver.atoms.inject.frame.getFrameWindow",
Expand Down
14 changes: 14 additions & 0 deletions javascript/webdriver/atoms/inject/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ webdriver.atoms.inject.frame.activeElement = function() {
};


/**
* Finds the parent frame of the specified frame.
*
* @param {!Window=} opt_root The window to perform the search under.
* If not specified window is used as the default.
* @return {string} A frame element wrapped in a JSON string as defined by
* the wire protocol.
*/
webdriver.atoms.inject.frame.parentFrame = function (opt_root) {
return webdriver.atoms.inject.executeScript(bot.frame.parentFrame,
[opt_root]);
};


/**
* Finds a frame by index.
*
Expand Down

0 comments on commit 25bf6d8

Please sign in to comment.