Skip to content

Commit 2f1c791

Browse files
yvsvarmasandeepsuryaprasad
authored andcommitted
[dotnet] Enhance Print PageSize class to support for predefined well-known sizes (SeleniumHQ#15144)
1 parent 107c6fe commit 2f1c791

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

dotnet/src/webdriver/PrintOptions.cs

+24
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,30 @@ public class PageSize
259259
private double height = DefaultPageHeight;
260260
private double width = DefaultPageWidth;
261261

262+
/// <summary>
263+
/// Represents the A4 paper size.
264+
/// Width: 21.0 cm, Height: 29.7 cm
265+
/// </summary>
266+
public static PageSize A4 => new PageSize { Width = 21.0, Height = 29.7 }; // cm
267+
268+
/// <summary>
269+
/// Represents the Legal paper size.
270+
/// Width: 21.59 cm, Height: 35.56 cm
271+
/// </summary>
272+
public static PageSize Legal => new PageSize { Width = 21.59, Height = 35.56 }; // cm
273+
274+
/// <summary>
275+
/// Represents the Letter paper size.
276+
/// Width: 21.59 cm, Height: 27.94 cm
277+
/// </summary>
278+
public static PageSize Letter => new PageSize { Width = 21.59, Height = 27.94 }; // cm
279+
280+
/// <summary>
281+
/// Represents the Tabloid paper size.
282+
/// Width: 27.94 cm, Height: 43.18 cm
283+
/// </summary>
284+
public static PageSize Tabloid => new PageSize { Width = 27.94, Height = 43.18 }; // cm
285+
262286
/// <summary>
263287
/// Gets or sets the height of each page in centimeters.
264288
/// </summary>

dotnet/test/common/PrintTest.cs

+35
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,40 @@ public void MarginsCannotHaveNegativeValues()
122122
Assert.That(() => new PrintOptions.Margins { Left = -1 }, Throws.TypeOf<ArgumentOutOfRangeException>());
123123
Assert.That(() => new PrintOptions.Margins { Right = -1 }, Throws.TypeOf<ArgumentOutOfRangeException>());
124124
}
125+
126+
[Test]
127+
public void CanSetPredefinedPageSizes()
128+
{
129+
var options = new PrintOptions();
130+
131+
options.PageDimensions = PrintOptions.PageSize.A4;
132+
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.A4.Width));
133+
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.A4.Height));
134+
135+
options.PageDimensions = PrintOptions.PageSize.Legal;
136+
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Legal.Width));
137+
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Legal.Height));
138+
139+
options.PageDimensions = PrintOptions.PageSize.Letter;
140+
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Letter.Width));
141+
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Letter.Height));
142+
143+
options.PageDimensions = PrintOptions.PageSize.Tabloid;
144+
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Tabloid.Width));
145+
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Tabloid.Height));
146+
}
147+
148+
[Test]
149+
public void CanSetCustomPageSize()
150+
{
151+
var options = new PrintOptions();
152+
var customPageSize = new PrintOptions.PageSize { Width = 25.0, Height = 30.0 };
153+
154+
options.PageDimensions = customPageSize;
155+
156+
Assert.That(options.PageDimensions.Width, Is.EqualTo(25.0));
157+
Assert.That(options.PageDimensions.Height, Is.EqualTo(30.0));
158+
}
159+
125160
}
126161
}

0 commit comments

Comments
 (0)