2011-02-16 6 views
0

내 배경 :
WatiN을 처음 사용했지만 새로운 웹 UI 테스트를 작성하는 데 익숙하지 않습니다. 새로운 일에서 우리는 WatiN을 웹 UI 테스트에 사용하려고 노력하고 있습니다 (CUIT 실패로 인해).WatiN이 CuteWebUI Uploader 팝업 대화 상자를 처리 할 수 ​​있습니까?

저는 ArtOfTest.WebAii를 사용하여 포함 된 요소의 매직 번호 오프셋을 사용하여 Win32 마우스 클릭을 사용하여이 문제를 해결했지만 WatiN에서이를 수행하는 방법에 대한 문서를 찾지 못하는 것 같습니다 나는 나 자신을 알아낼 수 없습니다 :

내 문제 : \
이 대화 상자가 나타납니다 나는 WatiN 그것을 클릭 할 수있는 방법을 찾을 수 없습니다.

<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); 
    } 
} 

일체의 도움이 아주 많이 이해할 수있을 것이다

enter image description here

대화 상자에는 다음과 같은 마크 업을 가지고있다.

감사합니다.

답변

0

귀하의 컨트롤은 WatiN으로 자동화 할 수없는 실버 라이트 구성 요소입니다. 다행히도 WatiN과 White를 결합하여 작업을 완료 할 수 있습니다.

다음 코드는 Leo Bartnik이 제작하여 게시하므로 모든 크레딧이 제공됩니다! 블로그 게시물 here을 살펴보십시오. 의견의 다음 코드는 다음과 같습니다.

그는 다음 버전을 사용했습니다. { // 이동합니다 WatiN와 웹 페이지에

  • 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() 문자열 url = "http : // localhost [포트 번호] /WatinWhiteTestLandingPage.aspx"; WatiN.Core.IE watin = new WatNN.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(); 
    

    }

이 BTW 모른다. ...

+0

감사합니다! 다른 프레임 워크를 내 코드베이스에 도입하는 것을 멀리하고 싶습니다. 특히 0.2 버전에 있습니다. WatiN이 지정된 픽셀 포인트에서 마우스 클릭을 시뮬레이션 할 수있는 방법이 있습니까? – GraehamF

+0

아니요, WatiN은 지정된 픽셀 지점에서 마우스 클릭을 수행 할 수 없습니다. –

0

Microsoft의 코드화 된 UI 테스트를 사용하여 Silverlight 대화 상자를 클릭하십시오. 그러나 CUIT는 WatiN보다 열등하므로 WatiN에서 테스트를 실행하고 CUIT를 하나, 클릭하십시오.

또한 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! ============================ 
     } 
관련 문제