Hi everyone,
I am trying to use Telerik Testing Framework to automate tests fpr a WPF application that has a drag and drop style "pallette" created using GoXam. I originally started using TestStudio, but got mixed results (sometimes the elements would be dragged and droppe, but not always), I believe that this is because it finds the elements based on location data.
I want to find the elements in the canvas via element data (automationId, type, text etc.), but whenever I try and search for an element by these attributes I get an element not found error. I tried with various different ways of finding the element (Find.ByTextContent, Find.ByAutomationID, Find.ByXamlExpression), but I always seem to get an element not found error.
I have posted my test and the section of the xaml that holds the element that I want to drag and drop below.
Any help would be hugely appreciated.
David
Xaml Section:
<DataTemplate x:Key="GroupTemplate">
<Border BorderThickness="2" Background="{Binding Path=Data.Color}"
BorderBrush="{Binding Path=Data.Color}"
go:Part.SelectionAdorned="True"
go:Part.Resizable= "{Binding Path=Data.Resizable, Mode=TwoWay}"
go:Node.LocationElementName="myGroupPanel"
go:Group.IsSubGraphExpanded="{Binding Path=Data.IsSubGraphExpanded, Mode=TwoWay}"
go:Part.DropOntoBehavior="AddsToGroup">
<StackPanel Background="{Binding Path=Node.IsDropOntoAccepted, Converter={StaticResource theBrushChooser}}">
<StackPanel AutomationProperties.AutomationId="Canvas_Element" Orientation="Horizontal" HorizontalAlignment="Left">
<Button x:Name="myCollapseExpandButton"
Content="{Binding Path=Group.IsExpandedSubGraph, Converter={StaticResource theButtonConverter}}"
Width="20" Margin="0 0 5 0" Visibility="{Binding Path=Data.Visibility}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding Path=DataContext.CollapseExpandCommand,
RelativeSource={RelativeSource AncestorType={x:Type local:HierarchicalView}}, Mode=OneWay}"
CommandParameter="{Binding Path=Group}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TextBox Text="{Binding Path=Data.Name}" FontWeight="Bold" go:Part.TextEditable="{Binding Path=Data.Editable}" FontSize="20" x:Name="TextBox"
IsEnabled="{Binding Path=Data.Editable}" Background="{Binding Path=Data.Color}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding Path=DataContext.LostFocusCommand,
RelativeSource={RelativeSource AncestorType={x:Type local:HierarchicalView}}, Mode=OneWay}"
CommandParameter="{Binding Path=Node}"/>
</i:EventTrigger>
<i:EventTrigger EventName="GotFocus">
<i:InvokeCommandAction Command="{Binding Path=DataContext.GotFocusCommand,
RelativeSource={RelativeSource AncestorType={x:Type local:HierarchicalView}}, Mode=OneWay}"
CommandParameter="{Binding Path=Node}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
<ComboBox Height="20" Width="75" x:Name="combo" Margin="20 0 0 0" ItemsSource="{Binding Path=Data.Elements}" Visibility="{Binding Path=Data.Visibility}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding Path=DataContext.SelectionChangedComboCommand,
RelativeSource={RelativeSource AncestorType={x:Type local:HierarchicalView}}, Mode=OneWay}"
CommandParameter="{Binding Path=Node}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<go:GroupPanel x:Name="myGroupPanel" Padding="5" SurroundsMembersAfterDrop="True" />
<i:Interaction.Triggers>
<i:EventTrigger EventName="Drop">
<i:InvokeCommandAction Command="{Binding Path=DataContext.DropNodeCommand,
RelativeSource={RelativeSource AncestorType={x:Type local:HierarchicalView}}, Mode=OneWay}"
CommandParameter="{Binding Path=Node}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</StackPanel>
<go:Group.Layout>
<go:GridLayout WrappingColumn="1" CellSize="1 1" Conditions="Standard GroupSizeChanged"/>
</go:Group.Layout>
</Border>
</DataTemplate>
</go:DataTemplateDictionary>
Test:
using ArtOfTest.WebAii.Controls.Xaml.Wpf;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.TestTemplates;
using ArtOfTest.WebAii.Wpf;
using ArtOfTest.WebAii.Xaml;
using ArtOfTest.WebAii.TestAttributes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using ArtOfTest.WebAii.Controls.Xaml.Wpf;
namespace UnitTestProject2
{
[TestClass]
public class TelerikNUnitTest1 : BaseWpfTest
{
private TestContext testContextInstance;
public WpfApplication foo_app { get; private set; }
[TestMethod]
public void Open_Application()
{
//TestContext.WriteLine("Start Unit Test");
/// Create my own Settings object and then modify the defaults
Settings mySettings = new Settings();
mySettings.ClientReadyTimeout = 60000;
/// Use my Settings object to construct my Manager object
Manager myManager = new Manager(mySettings);
myManager.Start();
// Launch the application instance from its location in file system
WpfApplication foo_app = myManager.LaunchNewApplication(@"C:\PathTo\Startup.exe");
//TestContext.WriteLine("Opened application");
/// Validate the title of the homepage
ArtOfTest.Common.UnitTesting.Assert.IsTrue(foo_app.MainWindow.Window.Caption.Equals("MainWindow"));
//TestContext.WriteLine("Validated window");
///Click the new project button
FrameworkElement newProjButton = foo_app.MainWindow.Find.ByTextContent("New project...");
//TestContext.WriteLine("Found element");
newProjButton.User.Click();
///Send keys to the project name textbox
FrameworkElement projNameTextBox = foo_app.MainWindow.Find.ByAutomationId("New_Proj_Text_Box");
projNameTextBox.Wait.ForNoMotion(5000);
projNameTextBox.User.Click();
projNameTextBox.User.TypeText("PokeMoon", 100);
///Select the View family
FrameworkElement viewElement = foo_app.MainWindow.Find.ByTextContent("View");
viewElement.User.Click();
///Click the "Create" Button
FrameworkElement createButton = foo_app.MainWindow.Find.ByTextContent("Create");
createButton.User.Click();
/// Wait for the canvas to load
FrameworkElement hierarchicalViewPage = foo_app.MainWindow.Find.ByAutomationId("Hierarchical_View");
hierarchicalViewPage.Wait.ForExists();
///Click on the PROCESS element and then drag it into the canvas
///This is where I cannot find the element.
FrameworkElement processElement = foo_app.MainWindow.Find.ByExpression(new XamlFindExpression("Key='GroupTemplate'", "|", "textcontent='PROCESS', "|", 'AutomationProperties.AutomationId='Canvas_Element'" ")).As<FrameworkElement>(); ;
processElement.Wait.ForNoMotion(5000);
processElement.User.Click();
processElement.User.DragTo(100, 100);
}
}
}