Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Mindfusion and Coded UI (Read 2469 times)
mbroadbe42
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Jul 15th, 2014
Mindfusion and Coded UI
Jul 15th, 2014 at 6:11pm
Print Post  
Hi,

We've recently built a WPF application with MindFusion and were interested in having MS CodedUI interact with the workflow elements for simple UI testing.

When we ran the Coded UI recorder it wasn't able to 'see' the objects within the MindFusion view. Is there a way to capture these elements to allow Coded UI to interact with the diagram?

Currently I'm doing it in a cumbersome fashion by using the x/y offset from the top left corner of the window to select the correct elements.

Hoping there is a better way! Thanks!!
Michael
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Mindfusion and Coded UI
Reply #1 - Jul 15th, 2014 at 6:40pm
Print Post  
Hi,

It seems Coded UI relies on the Accessibility API to run tests, so you might try deriving from Diagram and implementing the required methods as shown here:
http://msdn.microsoft.com/en-us/library/hh552522.aspx

We'll try to add built-in support for next release.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
mbroadbe42
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Jul 15th, 2014
Re: Mindfusion and Coded UI
Reply #2 - Jul 15th, 2014 at 10:43pm
Print Post  
Hi Stoyan,

I can try and see what I can come up with, unfortunately I'm not a traditional developer so I'm not sure if this is within my wheelhouse to sort out. If you could provide support for this in future editions or provide a bit more help on how to use that link effectively that would be appreciated.

Thanks,
Michael
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Mindfusion and Coded UI
Reply #3 - Jul 16th, 2014 at 8:44am
Print Post  
Hi Michael,

The link above was for Windows Forms, here's one showing how to implement it for WPF:
http://msdn.microsoft.com/en-us/library/cc165614.aspx

The code below should let you record and replay node selection events, you'll need your developers to add it to the application along with a reference to the .NET's UIAutomationTypes assembly:

Code
Select All
public class MyDiagram : Diagram
{
	protected override AutomationPeer OnCreateAutomationPeer()
	{
		return new MyDiagramAutomationPeer(this);
	}

	class MyDiagramAutomationPeer :
		FrameworkElementAutomationPeer,
		ISelectionProvider
	{
		public MyDiagramAutomationPeer(FrameworkElement owner) :
			base(owner)
		{
			var diagram = (MyDiagram)owner;
			nodePeers = new Dictionary<DiagramNode, DiagramNodeAutomationPeer>();

			diagram.NodeCreated +=
				(s, e) => RaiseAutomationEvent(AutomationEvents.StructureChanged);
			diagram.NodeDeleted +=
				(s, e) => RaiseAutomationEvent(AutomationEvents.StructureChanged);
			diagram.NodeSelected +=
				(s, e) => RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection);
			diagram.NodeDeselected +=
				(s, e) => RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection);
		}

		protected override string GetClassNameCore()
		{
			return "MyDiagram";
		}

		protected override AutomationControlType GetAutomationControlTypeCore()
		{
			return AutomationControlType.List;
		}

		protected override List<AutomationPeer> GetChildrenCore()
		{
			var children = new List<AutomationPeer>();
			foreach (var node in Diagram.Nodes)
				children.Add(PeerForNode(node));
			return children;
		}

		DiagramNodeAutomationPeer PeerForNode(DiagramNode node)
		{
			if (nodePeers.ContainsKey(node))
				return nodePeers[node];

			var nodePeer = new DiagramNodeAutomationPeer(node, this);
			nodePeers[node] = nodePeer;
			return nodePeer;
		}

		public override object GetPattern(PatternInterface patternInterface)
		{
			if (patternInterface == PatternInterface.Selection)
				return this;
			return base.GetPattern(patternInterface);
		}

		#region ISelectionProvider Members

		public IRawElementProviderSimple[] GetSelection()
		{
			var selectionPeers = new List<IRawElementProviderSimple>();
			foreach (var node in Diagram.Selection.Nodes)
				selectionPeers.Add(ProviderFromPeer(PeerForNode(node)));
			return selectionPeers.ToArray();
		}

		public bool CanSelectMultiple
		{
			get { return true; }
		}

		public bool IsSelectionRequired
		{
			get { return false; }
		}

		#endregion

		MyDiagram Diagram
		{
			get { return (MyDiagram)Owner; }
		}

		Dictionary<DiagramNode, DiagramNodeAutomationPeer> nodePeers;
	}

	class DiagramNodeAutomationPeer :
		FrameworkElementAutomationPeer,
		ISelectionItemProvider
	{
		public DiagramNodeAutomationPeer(FrameworkElement owner, MyDiagramAutomationPeer parent) :
			base(owner)
		{
			this.parent = parent;
		}

		MyDiagramAutomationPeer parent;

		protected override string GetClassNameCore()
		{
			return "DiagramNode";
		}

		protected override AutomationControlType GetAutomationControlTypeCore()
		{
			return AutomationControlType.ListItem;
		}

		public override object GetPattern(PatternInterface patternInterface)
		{
			if (patternInterface == PatternInterface.SelectionItem)
				return this;

			return base.GetPattern(patternInterface);
		}

		#region ISelectionItemProvider Members

		public void AddToSelection()
		{
			Node.Selected = true;
		}

		public bool IsSelected
		{
			get { return Node.Selected; }
		}

		public void RemoveFromSelection()
		{
			Node.Selected = false;
		}

		public void Select()
		{
			Node.Selected = true;
		}

		public IRawElementProviderSimple SelectionContainer
		{
			get { return ProviderFromPeer(parent); }
		}

		#endregion

		DiagramNode Node
		{
			get { return (DiagramNode)Owner; }
		}
	}
} 



You could extend it further by implementing ITextProvider in DiagramNodeAutomationPeer for example, which should let you test the nodes' Text property.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint