Quelqu'un peut-il fournir et exemple de télécharger un fichier PDF en utilisant Watin? J'ai essayé le SaveAsDialogHandler mais je n'ai pas pu le comprendre. Peut-être un MemoryStream pourrait-il être utilisé?Watin et PDF
Merci,
--jb
Quelqu'un peut-il fournir et exemple de télécharger un fichier PDF en utilisant Watin? J'ai essayé le SaveAsDialogHandler mais je n'ai pas pu le comprendre. Peut-être un MemoryStream pourrait-il être utilisé?Watin et PDF
Merci,
--jb
Ce code fera l'affaire. La classe UsedialogOnce peut être trouvée dans le code WatiN.UnitTests et fera partie de la version 1.3 de WatiN (qui sera probablement publiée le 14 octobre).
FileDownloadHandler fichierTéléchargerHandler = nouveau FileDownloadHandler (fichier.FullName); en utilisant (new UseDialogOnce (ie.DialogWatcher, fileDownloadHandler)) { ie.Button ("exportPdfButtonId"). ClickNoWait();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(30);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
}
HTH, Jeroen van Menen développeur principal Watin
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(file.FullName);
using (new UseDialogOnce(ie.DialogWatcher, fileDownloadHandler))
{
ie.Button("exportPdfButtonId").ClickNoWait();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(30);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
}
Je viens de rencontrer dans ce même problème, sauf que j'utilise Foxit au lieu d'Acrobat. J'ai dit à Foxit de ne pas courir dans le navigateur, alors ce code a commencé à fonctionner correctement. Voici un test unitaire complet qui devrait faire l'affaire:
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));
Jetez un oeil à ce poste:
How to check if PDF was successfully opened in the browser using WatiN?