5

I am trying to write a unit test using csharp to check if file is downloaded on click of a button. How can I find out if a download/save dialog is opened after clicking export button?

[TestMethod]
public void ExportMyFile()
{
    Home.GoToFilesPage();
    CommonFiles.ViewFile(0);
    CommonFiles.ClickExport();

    //int result = CommonFiles.ClickExport();
    //Assert.AreEqual(1, result); ???
}

public static class CommonFiles
{
    private const string ExportButton = "exportBtn";      

    public static void ClickExport()
    {
        Driver.Click(ExportButton);
    }
}
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
Kurkula
  • 6,386
  • 27
  • 127
  • 202
  • do you know what the string.Format function is.., where is the `{0}` parameter.. ? what's the purpose of you using string.Format..also where in your current code are you even displaying the save dialog.. please show all relevant code.. – MethodMan Aug 21 '15 at 18:47
  • Sorry MethodMan, I realized that I used it to get specific index of button. I removed the code after looking at your question. I just updated the code. Thanks for pointing that out. – Kurkula Aug 21 '15 at 18:49
  • Try [this](http://stackoverflow.com/questions/16710003/findwindowex-on-child-dialog-window) answer. – Old Fox Aug 24 '15 at 19:30
  • The code as given in the OP doesn't even compile (no `Driver` class), so I don't see how I can help you figuring out how to test it. Check out http://sscce.org. – Mark Seemann Aug 24 '15 at 19:40
  • Related: http://stackoverflow.com/a/2956085/126014 – Mark Seemann Aug 24 '15 at 20:29
  • 1
    @MarkSeemann the OP code has some clues... He works against a browser and `Driver` is `Selenium`... However I agree with you, the OP need to improve his question. – Old Fox Aug 25 '15 at 09:04

2 Answers2

1

If you are using the default save dialog from windows, you can use MS Fakes to mock that. Your mocked object will be able to tell you if it was called.

Steve
  • 367
  • 3
  • 11
1

I think you want to know how to confirm a file is downloaded in selenium web drive unit test.

Check out this: Access to file download dialog in Firefox

Community
  • 1
  • 1
flyfrog
  • 752
  • 1
  • 6
  • 7