Skip to content

Commit cbb17e4

Browse files
authored
Merge branch 'trunk' into fix-SeleniumManager
2 parents c363bd9 + a98248d commit cbb17e4

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

dotnet/src/webdriver/PrintOptions.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,27 @@ public bool ShrinkToFit
101101
}
102102

103103
/// <summary>
104-
/// Gets the dimensions for each page in the printed document.
104+
/// Gets or sets the dimensions for each page in the printed document.
105105
/// </summary>
106106
public PageSize PageDimensions
107107
{
108108
get { return pageSize; }
109+
set
110+
{
111+
pageSize = value ?? throw new ArgumentNullException(nameof(value));
112+
}
109113
}
110114

111115
/// <summary>
112-
/// Gets the margins for each page in the doucment.
116+
/// Gets or sets the margins for each page in the doucment.
113117
/// </summary>
114118
public Margins PageMargins
115119
{
116120
get { return margins; }
121+
set
122+
{
123+
margins = value ?? throw new ArgumentNullException(nameof(value));
124+
}
117125
}
118126

119127
/// <summary>

dotnet/test/common/DriverTestFixture.cs

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public abstract class DriverTestFixture
8888
public string scrollFrameOutOfViewport = EnvironmentManager.Instance.UrlBuilder.WhereIs("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html");
8989
public string scrollFrameInViewport = EnvironmentManager.Instance.UrlBuilder.WhereIs("scrolling_tests/frame_with_nested_scrolling_frame.html");
9090

91+
public string printPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("printPage.html");
92+
9193
protected IWebDriver driver;
9294

9395
public IWebDriver DriverInstance

dotnet/test/common/PrintTest.cs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using NUnit.Framework;
2+
using System;
3+
4+
namespace OpenQA.Selenium
5+
{
6+
[TestFixture]
7+
public class PrintTest : DriverTestFixture
8+
{
9+
private const string MagicString = "JVBER";
10+
private ISupportsPrint printer;
11+
12+
[SetUp]
13+
public void LocalSetUp()
14+
{
15+
Assert.That(driver, Is.InstanceOf<ISupportsPrint>(), $"Driver does not support {nameof(ISupportsPrint)}.");
16+
17+
printer = driver as ISupportsPrint;
18+
19+
driver.Navigate().GoToUrl(this.printPage);
20+
}
21+
22+
[Test]
23+
public void CanPrintPage()
24+
{
25+
var pdf = printer.Print(new PrintOptions());
26+
27+
Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
28+
}
29+
30+
[Test]
31+
public void CanPrintTwoPages()
32+
{
33+
var options = new PrintOptions();
34+
35+
options.AddPageRangeToPrint("1-2");
36+
37+
var pdf = printer.Print(options);
38+
39+
Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
40+
}
41+
42+
[Test]
43+
public void CanPrintWithMostParams()
44+
{
45+
var options = new PrintOptions()
46+
{
47+
Orientation = PrintOrientation.Landscape,
48+
ScaleFactor = 0.5,
49+
PageDimensions = new PrintOptions.PageSize { Width = 200, Height = 100 },
50+
PageMargins = new PrintOptions.Margins { Top = 1, Bottom = 1, Left = 2, Right = 2 },
51+
OutputBackgroundImages = true,
52+
ShrinkToFit = false
53+
};
54+
55+
options.AddPageRangeToPrint("1-3");
56+
57+
var pdf = printer.Print(options);
58+
59+
Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
60+
}
61+
62+
[Test]
63+
public void PageSizeCannotBeNull()
64+
{
65+
Assert.That(() => new PrintOptions { PageDimensions = null }, Throws.InstanceOf<ArgumentNullException>());
66+
}
67+
68+
[Test]
69+
public void MarginsCannotBeNull()
70+
{
71+
Assert.That(() => new PrintOptions { PageMargins = null }, Throws.InstanceOf<ArgumentNullException>());
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)