Can WatiN可以处理CuteWebUI Uploader弹出对话框吗?

问题描述:

我的背景:
我是WatiN的新手,但对编写自动化Web UI测试并不陌生。在我的新工作中,我们尝试使用WatiN进行Web UI测试(由于少数CUIT失败)。Can WatiN可以处理CuteWebUI Uploader弹出对话框吗?

我在过去使用ArtOfTest.WebAii解决了这个问题,通过使用Win32鼠标单击包含元素的幻数偏移量,但我似乎无法找到关于如何在WatiN中执行此操作的文档我不能找出自己:\

我的问题:出现
此对话框,我似乎无法找到一种方法为华廷点击它。

enter image description here

对话框包含以下标记:

<OBJECT style="FILTER: alpha(opacity=1); WIDTH: 329px; HEIGHT: 100px; mozOpacity: 0.01; opacity: 0.01; mozopacity: 0.01" data="data:application/x-oleobject;base64, <a bunch of data>" width=329 height=100 type=application/x-silverlight-2></OBJECT> 
    <param name="source" value="/CuteWebUI_Uploader_Resource.axd?type=file&file=silverlight.xap&_ver=634334311861475176"/> 
    <param name="windowless" value="true" object="" <=""/> 

我的测试代码:

[TestMethod] 
public void SomeTest() 
{ 
    Settings.MakeNewIeInstanceVisible = true; 
    Settings.AutoStartDialogWatcher = true; 
    Settings.AutoMoveMousePointerToTopLeft = false; 
    using (IE ie2 = new IE()) 
    { 
     ie2.GoTo(URL); 
     ie2.Link(SomeButtonID).Click(); 
     ie2.Image(AnotherButtonID).FireEvent("onclick"); 


     // some debugging code wrapped around the next user action 
     // which is clicking on the attach file button 
     var helper = new DialogHandlerHelper(); 
     using (new UseDialogOnce(ie2.DialogWatcher, helper)) 
     { 
      Thread.Sleep(1 * 1000); // wait for attach button to be "ready" 

      // Click button that triggers the dialog that states: 
      //  "file browsing dialog has been blocked" 
      //  "please click here and try again" 
      // 
      ie2.Button(FileAttachButtonID).FireEvent("onclick"); 
     } 
     foreach(string dialogHandler in helper.CandidateDialogHandlers) 
     { 
      // nothing prints out here :(
      Console.Out.WriteLine(dialogHandler); 
     } 


     // debug print out all elements with tagname = object 
     foreach (Element objectElement in ie2.ElementsWithTag("object")) 
     { 
      StringBuilder elementInfo = new StringBuilder(); 
      elementInfo.AppendLine("--------------------------------------------"); 
      elementInfo.AppendLine("element.tagname = " + objectElement.TagName); 
      elementInfo.AppendLine("element.style = " + objectElement.Style); 
      elementInfo.AppendLine("element.type = " + objectElement.GetAttributeValue("type")); 
      elementInfo.AppendLine("element.data = " + objectElement.GetAttributeValue("data")); 
      elementInfo.AppendLine("--------------------------------------------"); 
      Console.Out.WriteLine(elementInfo.ToString()); 

      // none of these clicks make the dialog go away 
      objectElement.ClickNoWait(); 
      objectElement.Click(); 
      objectElement.DoubleClick(); 
      objectElement.MouseEnter(); 
      objectElement.MouseDown(); 
      Thread.Sleep(500); 
      objectElement.MouseUp(); 
     } 

     // wait to see if dialog disappears after click 
     Thread.Sleep(300 * 1000); 
    } 
} 

任何及所有的帮助将是非常赞赏。

谢谢!

您的控件是Silverlight组件,它不能用WatiN自动执行。幸运的是,您可以将WatiN和White结合起来完成工作。

以下代码由Leo Bartnik创建并发布,所以所有学分都发给他!看看他的博客文章here。以下代码在评论中:

他使用了以下版本。

  • watin-2.0.50.1179.zip从2011-02-08 http://sourceforge.net/projects/watin/files/WatiN%202.x/2.0%20Final/

  • 白0.20二进制http://white.codeplex.com/releases/view/29694

    公共无效WatiN_and_White_join_forces(){ 到 与华廷网页//导航 string url =“http:// localhost [port#] /WatinWhiteTestLandingPage.aspx”; WatiN.Core.IE watin = new WatiN.Core.IE(url); watin.Link(Find.ByText(“点击这里))点击();

    // Attach the IE instance used by WatiN to White 
    InternetExplorerFactory.Plugin(); 
    string title = "[browser title here]"; // will be something like "WatinWhiteHybrid - Internet Explorer provided by ..." 
    var ie = (InternetExplorerWindow)Application.Attach(watin.ProcessID).GetWindow(title); 
    White.WebBrowser.Silverlight.SilverlightDocument sl = ie.SilverlightDocument; 
    
    // Click the button in the silverlight control using White 
    sl.Get(SearchCriteria.ByAutomationId("ClickMeId")).Click(); 
    

    }

顺便说一句不知道为什么这段代码的格式化是那么遥远。 ...

+0

感谢您的答复,吉荣!我想远离将另一个框架引入我的代码库 - 特别是在0.2版本中。 WatiN有什么方法可以在指定的像素点模拟鼠标点击? – GraehamF 2011-02-17 16:40:07

所以这是我的黑客解决方案: 使用微软的Coded UI Test来点击Silverlight对话框,但是CUIT不如WatiN,所以我在WatiN运行我的测试并加载了一个神奇的,点击。

此外,我无法使用CUIT轻松找到Silverlight对象,所以我找到它后面的窗口,找到窗口的中心像素并强制使用Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click()。是的,在黑客攻击中,我是一个非常糟糕的人,但我耗尽了时间,只是需要一些工作。

如果有人有更优雅的解决方案,请分享。

我的解决办法代码:

FileUploadDialogHandler helper = new FileUploadDialogHandler(attachmentPath); 
      using (new UseDialogOnce(ie.DialogWatcher, helper)) 
      { 
       Thread.Sleep(1 * 1000); // wait for attach button to be "ready" 
       ie.Button(browseButtonID).FireEvent("onclick"); 


       // When automating a file upload, there is a Silverlight popup in IE that forces an extra click 
       // before opening the file open dialog. WatiN does not support Silverlight automation 
       // and the popup element was acting quirky in Microsoft's Coded UI Test, so we find the 
       // dialog box UNDERNEATH the Silverlight popup and force one, lovely, mouse click. 
       //===== Entering Coded UI Test land, beware! ===================================== 

       // initialize Coded UI Test 
       Playback.Initialize(); 
       BrowserWindow.CurrentBrowser = "IE"; 
       Process watinBrowserProcess = Process.GetProcessById(ie.ProcessID); 
       BrowserWindow cuitBrowser = BrowserWindow.FromProcess(watinBrowserProcess); // attach Coded UI Test to the IE browser WatiN initialized 

       // get the window underneath the Silverlight popup 
       UITestControl modalUnderSilverlightPopup = new UITestControl(cuitBrowser.CurrentDocumentWindow); 
       modalUnderSilverlightPopup.SearchProperties.Add("id", windowElementUnderPopupID); 

       // get the X and Y pixel center of the window 
       int centerX = modalUnderSilverlightPopup.BoundingRectangle.X + modalUnderSilverlightPopup.BoundingRectangle.Width/2; 
       int centerY = modalUnderSilverlightPopup.BoundingRectangle.Y + modalUnderSilverlightPopup.BoundingRectangle.Height/2; 

       // Click! 
       Mouse.Click(new Point(centerX, centerY)); 

       // Shutdown Coded UI Test 
       Playback.Cleanup(); 
       //===== End Coded UI Test land, you survived! yay! ============================ 
     }