2008-10-13 13 views
7

¿Alguien puede proporcionar y ejemplo de descargar un archivo PDF usando Watin? Probé el SaveAsDialogHandler pero no pude resolverlo. Quizás un MemoryStream podría ser utilizado?Watin y PDF

Gracias,

--jb

Respuesta

2

Este código hará el truco. La clase UsedialogOnce se puede encontrar en el código WatiN.UnitTests y será parte de la versión WatiN 1.3 (que probablemente se lanzará a partir del 14 de octubre).

FileDownloadHandler fileDownloadHandler = new FileDownloadHandler (file.FullName); usando (new UseDialogOnce (es decir, .DialogWatcher, fileDownloadHandler)) { ie.Button ("exportPdfButtonId"). ClickNoWait();

fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(30); 
fileDownloadHandler.WaitUntilDownloadCompleted(200); 

}

HTH, Jeroen van Menen Desarrollador principal WatiN

4
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(file.FullName); 
using (new UseDialogOnce(ie.DialogWatcher, fileDownloadHandler)) 
{ 
    ie.Button("exportPdfButtonId").ClickNoWait(); 

    fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(30); 
    fileDownloadHandler.WaitUntilDownloadCompleted(200); 
} 
1

Me acabo de encontrar con esta misma emisión, a menos que utilizo Foxit lugar de Acrobat. Le dije a Foxit que no se ejecutara en el navegador, entonces este código comenzó a funcionar bien. Aquí está una prueba de unidad completa que debe hacer el truco:

 string file = Path.Combine(Directory.GetCurrentDirectory(), "test.pdf"); 

     using (IE ie = new IE()) 
     { 
      FileDownloadHandler handler = new FileDownloadHandler(file); 

      using (new UseDialogOnce(ie.DialogWatcher, handler)) 
      { 
       try 
       { 
        ie.GoToNoWait("http://www.tug.org/texshowcase/cheat.pdf"); 

        //WatiN seems to hang when IE loads a PDF, so let it timeout... 
        ie.WaitForComplete(5); 
       } 
       catch (Exception) 
       { 
        //Ok. 
       } 

       handler.WaitUntilFileDownloadDialogIsHandled(30); 
       handler.WaitUntilDownloadCompleted(30); 
      } 

     } 

     Assert.That(File.Exists(file));