Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Enhance PrintOptions class to support for predefined and cus… #15144

Merged
merged 13 commits into from
Jan 26, 2025
Merged
24 changes: 24 additions & 0 deletions dotnet/src/webdriver/PrintOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,30 @@ public class PageSize
private double height = DefaultPageHeight;
private double width = DefaultPageWidth;

/// <summary>
/// Represents the A4 paper size.
/// Width: 21.0 cm, Height: 29.7 cm
/// </summary>
public static PageSize A4 => new PageSize { Width = 21.0, Height = 29.7 }; // cm

/// <summary>
/// Represents the Legal paper size.
/// Width: 21.59 cm, Height: 35.56 cm
/// </summary>
public static PageSize Legal => new PageSize { Width = 21.59, Height = 35.56 }; // cm

/// <summary>
/// Represents the Letter paper size.
/// Width: 21.59 cm, Height: 27.94 cm
/// </summary>
public static PageSize Letter => new PageSize { Width = 21.59, Height = 27.94 }; // cm

/// <summary>
/// Represents the Tabloid paper size.
/// Width: 27.94 cm, Height: 43.18 cm
/// </summary>
public static PageSize Tabloid => new PageSize { Width = 27.94, Height = 43.18 }; // cm

/// <summary>
/// Gets or sets the height of each page in centimeters.
/// </summary>
Expand Down
35 changes: 35 additions & 0 deletions dotnet/test/common/PrintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,40 @@ public void MarginsCannotHaveNegativeValues()
Assert.That(() => new PrintOptions.Margins { Left = -1 }, Throws.TypeOf<ArgumentOutOfRangeException>());
Assert.That(() => new PrintOptions.Margins { Right = -1 }, Throws.TypeOf<ArgumentOutOfRangeException>());
}

[Test]
public void CanSetPredefinedPageSizes()
{
var options = new PrintOptions();

options.PageDimensions = PrintOptions.PageSize.A4;
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.A4.Width));
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.A4.Height));

options.PageDimensions = PrintOptions.PageSize.Legal;
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Legal.Width));
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Legal.Height));

options.PageDimensions = PrintOptions.PageSize.Letter;
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Letter.Width));
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Letter.Height));

options.PageDimensions = PrintOptions.PageSize.Tabloid;
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Tabloid.Width));
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Tabloid.Height));
}

[Test]
public void CanSetCustomPageSize()
{
var options = new PrintOptions();
var customPageSize = new PrintOptions.PageSize { Width = 25.0, Height = 30.0 };

options.PageDimensions = customPageSize;

Assert.That(options.PageDimensions.Width, Is.EqualTo(25.0));
Assert.That(options.PageDimensions.Height, Is.EqualTo(30.0));
}

yvsvarma marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading