【问题标题】:Using Selenium How Can I test that a Save Dialog Box was displayed on the screen?使用 Selenium 如何测试屏幕上是否显示了保存对话框?
【发布时间】:2012-09-05 14:14:00
【问题描述】:

我正在尝试以编程方式单击“保存”按钮并测试 Windows 保存对话框是否出现:除了我相信的断言语句之外,我拥有一切。我不知道如何断言我的自定义 SaveDialogBox 出现在用户面前。

[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.

【问题讨论】:

  • 那么这是一个网络集成测试吗?您所说的与 NUnit 关系不大,而与您使用的框架有很大关系:Selenium、WatIN 等。
  • 好的,我可以改写这个问题,抱歉

标签: c# selenium


【解决方案1】:

我不相信你可以:I can't interact with a popup dialog. My test stops in its tracks!。 “保存文件”被特别提到无法与 Selenium 交互。

【讨论】:

【解决方案2】:

使用异常来实现逻辑并不是一个好习惯,但也许这种快速的解决方案会有所帮助:

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

你也可以看到this的回答

【讨论】:

  • 我认为这可能有效,但在我的单元测试中我需要断言一些东西。我应该 Assert.isFalse(this.InternetExplorerDriver.SwitchTo().Alert().Accept());
猜你喜欢
  • 1970-01-01
  • 2016-08-25
  • 2011-01-09
  • 2010-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-10
相关资源
最近更新 更多