Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 26e96ef

Browse files
andrewnicolsOndraM
authored andcommitted
Add switch to parent frame command
Part of #683
1 parent ec98c9a commit 26e96ef

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

lib/Remote/HttpCommandExecutor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class HttpCommandExecutor implements WebDriverCommandExecutor
5151
DriverCommand::FIND_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element'],
5252
DriverCommand::FIND_ELEMENTS => ['method' => 'POST', 'url' => '/session/:sessionId/elements'],
5353
DriverCommand::SWITCH_TO_FRAME => ['method' => 'POST', 'url' => '/session/:sessionId/frame'],
54+
DriverCommand::SWITCH_TO_PARENT_FRAME => ['method' => 'POST', 'url' => '/session/:sessionId/frame/parent'],
5455
DriverCommand::SWITCH_TO_WINDOW => ['method' => 'POST', 'url' => '/session/:sessionId/window'],
5556
DriverCommand::GET => ['method' => 'POST', 'url' => '/session/:sessionId/url'],
5657
DriverCommand::GET_ACTIVE_ELEMENT => ['method' => 'POST', 'url' => '/session/:sessionId/element/active'],

lib/Remote/RemoteTargetLocator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ public function frame($frame)
9797
return $this->driver;
9898
}
9999

100+
/**
101+
* Switch to the parent iframe.
102+
*
103+
* @return WebDriver The driver focused on the given frame.
104+
*/
105+
public function parent()
106+
{
107+
$this->executor->execute(DriverCommand::SWITCH_TO_PARENT_FRAME, []);
108+
109+
return $this->driver;
110+
}
111+
100112
/**
101113
* Switch the focus to another window by its handle.
102114
*

lib/WebDriverTargetLocator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public function defaultContent();
3737
*/
3838
public function frame($frame);
3939

40+
///**
41+
// * Switch to the parent iframe.
42+
// *
43+
// * @todo Add in next major release (BC)
44+
// * @return WebDriver The driver focused on the given frame.
45+
// */
46+
//public function parent();
47+
4048
/**
4149
* Switch the focus to another window by its handle.
4250
*

tests/functional/RemoteTargetLocatorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ public function testShouldSwitchToFrameByItsId()
9292
$this->assertContains($parentPage, $this->driver->getPageSource());
9393
}
9494

95+
public function testShouldSwitchToParentFrame()
96+
{
97+
$parentPage = 'This is the host page which contains an iFrame';
98+
$firstChildFrame = 'This is the content of the iFrame';
99+
100+
$this->driver->get($this->getTestPageUrl('page_with_frame.html'));
101+
102+
$this->assertContains($parentPage, $this->driver->getPageSource());
103+
104+
$this->driver->switchTo()->frame(0);
105+
$this->assertContains($firstChildFrame, $this->driver->getPageSource());
106+
107+
$this->driver->switchTo()->parent();
108+
$this->assertContains($parentPage, $this->driver->getPageSource());
109+
}
110+
95111
public function testShouldSwitchToFrameByElement()
96112
{
97113
$this->driver->get($this->getTestPageUrl('page_with_frame.html'));

0 commit comments

Comments
 (0)