Skip to content

Commit

Permalink
Implementing switchToParentFrame command for IE driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jun 5, 2014
1 parent e73b9cc commit b9e9fc6
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 4 deletions.
49 changes: 49 additions & 0 deletions cpp/iedriver/CommandHandlers/SwitchToParentFrameCommandHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2014 Software Freedom Conservancy
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_
#define WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_

#include "../Browser.h"
#include "../IECommandHandler.h"
#include "../IECommandExecutor.h"

namespace webdriver {

class SwitchToParentFrameCommandHandler : public IECommandHandler {
public:
SwitchToParentFrameCommandHandler(void) {
}

virtual ~SwitchToParentFrameCommandHandler(void) {
}

protected:
void ExecuteInternal(const IECommandExecutor& executor,
const LocatorMap& locator_parameters,
const ParametersMap& command_parameters,
Response* response) {
BrowserHandle browser_wrapper;
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
if (status_code != WD_SUCCESS) {
response->SetErrorResponse(status_code, "Unable to get browser");
return;
}
browser_wrapper->SetFocusedFrameToParent();
response->SetSuccessResponse(Json::Value::null);
}
};

} // namespace webdriver

#endif // WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_
28 changes: 28 additions & 0 deletions cpp/iedriver/DocumentHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,34 @@ int DocumentHost::SetFocusedFrameByIndex(const int frame_index) {
return this->SetFocusedFrameByIdentifier(frame_identifier);
}

void DocumentHost::SetFocusedFrameToParent() {
LOG(TRACE) << "Entering DocumentHost::SetFocusedFrameToParent";
// Three possible outcomes.
// Outcome 1: Already at top-level browsing context. No-op.
if (this->focused_frame_window_ != NULL) {
CComPtr<IHTMLWindow2> parent_window;
HRESULT hr = this->focused_frame_window_->get_parent(&parent_window);
if (FAILED(hr)) {
LOGHR(WARN, hr) << "IHTMLWindow2::get_parent call failed.";
}
CComPtr<IHTMLWindow2> top_window;
hr = this->focused_frame_window_->get_top(&top_window);
if (FAILED(hr)) {
LOGHR(WARN, hr) << "IHTMLWindow2::get_top call failed.";
}
if (top_window.IsEqualObject(parent_window)) {
// Outcome 2: Focus is on a frame one level deep, making the
// parent the top-level browsing context. Set focused frame
// pointer to NULL.
this->focused_frame_window_ = NULL;
} else {
// Outcome 3: Focus is on a frame more than one level deep.
// Set focused frame pointer to parent frame.
this->focused_frame_window_ = parent_window;
}
}
}

int DocumentHost::SetFocusedFrameByIdentifier(VARIANT frame_identifier) {
LOG(TRACE) << "Entering DocumentHost::SetFocusedFrameByIdentifier";

Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/DocumentHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class DocumentHost {
int SetFocusedFrameByIndex(const int frame_index);
int SetFocusedFrameByName(const std::string& frame_name);
int SetFocusedFrameByElement(IHTMLElement* frame_element);
void SetFocusedFrameToParent(void);

bool wait_required(void) const { return this->wait_required_; }
void set_wait_required(const bool value) { this->wait_required_ = value; }
Expand Down
2 changes: 2 additions & 0 deletions cpp/iedriver/IECommandExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "CommandHandlers/SetWindowSizeCommandHandler.h"
#include "CommandHandlers/SubmitElementCommandHandler.h"
#include "CommandHandlers/SwitchToFrameCommandHandler.h"
#include "CommandHandlers/SwitchToParentFrameCommandHandler.h"
#include "CommandHandlers/SwitchToWindowCommandHandler.h"
#include "StringUtilities.h"

Expand Down Expand Up @@ -766,6 +767,7 @@ void IECommandExecutor::PopulateCommandHandlers() {
this->command_handlers_[webdriver::CommandType::GetWindowHandles] = CommandHandlerHandle(new GetAllWindowHandlesCommandHandler);
this->command_handlers_[webdriver::CommandType::SwitchToWindow] = CommandHandlerHandle(new SwitchToWindowCommandHandler);
this->command_handlers_[webdriver::CommandType::SwitchToFrame] = CommandHandlerHandle(new SwitchToFrameCommandHandler);
this->command_handlers_[webdriver::CommandType::SwitchToParentFrame] = CommandHandlerHandle(new SwitchToParentFrameCommandHandler);
this->command_handlers_[webdriver::CommandType::Get] = CommandHandlerHandle(new GoToUrlCommandHandler);
this->command_handlers_[webdriver::CommandType::GoForward] = CommandHandlerHandle(new GoForwardCommandHandler);
this->command_handlers_[webdriver::CommandType::GoBack] = CommandHandlerHandle(new GoBackCommandHandler);
Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/IEDriver.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
<ClInclude Include="CommandHandlers\SetTimeoutCommandHandler.h" />
<ClInclude Include="CommandHandlers\SetWindowPositionCommandHandler.h" />
<ClInclude Include="CommandHandlers\SetWindowSizeCommandHandler.h" />
<ClInclude Include="CommandHandlers\SwitchToParentFrameCommandHandler.h" />
<ClInclude Include="DocumentHost.h" />
<ClInclude Include="Element.h" />
<ClInclude Include="ElementFinder.h" />
Expand Down
3 changes: 3 additions & 0 deletions cpp/iedriver/IEDriver.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@
<ClInclude Include="ProxyManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CommandHandlers\SwitchToParentFrameCommandHandler.h">
<Filter>Header Files\CommandHandlers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="IEDriver.def">
Expand Down
4 changes: 4 additions & 0 deletions cpp/iedriverserver/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ available via the project downloads page. Changes in "revision" field indicate
private releases checked into the prebuilts directory of the source tree, but
not made generally available on the downloads page.

v2.42.0.1
=========
* Implemented switchToParentFrame command.

v2.42.0.0
=========
* Release to synchronize with release of Selenium project.
Expand Down
Binary file modified cpp/iedriverserver/IEDriverServer.rc
Binary file not shown.
Binary file modified cpp/prebuilt/Win32/Release/IEDriverServer.exe
Binary file not shown.
Binary file modified cpp/prebuilt/x64/Release/IEDriverServer.exe
Binary file not shown.
4 changes: 0 additions & 4 deletions dotnet/test/common/FrameSwitchingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public void ShouldThrowAnExceptionWhenAFrameCannotBeFoundByIndex()

[Test]
[IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]
Expand All @@ -212,7 +211,6 @@ public void ShouldBeAbleToSwitchToParentFrame()

[Test]
[IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]
Expand All @@ -228,7 +226,6 @@ public void ShouldBeAbleToSwitchToParentFrameFromASecondLevelFrame()

[Test]
[IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]
Expand All @@ -243,7 +240,6 @@ public void SwitchingToParentFrameFromDefaultContextIsNoOp()

[Test]
[IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]
Expand Down

0 comments on commit b9e9fc6

Please sign in to comment.