无法在基于Popup(.NET)的应用程序上使用CodedUI执行任何操作

时间:2018-04-16 06:01:21

标签: c# coded-ui-tests

启动浏览器后,我无法在基于Popup的应用程序(.NET)上单击(或执行任何操作)。

请找到录制的代码,点击"确定" Popup的按钮,我从下面的通用代码中获取元素属性:

UIIPVPNRouterCreationWWindow.UIItemWindow11.UIIPVPNRouterCreationWClient.UIItemWindow.UIIPVPNRouterCreationDocument.UIOKButton;

**UIIPVPNRouterCreationWWindow:**

[GeneratedCode("Coded UITest Builder", "12.0.31101.0")]
    public class UIIPVPNRouterCreationWWindow : BrowserWindow
    {

        public UIIPVPNRouterCreationWWindow()
        {
            #region Search Criteria
            this.SearchProperties[UITestControl.PropertyNames.Name] = "IPVPN Router Creation";
            this.SearchProperties[UITestControl.PropertyNames.ClassName] = "Internet Explorer_TridentDlgFrame";
            this.WindowTitles.Add("IPVPN Router Creation");
            #endregion
        }

        public void LaunchUrl(System.Uri url)
        {
            this.CopyFrom(BrowserWindow.Launch(url));
        }

**UIItemWindow11:**   
[GeneratedCode("Coded UITest Builder", "12.0.31101.0")]
    public class UIItemWindow11 : WinWindow
    {

        public UIItemWindow11(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.ClassName] = "ThunderRT6UserControlDC";
            this.WindowTitles.Add("IPVPN Router Creation");
            #endregion
        }
**UIIPVPNRouterCreationWClient:**  
 [GeneratedCode("Coded UITest Builder", "12.0.31101.0")]
    public class UIIPVPNRouterCreationWClient : WinClient
    {

        public UIIPVPNRouterCreationWClient(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.WindowTitles.Add("IPVPN Router Creation");
            #endregion
        }
**UIItemWindow:**
[GeneratedCode("Coded UITest Builder", "12.0.31101.0")]
    public class UIItemWindow5 : WinWindow
    {

        public UIItemWindow5(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[WinWindow.PropertyNames.ClassName] = "ThunderRT6ComboBox";
            this.WindowTitles.Add("IPVPN Router Creation");
            #endregion
        }


**UIIPVPNRouterCreationDocument:**

[GeneratedCode("Coded UITest Builder", "12.0.31101.0")]
    public class UIIPVPNRouterCreationDocument : HtmlDocument
    {

        public UIIPVPNRouterCreationDocument(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
            this.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
            this.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "False";
            this.FilterProperties[HtmlDocument.PropertyNames.Title] = "IPVPN Router Creation";
            this.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/Ordering/ROUTER/newOrder.aspx";
            this.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://rcorp-fil-02dev-fileadeete.sso-dev.infra.ftgroup/Ordering/ROUTER/newOrder." +
                "aspx?EditMode=Create New Router&OrderType=Addition&SitaType=IPNET&OrderStatus=Ed" +
                "it";
            this.WindowTitles.Add("IPVPN Router Creation");
            #endregion
        }
**UIOKButton:**
public HtmlInputButton UIOKButton
        {
            get
            {
                if ((this.mUIOKButton == null))
                {
                    this.mUIOKButton = new HtmlInputButton(this);
                    #region Search Criteria
                    this.mUIOKButton.SearchProperties[HtmlButton.PropertyNames.Id] = "btnOK";
                    this.mUIOKButton.SearchProperties[HtmlButton.PropertyNames.Name] = "btnOK";
                    this.mUIOKButton.FilterProperties[HtmlButton.PropertyNames.DisplayText] = "OK";
                    this.mUIOKButton.FilterProperties[HtmlButton.PropertyNames.Type] = "button";
                    this.mUIOKButton.FilterProperties[HtmlButton.PropertyNames.Title] = null;
                    this.mUIOKButton.FilterProperties[HtmlButton.PropertyNames.Class] = "button center";
                    this.mUIOKButton.FilterProperties[HtmlButton.PropertyNames.ControlDefinition] = "id=btnOK class=\"button center\" type=butt";
                    this.mUIOKButton.FilterProperties[HtmlButton.PropertyNames.TagInstance] = "5";
                    this.mUIOKButton.WindowTitles.Add("IPVPN Router Creation");
                    #endregion
                }
                return this.mUIOKButton;
            }
        }

我试过的代码(通用代码):

namespace ProjectName
{
   public class CustomCaller
    {

        public static void customcallerMethod() {

            BrowserWindow broWin = new BrowserWindow();
            broWin.SearchProperties[UITestControl.PropertyNames.Name] = "Fileade";


            HtmlCustom htCus = new HtmlCustom(broWin);
            htCus.SearchProperties["TagName"] = "FRAMESET";

            HtmlFrame htFrame = new HtmlFrame(htCus);
            htFrame.SearchProperties[HtmlFrame.PropertyNames.Name] = "nav";

            HtmlDocument htDoc = new HtmlDocument(htFrame);
            htDoc.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/Ordering/nav.aspx";
            Playback.Wait(2000);

            HtmlDiv htDev = new HtmlDiv(htDoc);
            htDev.SearchProperties[HtmlDiv.PropertyNames.Id] = "Device";
            Mouse.Click(htDev);
            Playback.Wait(2000);
            HtmlDiv htDev1 = new HtmlDiv(htDev);
            htDev1.SearchProperties[HtmlDiv.PropertyNames.Id] = "DeviceSub";

            Playback.Wait(2000);
            HtmlDiv htDev2 = new HtmlDiv(htDoc);
            htDev2.FilterProperties[HtmlDiv.PropertyNames.InnerText] = "New IP VPN";
            Mouse.Click(htDev2);
            Playback.Wait(5000);



           // UITestControl broWin1 = new UITestControl();
           // broWin1.TechnologyName = "MSAA";
            //broWin1.SearchProperties[UITestControl.PropertyNames.Name] = "IPVPN Router Creation";

// Problematic Code starts here for action to be performed on IE based popup Application---- Which does not allow me click Ok button on popup:
            BrowserWindow broWin1 = new BrowserWindow();
            broWin1.TechnologyName = "MSAA";
            broWin1.SearchProperties[UITestControl.PropertyNames.Name] = "IPVPN Router Creation";
            broWin1.SearchProperties[UITestControl.PropertyNames.ClassName] = "Internet Explorer_TridentDlgFrame";

            WinWindow winWin = new WinWindow(broWin1);
            winWin.SearchProperties[WinWindow.PropertyNames.ClassName] = "ThunderRT6UserControlDC";
            //winWin.SearchProperties[WinWindow.PropertyNames.ControlId] = "1001";
            Playback.Wait(3000);

            //winWin.SearchProperties[WinWindow.PropertyNames.ClassName] = "ThunderRT6UserControlDC";
            // Mouse.Click(winWin);

           // WinClient wClient = new WinClient(winWin);
          // wClient.WindowTitles.Add("IPVPN Router Creation");

            //UIIPVPNRouterCreationWClient.UIItemWindow
            WinWindow winWin1 = new WinWindow(winWin);
             winWin1.SearchProperties[WinWindow.PropertyNames.ClassName] = "ThunderRT6ComboBox";

            //UIIPVPNRouterCreationWClient.UIItemWindow.UIIPVPNRouterCreationDocument
             HtmlDocument htDoc3 = new HtmlDocument(winWin1);
           htDoc3.FilterProperties[HtmlDocument.PropertyNames.Title] = "IPVPN Router Creation";
            //htDoc3.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/Ordering/ROUTER/newOrder.aspx";

            //UIIPVPNRouterCreationWClient.UIItemWindow.UIIPVPNRouterCreationDocument.UIOKButton
           HtmlInputButton htCon = new HtmlInputButton(htDoc3);
            htCon.TechnologyName = "Web";
            htCon.SearchProperties[HtmlButton.PropertyNames.Name] = "btnOK";
            Playback.Wait(2000);
            Mouse.Click(htCon);
            Playback.Wait(3000);

发生异常:

Test Name:  CodedUITestMethod1
Test FullName:  ProjectName.CodedUITest1.CodedUITestMethod1
Test Source:    c:\CODEUI\WorkProject\FileadePOC\FileadePOC\CodedUITest1.cs : line 38
Test Outcome:   Failed
Test Duration:  0:00:49.625137

结果讯息:

测试方法ProjectName.CodedUITest1.CodedUITestMethod1抛出异常: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException:播放无法找到具有给定搜索属性的控件。额外细节: TechnologyName:' Web' ControlType:'文档' TagName:' BODY'  ---> System.Runtime.InteropServices.COMException:错误HRESULT已从调用COM组件返回E_FAIL。 结果StackTrace:
在Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants(String bstrQueryId,Object& pvarResKeys,Int32 cResKeys,Int32 nMaxDepth)

请帮忙..在此先感谢!!!

0 个答案:

没有答案