Skip to content

Commit

Permalink
Adding new window commands to .NET bindings
Browse files Browse the repository at this point in the history
Adding the MinimizeWindow and FullScreenWindow commands to the .NET
bindings.
  • Loading branch information
jimevans committed Aug 31, 2017
1 parent 08a118b commit d6d0cb6
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
12 changes: 11 additions & 1 deletion dotnet/src/webdriver/IWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="IWindow.cs" company="WebDriver Committers">
// <copyright file="IWindow.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
Expand Down Expand Up @@ -41,5 +41,15 @@ public interface IWindow
/// Maximizes the current window if it is not already maximized.
/// </summary>
void Maximize();

/// <summary>
/// Minimizes the current window if it is not already maximized.
/// </summary>
void Minimize();

/// <summary>
/// Sets the current window to full screen if it is not already in that state.
/// </summary>
void FullScreen();
}
}
20 changes: 19 additions & 1 deletion dotnet/src/webdriver/Remote/RemoteWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="RemoteWindow.cs" company="WebDriver Committers">
// <copyright file="RemoteWindow.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
Expand Down Expand Up @@ -139,5 +139,23 @@ public void Maximize()

this.driver.InternalExecute(DriverCommand.MaximizeWindow, parameters);
}

/// <summary>
/// Minimizes the current window if it is not already maximized.
/// </summary>
public void Minimize()
{
Dictionary<string, object> parameters = null;
this.driver.InternalExecute(DriverCommand.MinimizeWindow, parameters);
}

/// <summary>
/// Sets the current window to full screen if it is not already in that state.
/// </summary>
public void FullScreen()
{
Dictionary<string, object> parameters = null;
this.driver.InternalExecute(DriverCommand.FullScreenWindow, parameters);
}
}
}
72 changes: 70 additions & 2 deletions dotnet/test/common/WindowTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;
using NUnit.Framework;

Expand Down Expand Up @@ -90,6 +90,60 @@ public void ShouldBeAbleToSetThePositionOfTheCurrentWindow()
}


[Test]
[IgnoreBrowser(Browser.Safari, "Not implemented in driver")]
[IgnoreBrowser(Browser.Edge, "Not implemented in driver")]
[IgnoreBrowser(Browser.Chrome, "Not implemented in driver")]
[IgnoreBrowser(Browser.Firefox, "Not implemented in driver")]
[IgnoreBrowser(Browser.HtmlUnit, "Not implemented in driver")]
[IgnoreBrowser(Browser.Opera, "Not implemented in driver")]
[IgnoreBrowser(Browser.Android, "Not implemented in driver")]
[IgnoreBrowser(Browser.IPhone, "Not implemented in driver")]
[IgnoreBrowser(Browser.WindowsPhone, "Not implemented in mobile driver")]
[IgnoreBrowser(Browser.PhantomJS, "As a headless browser, there is no position of the window.")]
public void ShouldBeAbleToFullScreenTheCurrentWindow()
{
Size targetSize = new Size(450, 275);

ChangeSizeTo(targetSize);

FullScreen();

IWindow window = driver.Manage().Window;
Size windowSize = window.Size;
Point windowPosition = window.Position;
Assert.Greater(windowSize.Height, targetSize.Height);
Assert.Greater(windowSize.Width, targetSize.Width);
}

[Test]
[IgnoreBrowser(Browser.Safari, "Not implemented in driver")]
[IgnoreBrowser(Browser.Edge, "Not implemented in driver")]
[IgnoreBrowser(Browser.Chrome, "Not implemented in driver")]
[IgnoreBrowser(Browser.Firefox, "Not implemented in driver")]
[IgnoreBrowser(Browser.HtmlUnit, "Not implemented in driver")]
[IgnoreBrowser(Browser.Opera, "Not implemented in driver")]
[IgnoreBrowser(Browser.Android, "Not implemented in driver")]
[IgnoreBrowser(Browser.IPhone, "Not implemented in driver")]
[IgnoreBrowser(Browser.WindowsPhone, "Not implemented in mobile driver")]
[IgnoreBrowser(Browser.PhantomJS, "As a headless browser, there is no position of the window.")]
public void ShouldBeAbleToMinimizeTheCurrentWindow()
{
Size targetSize = new Size(450, 275);

ChangeSizeTo(targetSize);

Minimize();

IWindow window = driver.Manage().Window;
Size windowSize = window.Size;
Point windowPosition = window.Position;
Assert.Less(windowSize.Height, targetSize.Height);
Assert.Less(windowSize.Width, targetSize.Width);
Assert.Less(windowPosition.X, 0);
Assert.Less(windowPosition.Y, 0);
}

[Test]
[IgnoreBrowser(Browser.HtmlUnit, "Not implemented in driver")]
[IgnoreBrowser(Browser.Opera, "Not implemented in driver")]
Expand Down Expand Up @@ -156,6 +210,13 @@ public void ShouldBeAbleToMaximizeTheWindowFromIframe()
}
}

private void FullScreen()
{
IWindow window = driver.Manage().Window;
Size currentSize = window.Size;
window.FullScreen();
}

private void Maximize()
{
IWindow window = driver.Manage().Window;
Expand All @@ -165,6 +226,13 @@ private void Maximize()
WaitFor(WindowWidthToBeGreaterThan(currentSize.Width), "Window width was not greater than " + currentSize.Width.ToString());
}

private void Minimize()
{
IWindow window = driver.Manage().Window;
Size currentSize = window.Size;
window.Minimize();
}

private void ChangeSizeTo(Size targetSize)
{
IWindow window = driver.Manage().Window;
Expand Down Expand Up @@ -193,4 +261,4 @@ private Func<bool> WindowWidthToBeGreaterThan(int width)
return () => { return driver.Manage().Window.Size.Width > width; };
}
}
}
}

0 comments on commit d6d0cb6

Please sign in to comment.