From dd8618e14feaab31301322eba64d9b6214eb1d28 Mon Sep 17 00:00:00 2001 From: adrianknight89 Date: Wed, 3 Jul 2019 23:09:02 -0500 Subject: [PATCH] Create UI test template for XAML pages (#5853) * create template for XAML pages * update existing template * added BindingContext * removed whitespace * move BindingContext * change class name to Issue * fixed absolute path --- .../Xamarin.Forms.Controls.Issues.Shared.projitems | 8 +++ .../_Template.cs | 28 ++++++++-- .../_TemplateMarkup.xaml | 11 ++++ .../_TemplateMarkup.xaml.cs | 64 ++++++++++++++++++++++ 4 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index f634d3c..c982c22 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -523,6 +523,10 @@ + + _TemplateMarkup.xaml + Code + @@ -1230,6 +1234,10 @@ + + Designer + MSBuild:Compile + Designer MSBuild:UpdateDesignTimeXaml diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_Template.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_Template.cs index 91574b6..e5f6e0f 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_Template.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_Template.cs @@ -21,9 +21,11 @@ namespace Xamarin.Forms.Controls.Issues // Initialize ui here instead of ctor Content = new Label { - AutomationId = "IssuePageLabel", + AutomationId = "Issue1Label", Text = "See if I'm here" }; + + BindingContext = new ViewModelIssue1(); } #if UITEST @@ -31,10 +33,28 @@ namespace Xamarin.Forms.Controls.Issues public void Issue1Test() { // Delete this and all other UITEST sections if there is no way to automate the test. Otherwise, be sure to rename the test and update the Category attribute on the class. Note that you can add multiple categories. - RunningApp.Screenshot ("I am at Issue 1"); - RunningApp.WaitForElement (q => q.Marked ("IssuePageLabel")); - RunningApp.Screenshot ("I see the Label"); + RunningApp.Screenshot("I am at Issue1"); + RunningApp.WaitForElement(q => q.Marked("Issue1Label")); + RunningApp.Screenshot("I see the Label"); } #endif } + + [Preserve(AllMembers = true)] + public class ViewModelIssue1 + { + public ViewModelIssue1() + { + + } + } + + [Preserve(AllMembers = true)] + public class ModelIssue1 + { + public ModelIssue1() + { + + } + } } \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml new file mode 100644 index 0000000..52aea40 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml.cs new file mode 100644 index 0000000..e9b25fb --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml.cs @@ -0,0 +1,64 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using Xamarin.Forms.Xaml; + +#if UITEST +using Xamarin.Forms.Core.UITests; +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [Category(UITestCategories.ManualReview)] +#endif +#if APP + [XamlCompilation(XamlCompilationOptions.Compile)] +#endif + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 2, "Issue Description (Markup)", PlatformAffected.Default)] + public partial class _TemplateMarkup : TestContentPage + { + public _TemplateMarkup() + { +#if APP + InitializeComponent(); +#endif + } + + protected override void Init() + { + BindingContext = new ViewModelIssue2(); + } + +#if UITEST + [Test] + public void Issue2Test() + { + // Delete this and all other UITEST sections if there is no way to automate the test. Otherwise, be sure to rename the test and update the Category attribute on the class. Note that you can add multiple categories. + RunningApp.Screenshot("I am at Issue2"); + RunningApp.WaitForElement(q => q.Marked("Issue2Label")); + RunningApp.Screenshot("I see the Label"); + } +#endif + } + + [Preserve(AllMembers = true)] + public class ViewModelIssue2 + { + public ViewModelIssue2() + { + + } + } + + [Preserve(AllMembers = true)] + public class ModelIssue2 + { + public ModelIssue2() + { + + } + } +} \ No newline at end of file -- 2.7.4