Skip to content

Commit b9e9fc6

Browse files
committed
Implementing switchToParentFrame command for IE driver
1 parent e73b9cc commit b9e9fc6

11 files changed

+88
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2014 Software Freedom Conservancy
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
#ifndef WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_
15+
#define WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_
16+
17+
#include "../Browser.h"
18+
#include "../IECommandHandler.h"
19+
#include "../IECommandExecutor.h"
20+
21+
namespace webdriver {
22+
23+
class SwitchToParentFrameCommandHandler : public IECommandHandler {
24+
public:
25+
SwitchToParentFrameCommandHandler(void) {
26+
}
27+
28+
virtual ~SwitchToParentFrameCommandHandler(void) {
29+
}
30+
31+
protected:
32+
void ExecuteInternal(const IECommandExecutor& executor,
33+
const LocatorMap& locator_parameters,
34+
const ParametersMap& command_parameters,
35+
Response* response) {
36+
BrowserHandle browser_wrapper;
37+
int status_code = executor.GetCurrentBrowser(&browser_wrapper);
38+
if (status_code != WD_SUCCESS) {
39+
response->SetErrorResponse(status_code, "Unable to get browser");
40+
return;
41+
}
42+
browser_wrapper->SetFocusedFrameToParent();
43+
response->SetSuccessResponse(Json::Value::null);
44+
}
45+
};
46+
47+
} // namespace webdriver
48+
49+
#endif // WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_

cpp/iedriver/DocumentHost.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,34 @@ int DocumentHost::SetFocusedFrameByIndex(const int frame_index) {
156156
return this->SetFocusedFrameByIdentifier(frame_identifier);
157157
}
158158

