Example #1
0
 public void Can_print_the_authorized_pdf()
 {
     var testLink = selenium.FindElement(By.LinkText("Logged In Test"));
     var pdfHref = testLink.GetAttribute("href");
     testLink.Click();
     var username = selenium.FindElement(By.Id("UserName"));
     username.SendKeys("admin");
     var password = selenium.FindElement(By.Id("Password"));
     password.SendKeys("admin");
     password.Submit();
     var manage = selenium.Manage();
     var cookies = manage.Cookies.AllCookies;
     using (var wc = new WebClient())
     {
         foreach (var cookie in cookies)
         {
             var cookieText = cookie.Name + "=" + cookie.Value;
             wc.Headers.Add(HttpRequestHeader.Cookie, cookieText);
         }
         var pdfResult = wc.DownloadData(new Uri(pdfHref));
         var pdfTester = new PdfTester();
         pdfTester.LoadPdf(pdfResult);
         pdfTester.PdfIsValid.Should().Be.True();
         pdfTester.PdfContains("My MVC Application").Should().Be.True();
         pdfTester.PdfContains("admin").Should().Be.True();
     }
 }
Example #2
0
        public void Can_print_the_authorized_pdf()
        {
            var testLink = selenium.FindElement(By.LinkText("Logged In Test"));
            var pdfHref  = testLink.GetAttribute("href");

            testLink.Click();
            var username = selenium.FindElement(By.Id("UserName"));

            username.SendKeys("admin");
            var password = selenium.FindElement(By.Id("Password"));

            password.SendKeys("admin");
            password.Submit();
            var manage  = selenium.Manage();
            var cookies = manage.Cookies.AllCookies;

            using (var wc = new WebClient())
            {
                foreach (var cookie in cookies)
                {
                    var cookieText = cookie.Name + "=" + cookie.Value;
                    wc.Headers.Add(HttpRequestHeader.Cookie, cookieText);
                }
                var pdfResult = wc.DownloadData(new Uri(pdfHref));
                var pdfTester = new PdfTester();
                pdfTester.LoadPdf(pdfResult);
                pdfTester.PdfIsValid.Should().Be.True();
                pdfTester.PdfContains("My MVC Application").Should().Be.True();
                pdfTester.PdfContains("admin").Should().Be.True();
            }
        }
Example #3
0
 public void Can_print_the_pdf_from_a_view()
 {
     var testLink = selenium.FindElement(By.LinkText("Test View"));
     var pdfHref = testLink.GetAttribute("href");
     using (var wc = new WebClient())
     {
         var pdfResult = wc.DownloadData(new Uri(pdfHref));
         var pdfTester = new PdfTester();
         pdfTester.LoadPdf(pdfResult);
         pdfTester.PdfIsValid.Should().Be.True();
         pdfTester.PdfContains("My MVC Application").Should().Be.True();
     }
 }
Example #4
0
 public void Can_print_the_pdf_from_a_view_with_a_model()
 {
     var testLink = selenium.FindElement(By.LinkText("Test ViewAsPdf with a model"));
     var pdfHref = testLink.GetAttribute("href");
     var title = "This is my test!";
     using (var wc = new WebClient())
     {
         var pdfResult = wc.DownloadData(new Uri(pdfHref + "/" + title));
         var pdfTester = new PdfTester();
         pdfTester.LoadPdf(pdfResult);
         pdfTester.PdfIsValid.Should().Be.True();
         pdfTester.PdfContains(title).Should().Be.True();
     }
 }
Example #5
0
        public void Can_print_the_test_pdf()
        {
            var testLink = selenium.FindElement(By.LinkText("Test"));
            var pdfHref  = testLink.GetAttribute("href");

            using (var wc = new WebClient())
            {
                var pdfResult = wc.DownloadData(new Uri(pdfHref));
                var pdfTester = new PdfTester();
                pdfTester.LoadPdf(pdfResult);
                pdfTester.PdfIsValid.Should().Be.True();
                pdfTester.PdfContains("My MVC Application").Should().Be.True();
            }
        }
Example #6
0
        public void Can_print_the_pdf_from_a_view_with_non_ascii_chars()
        {
            var testLink = selenium.FindElement(By.LinkText("Test View"));
            var pdfHref  = testLink.GetAttribute("href");

            using (var wc = new WebClient())
            {
                var pdfResult = wc.DownloadData(new Uri(pdfHref));
                var pdfTester = new PdfTester();
                pdfTester.LoadPdf(pdfResult);
                pdfTester.PdfIsValid.Should().Be.True();
                pdfTester.PdfContains("àéù").Should().Be.True();
            }
        }
