|
| 1 | +using NUnit.Framework; |
| 2 | + |
| 3 | +namespace OpenQA.Selenium |
| 4 | +{ |
| 5 | + [TestFixture] |
| 6 | + public class PrintTest : DriverTestFixture |
| 7 | + { |
| 8 | + private const string MagicString = "JVBER"; |
| 9 | + private ISupportsPrint printer; |
| 10 | + |
| 11 | + [SetUp] |
| 12 | + public void LocalSetUp() |
| 13 | + { |
| 14 | + Assert.That(driver, Is.InstanceOf<ISupportsPrint>(), $"Driver does not support {nameof(ISupportsPrint)}."); |
| 15 | + |
| 16 | + printer = driver as ISupportsPrint; |
| 17 | + |
| 18 | + driver.Navigate().GoToUrl(this.printPage); |
| 19 | + } |
| 20 | + |
| 21 | + [Test] |
| 22 | + public void CanPrintPage() |
| 23 | + { |
| 24 | + var pdf = printer.Print(new PrintOptions()); |
| 25 | + |
| 26 | + Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString), "Printed PDF does not contain the expected magic string."); |
| 27 | + } |
| 28 | + |
| 29 | + //[Test] |
| 30 | + //[Ignore("Skipped for Chrome because it needs to run headless, a workaround is needed.")] |
| 31 | + //public void CanPrintTwoPages() |
| 32 | + //{ |
| 33 | + // PrintOptions printOptions = new PrintOptions |
| 34 | + // { |
| 35 | + // PageRanges = "1-2" |
| 36 | + // }; |
| 37 | + |
| 38 | + // var pdf = printer.Print(printOptions); |
| 39 | + // Assert.That(pdf.Content.Contains(MAGIC_STRING), Is.True, "Printed PDF does not contain the expected magic string."); |
| 40 | + //} |
| 41 | + |
| 42 | + //[Test] |
| 43 | + //[Ignore("Skipped for Chrome because it needs to run headless, a workaround is needed.")] |
| 44 | + //public void CanPrintWithValidParams() |
| 45 | + //{ |
| 46 | + // PrintOptions printOptions = new PrintOptions(); |
| 47 | + |
| 48 | + // //set all options |
| 49 | + // printOptions.PageRanges = "1"; |
| 50 | + // printOptions.Orientation = PrintOrientation.Landscape; |
| 51 | + // printOptions.PageSize = new PageSize(); |
| 52 | + // printOptions.Scale = 0.5; |
| 53 | + // printOptions.DisplayHeaderFooter = true; |
| 54 | + // printOptions.HeaderTemplate = "Header"; |
| 55 | + // printOptions.FooterTemplate = "Footer"; |
| 56 | + // printOptions.PrintBackground = true; |
| 57 | + // printOptions.shrinkToFit = true; |
| 58 | + |
| 59 | + // var pdf = printer.Print(printOptions); |
| 60 | + // Assert.That(pdf.Content.Contains(MAGIC_STRING), Is.True, "Printed PDF does not contain the expected magic string."); |
| 61 | + //} |
| 62 | + } |
| 63 | +} |
0 commit comments