Skip to content

Commit

Permalink
Adding support for SwitchTo().ParentFrame() in .NET bindings
Browse files Browse the repository at this point in the history
This brings the .NET bindings into parity with other languages. Fixes
issue #7419.
  • Loading branch information
jimevans committed Jun 2, 2014
1 parent 88dcffe commit f5b3934
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
20 changes: 20 additions & 0 deletions dotnet/src/support/Events/EventFiringWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,26 @@ public IWebDriver Frame(IWebElement frameElement)
return driver;
}

/// <summary>
/// Select the parent frame of the currently selected frame.
/// </summary>
/// <returns>An <see cref="IWebDriver"/> instance focused on the specified frame.</returns>
public IWebDriver ParentFrame()
{
IWebDriver driver = null;
try
{
driver = this.wrappedLocator.ParentFrame();
}
catch (Exception ex)
{
this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex));
throw;
}

return driver;
}

/// <summary>
/// Change to the Window by passing in the name
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions dotnet/src/webdriver/ITargetLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public interface ITargetLocator
/// <exception cref="StaleElementReferenceException">If the element is no longer valid.</exception>
IWebDriver Frame(IWebElement frameElement);

/// <summary>
/// Select the parent frame of the currently selected frame.
/// </summary>
/// <returns>An <see cref="IWebDriver"/> instance focused on the specified frame.</returns>
IWebDriver ParentFrame();

/// <summary>
/// Switches the focus of future commands for this driver to the window with the given name.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/webdriver/Remote/CommandInfoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ private void InitializeCommandDictionary()
this.commandDictionary.Add(DriverCommand.ExecuteAsyncScript, new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/execute_async"));
this.commandDictionary.Add(DriverCommand.Screenshot, new CommandInfo(CommandInfo.GetCommand, "/session/{sessionId}/screenshot"));
this.commandDictionary.Add(DriverCommand.SwitchToFrame, new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/frame"));
this.commandDictionary.Add(DriverCommand.SwitchToParentFrame, new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/frame/parent"));
this.commandDictionary.Add(DriverCommand.SwitchToWindow, new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/window"));
this.commandDictionary.Add(DriverCommand.GetAllCookies, new CommandInfo(CommandInfo.GetCommand, "/session/{sessionId}/cookie"));
this.commandDictionary.Add(DriverCommand.AddCookie, new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/cookie"));
Expand Down
5 changes: 5 additions & 0 deletions dotnet/src/webdriver/Remote/DriverCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public static class DriverCommand
/// </summary>
public static readonly string SwitchToFrame = "switchToFrame";

/// <summary>
/// Represents SwitchToParentFrame command
/// </summary>
public static readonly string SwitchToParentFrame = "switchToParentFrame";

/// <summary>
/// Represents GetActiveElement command
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions dotnet/src/webdriver/Remote/RemoteTargetLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ public IWebDriver Frame(IWebElement frameElement)
return this.driver;
}

/// <summary>
/// Select the parent frame of the currently selected frame.
/// </summary>
/// <returns>An <see cref="IWebDriver"/> instance focused on the specified frame.</returns>
public IWebDriver ParentFrame()
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
this.driver.InternalExecute(DriverCommand.SwitchToParentFrame, parameters);
return this.driver;
}

/// <summary>
/// Change to the Window by passing in the name
/// </summary>
Expand Down
63 changes: 63 additions & 0 deletions dotnet/test/common/FrameSwitchingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,69 @@ public void ShouldThrowAnExceptionWhenAFrameCannotBeFoundByIndex()
driver.SwitchTo().Frame(27);
}

[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")]
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Opera, "Browser does not support parent frame navigation")]
public void ShouldBeAbleToSwitchToParentFrame()
{
driver.Url = framesetPage;
driver.SwitchTo().Frame("fourth").SwitchTo().ParentFrame().SwitchTo().Frame("first");
Assert.AreEqual("1", driver.FindElement(By.Id("pageNumber")).Text);
}

[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")]
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Opera, "Browser does not support parent frame navigation")]
public void ShouldBeAbleToSwitchToParentFrameFromASecondLevelFrame()
{
driver.Url = framesetPage;

driver.SwitchTo().Frame("fourth").SwitchTo().Frame("child1").SwitchTo().ParentFrame().SwitchTo().Frame("child2");
Assert.AreEqual("11", driver.FindElement(By.Id("pageNumber")).Text);
}

[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")]
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Opera, "Browser does not support parent frame navigation")]
public void SwitchingToParentFrameFromDefaultContextIsNoOp()
{
driver.Url = xhtmlTestPage;
driver.SwitchTo().ParentFrame();
Assert.AreEqual("XHTML Test Page", driver.Title);
}

[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")]
[IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")]
[IgnoreBrowser(Browser.Opera, "Browser does not support parent frame navigation")]
public void ShouldBeAbleToSwitchToParentFromAnIframe()
{
driver.Url = iframePage;
driver.SwitchTo().Frame(0);

driver.SwitchTo().ParentFrame();
driver.FindElement(By.Id("iframe_page_heading"));
}

// ----------------------------------------------------------------------------------------------
//
// General frame handling behavior tests
Expand Down

0 comments on commit f5b3934

Please sign in to comment.