代码之家  ›  专栏  ›  技术社区  ›  anonymous

watin:打印对话框

  •  0
  • anonymous  · 技术社区  · 15 年前

    我有一个屏幕,加载时弹出一个使用javascript的打印对话框。

    我刚开始用watin测试我的应用程序。此屏幕是测试的最后一步。

    有时会在对话框出现之前关闭窗口,有时不会关闭窗口。我在测试拆卸中有ie.close(),但如果显示打印对话框,它仍然保持打开状态。

    我想避免的是有一个孤立的IE窗口。我要它一直关闭。

    我查找了DialogHandlers并编写了以下内容:

    var printDialogHandler = new PrintDialogHandler(PrintDialogHandler.ButtonsEnum.Cancel);
    ie.DialogWatcher.Add(printDialogHandler);
    

    把它放在按钮前点击链接到页面,但没有改变。

    我看到的示例中的代码可以执行如下操作:

    someDialogHandler.WaitUntilExists() // I might have this function name wrong...
    

    但PrintDialogHandler没有太多成员。

    最初我并没有试图测试这个对话框是否出现(只是页面加载并检查页面上的一些值),但我想等待并测试打印对话框是否存在会更为完整。

    3 回复  |  直到 13 年前
        1
  •  2
  •   Greg Bray    15 年前

    不完全确定您的情况,但加载时弹出窗口也显示打印对话框时出现问题。我们的主要问题是忘记创建一个新的IE实例并将其附加到弹出窗口。这是工作代码:

    btnCoverSheetPrint.Click(); //Clicking this button will open a new window and a print dialog
    IE iePopup = IE.AttachToIE(Find.ByUrl(new Regex(".+_CoverPage.aspx"))); //Match url ending in "_CoverPage.aspx"
    
    WatiN.Core.DialogHandlers.PrintDialogHandler pdhPopup = new WatiN.Core.DialogHandlers.PrintDialogHandler(WatiN.Core.DialogHandlers.PrintDialogHandler.ButtonsEnum.Cancel);
    using (new WatiN.Core.DialogHandlers.UseDialogOnce(iePopup.DialogWatcher, pdhPopup)) //This will use the DialogHandler once and then remove it from the DialogWatcher
    {
        //At this point the popup window will be open, and the print dialog will be canceled
        //Use the iePopup object to manage the new window in here.
    }
    
    iePopup.Close(); // Close the popup once we are done.
    
        2
  •  1
  •   Tim Cooper    13 年前

    这对我很有用:

    private void Print_N_Email(Browser ie)
    {
       //Print and handle dialog.
       ie.Div(Find.ById("ContentMenuLeft")).Link(Find.ByText(new Regex("Print.*"))).Click();//orig
       Browser ie2 = Browser.AttachTo(typeof(IE), Find.ByUrl(new Regex(".*Print.*")));
       System.Threading.Thread.Sleep(1000);
    
       PrintDialogHandler pdh = new PrintDialogHandler(PrintDialogHandler.ButtonsEnum.Cancel);
       new UseDialogOnce(ie2.DialogWatcher, pdh);
       ie2.Close(); 
    }
    
        3
  •  0
  •   Shady M. Najib    14 年前

    您仍可能需要检查浏览器 AutoClose 财产 ie.AutoClose