Skip to content

Commit

Permalink
Merge branch 'trunk' into fix-SeleniumManager
Browse files Browse the repository at this point in the history
  • Loading branch information
VietND96 authored Oct 16, 2024
2 parents c363bd9 + a98248d commit cbb17e4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
12 changes: 10 additions & 2 deletions dotnet/src/webdriver/PrintOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,27 @@ public bool ShrinkToFit
}

/// <summary>
/// Gets the dimensions for each page in the printed document.
/// Gets or sets the dimensions for each page in the printed document.
/// </summary>
public PageSize PageDimensions
{
get { return pageSize; }
set
{
pageSize = value ?? throw new ArgumentNullException(nameof(value));
}
}

/// <summary>
/// Gets the margins for each page in the doucment.
/// Gets or sets the margins for each page in the doucment.
/// </summary>
public Margins PageMargins
{
get { return margins; }
set
{
margins = value ?? throw new ArgumentNullException(nameof(value));
}
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions dotnet/test/common/DriverTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public abstract class DriverTestFixture
public string scrollFrameOutOfViewport = EnvironmentManager.Instance.UrlBuilder.WhereIs("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html");
public string scrollFrameInViewport = EnvironmentManager.Instance.UrlBuilder.WhereIs("scrolling_tests/frame_with_nested_scrolling_frame.html");

public string printPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("printPage.html");

protected IWebDriver driver;

public IWebDriver DriverInstance
Expand Down
74 changes: 74 additions & 0 deletions dotnet/test/common/PrintTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using NUnit.Framework;
using System;

namespace OpenQA.Selenium
{
[TestFixture]
public class PrintTest : DriverTestFixture
{
private const string MagicString = "JVBER";
private ISupportsPrint printer;

[SetUp]
public void LocalSetUp()
{
Assert.That(driver, Is.InstanceOf<ISupportsPrint>(), $"Driver does not support {nameof(ISupportsPrint)}.");

printer = driver as ISupportsPrint;

driver.Navigate().GoToUrl(this.printPage);
}

[Test]
public void CanPrintPage()
{
var pdf = printer.Print(new PrintOptions());

Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
}

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

options.AddPageRangeToPrint("1-2");

var pdf = printer.Print(options);

Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
}

[Test]
public void CanPrintWithMostParams()
{
var options = new PrintOptions()
{
Orientation = PrintOrientation.Landscape,
ScaleFactor = 0.5,
PageDimensions = new PrintOptions.PageSize { Width = 200, Height = 100 },
PageMargins = new PrintOptions.Margins { Top = 1, Bottom = 1, Left = 2, Right = 2 },
OutputBackgroundImages = true,
ShrinkToFit = false
};

options.AddPageRangeToPrint("1-3");

var pdf = printer.Print(options);

Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
}

[Test]
public void PageSizeCannotBeNull()
{
Assert.That(() => new PrintOptions { PageDimensions = null }, Throws.InstanceOf<ArgumentNullException>());
}

[Test]
public void MarginsCannotBeNull()
{
Assert.That(() => new PrintOptions { PageMargins = null }, Throws.InstanceOf<ArgumentNullException>());
}
}
}

0 comments on commit cbb17e4

Please sign in to comment.