diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index b1f3efd30692e..27375a0a72d1e 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -259,6 +259,30 @@ public class PageSize private double height = DefaultPageHeight; private double width = DefaultPageWidth; + /// + /// Represents the A4 paper size. + /// Width: 21.0 cm, Height: 29.7 cm + /// + public static PageSize A4 => new PageSize { Width = 21.0, Height = 29.7 }; // cm + + /// + /// Represents the Legal paper size. + /// Width: 21.59 cm, Height: 35.56 cm + /// + public static PageSize Legal => new PageSize { Width = 21.59, Height = 35.56 }; // cm + + /// + /// Represents the Letter paper size. + /// Width: 21.59 cm, Height: 27.94 cm + /// + public static PageSize Letter => new PageSize { Width = 21.59, Height = 27.94 }; // cm + + /// + /// Represents the Tabloid paper size. + /// Width: 27.94 cm, Height: 43.18 cm + /// + public static PageSize Tabloid => new PageSize { Width = 27.94, Height = 43.18 }; // cm + /// /// Gets or sets the height of each page in centimeters. /// diff --git a/dotnet/test/common/PrintTest.cs b/dotnet/test/common/PrintTest.cs index 324fc6e399c48..7d67e9f83bbc7 100644 --- a/dotnet/test/common/PrintTest.cs +++ b/dotnet/test/common/PrintTest.cs @@ -122,5 +122,40 @@ public void MarginsCannotHaveNegativeValues() Assert.That(() => new PrintOptions.Margins { Left = -1 }, Throws.TypeOf()); Assert.That(() => new PrintOptions.Margins { Right = -1 }, Throws.TypeOf()); } + + [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)); + } + } }