0

I am trying to programatically click the "save" button and test that the windows Save Dialog box appears: I have everything but the assert statement I believe. I don't know how to assert that my custom SaveDialogBox appears to the user.

[test]
public void Method_WhenThePersonIsNotfound_ClickingTheButtonSavesLetterToWordDocument
{
     //arrange
     CreateNewPage(); //creates IE window enters fields and clicks submit on first page.
     //act
     this.InternetExplorerDriver.FindElementById("SaveForm").Click(); //Clicks my button that should produce a save dialog box.

     //assert
     //Assert statement to verify that when button was clicked the save dialog box to save the letter in word appears.
Robert
  • 4,306
  • 11
  • 45
  • 95
  • So it's a web integration test then? What you're talking about has very little to do with NUnit and a lot to do with which framework you're using: Selenium, WatIN, etc. – Tim Rogers Sep 04 '12 at 21:46
  • Okay, I can rephrase the question, sorry about that – Robert Sep 04 '12 at 21:50

2 Answers2

2

I don't believe you can: I can't interact with a popup dialog. My test stops in its tracks!. "Save File" is specifically mentioned as being unable to be interacted with by Selenium.

vinny
  • 1,810
  • 15
  • 21
  • Same discussion over here: http://stackoverflow.com/questions/866856/how-do-i-test-modal-dialogs-with-selenium, with a possible workaround. – vinny Sep 04 '12 at 22:05
0

Using exceptions for implementing logic is not a good practice, but maybe this fast solution could help:

try { 
      this.InternetExplorerDriver.SwitchTo().Alert().Accept();//Appears sometime
    } 
catch (NoAlertPresentException) 
    { 
      // this code will perform if no alert is shown
    }

Also you can see this answer

Community
  • 1
  • 1
Frigik
  • 449
  • 1
  • 3
  • 13
  • I think this may work but in my unit test I need to assert something. should I Assert.isFalse(this.InternetExplorerDriver.SwitchTo().Alert().Accept()); – Robert Sep 05 '12 at 12:07