Coded UI Testing Without UIMAP

前端 未结 1 1672
一整个雨季
一整个雨季 2021-01-07 14:11

I have working in coded ui project. I have trying to coded ui test without UIMAP.In this requirement using following code in c#.

[TestMethod]
public void Cod         


        
相关标签:
1条回答
  • 2021-01-07 14:48

    Coded UI solution structure

    CodedUIExtension File

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.VisualStudio.TestTools.UITesting;
    
    namespace CodedUITest
    {
    public static class CodedUIExtension
    {
    
        public static T SearchFor<T>(this UITestControl _this, dynamic searchProperties, dynamic filterProperties = null) where T : UITestControl, new()
        {
            T ctrl = new T();
            ctrl.Container = _this;
    
            IEnumerable<string> propNames = ((object)searchProperties).GetPropertiesForObject();
            foreach (var item in propNames)
            {
                ctrl.SearchProperties.Add(item, ((object)searchProperties).GetPropertyValue(item).ToString());
            }
            object s = filterProperties;
    
            if (s != null)
            {
                propNames = ((object)filterProperties).GetPropertiesForObject();
                foreach (var item in propNames)
                {
                    ctrl.SearchProperties.Add(item, ((object)filterProperties).GetPropertyValue(item).ToString());
                }
            }
    
            return ctrl as T;
    
    
        }
    
        private static IEnumerable<string> GetPropertiesForObject(this object _this)
        {
            return (from x in _this.GetType().GetProperties() select x.Name).ToList();
        }
    
        private static object GetPropertyValue(this object _this, string propName)
        {
            var prop = (from x in _this.GetType().GetProperties() where x.Name == propName select x).FirstOrDefault();
            return prop.GetValue(_this);
        }
    
    
    
    }
    
    }
    

    Testmethod

    [TestMethod]
        public void CodedUITestMethod1()
        {
    
            try
            {
                //ProcessStartInfo processStartInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CodedUITestBuilder.exe ");
                //processStartInfo.Arguments = @"/standalone";
                //ApplicationUnderTest app = ApplicationUnderTest.Launch(processStartInfo);
    
                ApplicationUnderTest app = ApplicationUnderTest.Launch("C:\\Windows\\System32\\calc.exe", "%windir%\\System32\\calc.exe");
                WinWindow calWindow = new WinWindow();
                calWindow = app.SearchFor<WinWindow>(
                    /* pass search properties */
     new { Name = "Calculator" },
                    /*pass filter properties if needed */
      new { ClassName = "CalcFrame" });
    
                WinButton buttonAdd = calWindow.Container.SearchFor<WinButton>(new { Name = "Add" });
                WinButton buttonEqual = calWindow.Container.SearchFor<WinButton>(new { Name = "Equals" });
                WinButton button1 = calWindow.Container.SearchFor<WinButton>(new { Name = "1" });
                WinButton button2 = calWindow.Container.SearchFor<WinButton>(new { Name = "2" });
                WinButton button3 = calWindow.Container.SearchFor<WinButton>(new { Name = "3" });
                WinText txtResult = calWindow.Container.SearchFor<WinText>(new { Name = "Result" });
    
                //do all the operations
                Mouse.Click(button2);
                Mouse.Click(buttonAdd);
                Mouse.Click(button3);
                Mouse.Click(buttonEqual);
    
                //evaluate the results
                Assert.AreEqual("5", txtResult.DisplayText);
    
                //close the application
                app.Close();
    
            }
            catch (Exception e)
            {
    
            }
        }
    

    I hope this is working sample for code ui without uimap

    0 讨论(0)
提交回复
热议问题