【问题标题】:Highlighting a particular control while capturing screenshot of a dialog in web page in c#在c#中捕获网页中对话框的屏幕截图时突出显示特定控件
【发布时间】:2014-11-28 00:33:48
【问题描述】:

我需要捕获打开的对话框的屏幕截图,其中突出显示了特定的 html 控件(其静态 id 已给出)。目前我实现了以下方式的代码:

public void Snapshot()
{
    Image currentImage = null;
    currentImage = GetOpenedDialogFrame().CaptureImage();
}

public UITestControl GetOpenedDialogFrame()
{
    var dialogsFrames = new HtmlDiv(this.BrowserMainWindow.UiMobiControlDocument);
    dialogsFrames.SearchProperties.Add(new PropertyExpression(HtmlControl.PropertyNames.Class, "mcw-dialog", PropertyExpressionOperator.Contains));
    var dialogs = dialogsFrames.FindMatchingControls();
    if (dialogs.Count == 0)
    {
       return null;
    }

    return dialogs[dialogs.Count - 1];
}

现在我必须编写代码以在截屏时突出显示特定的 html 控件。 Microsoft.VisualStudio.TestTools.UITesting.dllDrawHighlight() 方法不带任何参数,所以如何在屏幕截图中突出显示特定的 html 控件。

【问题讨论】:

    标签: c# coded-ui-tests


    【解决方案1】:

    DrawHighlight() 是一个 UI 控件的方法。它可以用于这种风格:

    public void Snapshot()
    {
        Image currentImage = null;
        var control = GetOpenedDialogFrame();
        // TODO: protect the code below against control==null.
        control.DrawHighlight();
        currentImage = control.CaptureImage();
    }
    

    虽然这回答了您关于 DrawHighlight 的问题,但我不确定它是否能实现您想要的。请参阅this question the Microsoft forums,他们正在尝试进行类似的屏幕截图。

    【讨论】:

      【解决方案2】:

      为什么不简单地使用播放设置:

      Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
      

      这将生成 html 日志文件,其中包含您的 codedui 测试抛出的所有屏幕截图。

      【讨论】:

        【解决方案3】:

        搜索匹配的控件后,您可以尝试突出显示它们中的每一个。 类似:

              foreach( var control in controls)      
              {
               control.drawhighlight();
              } 
        

        这样您就可以通过播放找到哪些控件(更准确地说是 qtagent)。此外,这将帮助您决定要引用哪个实例。 (运行并等待查看突出显示的控件,选择您需要的控件并将其硬编码为测试的一部分)。

        所以在测试运行之后你会得到类似的结果:

             var dialogs = dialogsFrames.FindMatchingControls();
             dialogs[desiredLocation].drawhighlight();
        

        希望这会有所帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-03-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-29
          • 1970-01-01
          • 2015-05-16
          • 1970-01-01
          相关资源
          最近更新 更多