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
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