Example #7
0
        public void Can_print_pdf_from_page_with_external_css_file()
        {
            var testLink = selenium.FindElement(By.LinkText("External CSS Test"));
            var pdfHref  = testLink.GetAttribute("href");
            var content  = "Hi guys, this content shows up thanks to css file.";

            using (var wc = new WebClient())
            {
                var pdfResult = wc.DownloadData(new Uri(pdfHref));
                var pdfTester = new PdfTester();
                pdfTester.LoadPdf(pdfResult);
                pdfTester.PdfIsValid.Should().Be.True();
                pdfTester.PdfContains(content).Should().Be.True();
            }
        }
Example #8
0
        public void Can_print_pdf_from_page_with_content_from_ajax_request()
        {
            var testLink = selenium.FindElement(By.LinkText("Ajax Test"));
            var pdfHref  = testLink.GetAttribute("href");
            var content  = "Hi there, this is content from a Ajax call.";

            using (var wc = new WebClient())
            {
                var pdfResult = wc.DownloadData(new Uri(pdfHref));
                var pdfTester = new PdfTester();
                pdfTester.LoadPdf(pdfResult);
                pdfTester.PdfIsValid.Should().Be.True();
                pdfTester.PdfContains(content).Should().Be.True();
            }
        }
Example #9
0
        public void Can_print_the_pdf_from_a_partial_view_with_a_model()
        {
            var testLink = selenium.FindElement(By.LinkText("Test PartialViewAsPdf with a model"));
            var pdfHref  = testLink.GetAttribute("href");
            var content  = "This is a test with a partial view";

            using (var wc = new WebClient())
            {
                var pdfResult = wc.DownloadData(new Uri(pdfHref));
                var pdfTester = new PdfTester();
                pdfTester.LoadPdf(pdfResult);
                pdfTester.PdfIsValid.Should().Be.True();
                pdfTester.PdfContains(content).Should().Be.True();
            }
        }
Example #10
0
 public void Can_build_the_pdf_binary()
 {
     var localPath = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory);
     var solutionDir = localPath.Parent.Parent.FullName;
     var wkhtmltopdfPath = Path.Combine(solutionDir, "Rotativa", "Rotativa");
     var actionResult = new UrlAsPdf("https://github.com/webgio/Rotativa")
         {
             WkhtmltopdfPath = wkhtmltopdfPath
         }; 
     var builder = new TestControllerBuilder();
     var controller = new HomeController();
     builder.InitializeController(controller);
     var pdfBinary = actionResult.BuildPdf(controller.ControllerContext);
     var pdfTester = new PdfTester();
     pdfTester.LoadPdf(pdfBinary);
     pdfTester.PdfIsValid.Should().Be.True();
     pdfTester.PdfContains("Rotativa").Should().Be.True();
 }
Example #11
0
 public void Can_print_pdf_from_page_with_external_css_file()
 {
     var testLink = selenium.FindElement(By.LinkText("External CSS Test"));
     var pdfHref = testLink.GetAttribute("href");
     var content = "Hi guys, this content shows up thanks to css file.";
     using (var wc = new WebClient())
     {
         var pdfResult = wc.DownloadData(new Uri(pdfHref));
         var pdfTester = new PdfTester();
         pdfTester.LoadPdf(pdfResult);
         pdfTester.PdfIsValid.Should().Be.True();
         pdfTester.PdfContains(content).Should().Be.True();
     }
 }
Example #12
0
 public void Can_print_pdf_from_page_with_content_from_ajax_request()
 {
     var testLink = selenium.FindElement(By.LinkText("Ajax Test"));
     var pdfHref = testLink.GetAttribute("href");
     var content = "Hi there, this is content from a Ajax call.";
     using (var wc = new WebClient())
     {
         var pdfResult = wc.DownloadData(new Uri(pdfHref));
         var pdfTester = new PdfTester();
         pdfTester.LoadPdf(pdfResult);
         pdfTester.PdfIsValid.Should().Be.True();
         pdfTester.PdfContains(content).Should().Be.True();
     }
 }