159+
void DocumentHost::SetFocusedFrameToParent() {
160+
LOG(TRACE) << "Entering DocumentHost::SetFocusedFrameToParent";
161+
// Three possible outcomes.
162+
// Outcome 1: Already at top-level browsing context. No-op.
163+
if (this->focused_frame_window_ != NULL) {
164+
CComPtr<IHTMLWindow2> parent_window;
165+
HRESULT hr = this->focused_frame_window_->get_parent(&parent_window);
166+
if (FAILED(hr)) {
167+
LOGHR(WARN, hr) << "IHTMLWindow2::get_parent call failed.";
168+
}
169+
CComPtr<IHTMLWindow2> top_window;
170+
hr = this->focused_frame_window_->get_top(&top_window);
171+
if (FAILED(hr)) {
172+
LOGHR(WARN, hr) << "IHTMLWindow2::get_top call failed.";
173+
}
174+
if (top_window.IsEqualObject(parent_window)) {
175+
// Outcome 2: Focus is on a frame one level deep, making the
176+
// parent the top-level browsing context. Set focused frame
177+
// pointer to NULL.
178+
this->focused_frame_window_ = NULL;
179+
} else {
180+
// Outcome 3: Focus is on a frame more than one level deep.
181+
// Set focused frame pointer to parent frame.
182+
this->focused_frame_window_ = parent_window;
183+
}
184+
}
185+
}
186+
159187
int DocumentHost::SetFocusedFrameByIdentifier(VARIANT frame_identifier) {
160188
LOG(TRACE) << "Entering DocumentHost::SetFocusedFrameByIdentifier";
161189

cpp/iedriver/DocumentHost.h

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class DocumentHost {
6767
int SetFocusedFrameByIndex(const int frame_index);
6868
int SetFocusedFrameByName(const std::string& frame_name);
6969
int SetFocusedFrameByElement(IHTMLElement* frame_element);
70+
void SetFocusedFrameToParent(void);
7071

7172
bool wait_required(void) const { return this->wait_required_; }
7273
void set_wait_required(const bool value) { this->wait_required_ = value; }

cpp/iedriver/IECommandExecutor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "CommandHandlers/SetWindowSizeCommandHandler.h"
7373
#include "CommandHandlers/SubmitElementCommandHandler.h"
7474
#include "CommandHandlers/SwitchToFrameCommandHandler.h"
75+
#include "CommandHandlers/SwitchToParentFrameCommandHandler.h"
7576
#include "CommandHandlers/SwitchToWindowCommandHandler.h"
7677
#include "StringUtilities.h"
7778

@@ -766,6 +767,7 @@ void IECommandExecutor::PopulateCommandHandlers() {
766767
this->command_handlers_[webdriver::CommandType::GetWindowHandles] = CommandHandlerHandle(new GetAllWindowHandlesCommandHandler);
767768
this->command_handlers_[webdriver::CommandType::SwitchToWindow] = CommandHandlerHandle(new SwitchToWindowCommandHandler);
768769
this->command_handlers_[webdriver::CommandType::SwitchToFrame] = CommandHandlerHandle(new SwitchToFrameCommandHandler);
770+
this->command_handlers_[webdriver::CommandType::SwitchToParentFrame] = CommandHandlerHandle(new SwitchToParentFrameCommandHandler);
769771
this->command_handlers_[webdriver::CommandType::Get] = CommandHandlerHandle(new GoToUrlCommandHandler);
770772
this->command_handlers_[webdriver::CommandType::GoForward] = CommandHandlerHandle(new GoForwardCommandHandler);
771773
this->command_handlers_[webdriver::CommandType::GoBack] = CommandHandlerHandle(new GoBackCommandHandler);

cpp/iedriver/IEDriver.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@
262262
<ClInclude Include="CommandHandlers\SetTimeoutCommandHandler.h" />
263263
<ClInclude Include="CommandHandlers\SetWindowPositionCommandHandler.h" />
264264
<ClInclude Include="CommandHandlers\SetWindowSizeCommandHandler.h" />
265+
<ClInclude Include="CommandHandlers\SwitchToParentFrameCommandHandler.h" />
265266
<ClInclude Include="DocumentHost.h" />
266267
<ClInclude Include="Element.h" />
267268
<ClInclude Include="ElementFinder.h" />

cpp/iedriver/IEDriver.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@
349349
<ClInclude Include="ProxyManager.h">
350350
<Filter>Header Files</Filter>
351351
</ClInclude>
352+
<ClInclude Include="CommandHandlers\SwitchToParentFrameCommandHandler.h">
353+
<Filter>Header Files\CommandHandlers</Filter>
354+
</ClInclude>
352355
</ItemGroup>
353356
<ItemGroup>
354357
<None Include="IEDriver.def">

cpp/iedriverserver/CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ available via the project downloads page. Changes in "revision" field indicate
99
private releases checked into the prebuilts directory of the source tree, but
1010
not made generally available on the downloads page.
1111

12+
v2.42.0.1
13+
=========
14+
* Implemented switchToParentFrame command.
15+
1216
v2.42.0.0
1317
=========
1418
* Release to synchronize with release of Selenium project.

cpp/iedriverserver/IEDriverServer.rc

0 Bytes
Binary file not shown.
Binary file not shown.
6.5 KB
Binary file not shown.

dotnet/test/common/FrameSwitchingTest.cs

-4
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ public void ShouldThrowAnExceptionWhenAFrameCannotBeFoundByIndex()
197197

198198
[Test]
199199
[IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")]
200-
[IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")]
201200
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
202201
[IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")]
203202
[IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]
@@ -212,7 +211,6 @@ public void ShouldBeAbleToSwitchToParentFrame()
212211

213212
[Test]
214213
[IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")]
215-
[IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")]
216214
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
217215
[IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")]
218216
[IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]
@@ -228,7 +226,6 @@ public void ShouldBeAbleToSwitchToParentFrameFromASecondLevelFrame()
228226

229227
[Test]
230228
[IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")]
231-
[IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")]
232229
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
233230
[IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")]
234231
[IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]
@@ -243,7 +240,6 @@ public void SwitchingToParentFrameFromDefaultContextIsNoOp()
243240

244241
[Test]
245242
[IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")]
246-
[IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")]
247243
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
248244
[IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")]
249245
[IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]

0 commit comments

Comments
 (0)