-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Tranquire.Selenium/Actions/Window/FullScreenWindowAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Tranquire.Selenium.Actions.Window | ||
{ | ||
/// <summary> | ||
/// Set the window in full screen | ||
/// </summary> | ||
public class FullScreenWindowAction : ActionBaseUnit<WebBrowser> | ||
{ | ||
/// <inheritdoc /> | ||
public override string Name => "Full screen Window"; | ||
|
||
/// <summary> | ||
/// Execute the action | ||
/// </summary> | ||
/// <param name="actor"></param> | ||
/// <param name="ability"></param> | ||
protected override void ExecuteWhen(IActor actor, WebBrowser ability) | ||
{ | ||
ability.Driver.Manage().Window.FullScreen(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Tranquire.Selenium/Actions/Window/MaximizeWindowAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Drawing; | ||
|
||
namespace Tranquire.Selenium.Actions.Window | ||
{ | ||
/// <summary> | ||
/// Maximizes the window | ||
/// </summary> | ||
public class MaximizeWindowAction : ActionBaseUnit<WebBrowser> | ||
{ | ||
/// <inheritdoc /> | ||
public override string Name => "Maximize Window"; | ||
|
||
/// <summary> | ||
/// Execute the action | ||
/// </summary> | ||
/// <param name="actor"></param> | ||
/// <param name="ability"></param> | ||
protected override void ExecuteWhen(IActor actor, WebBrowser ability) | ||
{ | ||
ability.Driver.Manage().Window.Maximize(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Tranquire.Selenium/Actions/Window/MinimizeWindowAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Tranquire.Selenium.Actions.Window | ||
{ | ||
/// <summary> | ||
/// Minimizes the window | ||
/// </summary> | ||
public class MinimizeWindowAction : ActionBaseUnit<WebBrowser> | ||
{ | ||
/// <inheritdoc /> | ||
public override string Name => "Minimize Window"; | ||
|
||
/// <summary> | ||
/// Execute the action | ||
/// </summary> | ||
/// <param name="actor"></param> | ||
/// <param name="ability"></param> | ||
protected override void ExecuteWhen(IActor actor, WebBrowser ability) | ||
{ | ||
ability.Driver.Manage().Window.Minimize(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Tranquire.Selenium/Actions/Window/ResizeWindowAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Drawing; | ||
|
||
namespace Tranquire.Selenium.Actions.Window | ||
{ | ||
/// <summary> | ||
/// Contains actions for resizing the window | ||
/// </summary> | ||
public class ResizeWindowAction : ActionBaseUnit<WebBrowser> | ||
{ | ||
private readonly Size _size; | ||
|
||
/// <inheritdoc /> | ||
public override string Name => "Resize Window"; | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="ResizeWindowAction" /> | ||
/// </summary> | ||
/// <param name="size"></param> | ||
public ResizeWindowAction(Size size) | ||
{ | ||
_size = size; | ||
} | ||
|
||
/// <summary> | ||
/// Execute the action | ||
/// </summary> | ||
/// <param name="actor"></param> | ||
/// <param name="ability"></param> | ||
protected override void ExecuteWhen(IActor actor, WebBrowser ability) | ||
{ | ||
ability.Driver.Manage().Window.Size = _size; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Text; | ||
using Tranquire.Selenium.Actions.Window; | ||
using Tranquire.Selenium.Questions; | ||
|
||
namespace Tranquire.Selenium | ||
{ | ||
/// <summary> | ||
/// Contains actions about the web browser window | ||
/// </summary> | ||
public static class WebBrowserWindow | ||
{ | ||
/// <summary> | ||
/// Create an action that resizes the window | ||
/// </summary> | ||
/// <param name="size">The new size</param> | ||
/// <returns></returns> | ||
public static IAction<Unit> Resize(Size size) => new ResizeWindowAction(size); | ||
|
||
/// <summary> | ||
/// Create an action that maximizes the windows | ||
/// </summary> | ||
/// <returns></returns> | ||
public static IAction<Unit> Maximize() => new MaximizeWindowAction(); | ||
|
||
/// <summary> | ||
/// Create an action that minimizes the windows | ||
/// </summary> | ||
/// <returns></returns> | ||
public static IAction<Unit> Minimize() => new MinimizeWindowAction(); | ||
|
||
/// <summary> | ||
/// Create an action that maximizes the windows | ||
/// </summary> | ||
/// <returns></returns> | ||
public static IAction<Unit> FullScreen() => new FullScreenWindowAction(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Tranquire.Selenium.Tests.Actions | ||
{ | ||
public class WindowTests : WebDriverTest | ||
{ | ||
public WindowTests(WebDriverFixture fixture) : base(fixture, "Window.html") | ||
{ | ||
|
||
} | ||
|
||
[Fact] | ||
public void ResizeTest() | ||
{ | ||
var size = Fixture.WebDriver.Manage().Window.Size; | ||
try | ||
{ | ||
var expected = new Size(516, 560); | ||
Fixture.Actor.When(WebBrowserWindow.Resize(expected)); | ||
var actual = Fixture.WebDriver.Manage().Window.Size; | ||
Assert.Equal(expected, actual); | ||
} | ||
finally | ||
{ | ||
Fixture.WebDriver.Manage().Window.Size = size; | ||
} | ||
} | ||
|
||
[Fact] | ||
public void MaximizeTest() | ||
{ | ||
var restoreSize = Fixture.WebDriver.Manage().Window.Size; | ||
try | ||
{ | ||
var size = new Size(400, 400); | ||
Fixture.Actor.Given(WebBrowserWindow.Resize(size)); | ||
Fixture.Actor.When(WebBrowserWindow.Maximize()); | ||
var actual = Fixture.WebDriver.Manage().Window.Size; | ||
Assert.True(actual.Width > size.Width && actual.Height > size.Height, $"Actual: {actual}; Previous: {size}"); | ||
Assert.Equal(new Point(-8, -8), Fixture.WebDriver.Manage().Window.Position); | ||
} | ||
finally | ||
{ | ||
Fixture.WebDriver.Manage().Window.Size = restoreSize; | ||
} | ||
} | ||
|
||
[Fact] | ||
public void MinimizeTest() | ||
{ | ||
var restoreSize = Fixture.WebDriver.Manage().Window.Size; | ||
try | ||
{ | ||
var size = new Size(400, 400); | ||
Fixture.Actor.Given(WebBrowserWindow.Resize(size)); | ||
Fixture.Actor.When(WebBrowserWindow.Minimize()); | ||
var actual = Fixture.WebDriver.Manage().Window.Size; | ||
//Assert.True(actual.Width == size.Width && actual.Height == size.Height, $"Actual: {actual}; Previous: {size}"); | ||
Assert.Equal(new Point(10, 10), Fixture.WebDriver.Manage().Window.Position); | ||
} | ||
finally | ||
{ | ||
Fixture.WebDriver.Manage().Window.Size = restoreSize; | ||
} | ||
} | ||
|
||
[Fact] | ||
public void FullScreenTest() | ||
{ | ||
var restoreSize = Fixture.WebDriver.Manage().Window.Size; | ||
try | ||
{ | ||
var size = new Size(400, 400); | ||
Fixture.Actor.Given(WebBrowserWindow.Resize(size)); | ||
Fixture.Actor.When(WebBrowserWindow.FullScreen()); | ||
var actual = Fixture.WebDriver.Manage().Window.Size; | ||
Assert.True(actual.Width > size.Width && actual.Height > size.Height, $"Actual: {actual}; Previous: {size}"); | ||
Assert.Equal(Point.Empty, Fixture.WebDriver.Manage().Window.Position); | ||
} | ||
finally | ||
{ | ||
Fixture.WebDriver.Manage().Window.Size = restoreSize; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Window</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |