|
| 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