Create UI test template for XAML pages (#5853)
authoradrianknight89 <adrianknight89@outlook.com>
Thu, 4 Jul 2019 04:09:02 +0000 (23:09 -0500)
committerSamantha Houts <samhouts@users.noreply.github.com>
Thu, 4 Jul 2019 04:09:02 +0000 (21:09 -0700)
* 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/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_Template.cs
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/_TemplateMarkup.xaml.cs [new file with mode: 0644]

index f634d3c..c982c22 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39458.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39853.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)MultipleClipToBounds.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)_TemplateMarkup.xaml.cs">
+         <DependentUpon>_TemplateMarkup.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)PerformanceGallery\PerformanceDataManager.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)PerformanceGallery\PerformanceGallery.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)PerformanceGallery\PerformanceScenario.cs" />
     </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
+    <EmbeddedResource Include="$(MSBuildThisFileDirectory)_TemplateMarkup.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </EmbeddedResource>
     <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue5801.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
index 91574b6..e5f6e0f 100644 (file)
@@ -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 (file)
index 0000000..52aea40
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<controls:TestContentPage
+    xmlns="http://xamarin.com/schemas/2014/forms"
+    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+    xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
+    x:Class="Xamarin.Forms.Controls.Issues._TemplateMarkup">
+
+    <Grid>
+        <Label AutomationId="Issue2Label" Text="See if I'm here (Markup)"/>
+    </Grid>
+</controls:TestContentPage>
\ 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 (file)
index 0000000..e9b25fb
--- /dev/null
@@ -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