From 004197380ae45d394fcf3b0e8cc53ab840135433 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Fri, 27 Jan 2017 12:52:38 +0000 Subject: Add MacOS gallery and UITest (#721) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [MacOS] Cleanup * [Controls] Add Header support to ListView * [MacOS] NSView reuse on NSTableView * [MacOS] Some fix on layour order * [MacOS] Add CarouselPageRenderer * [MacOS] Implement EventTracker on PageRenderer * [MacOS] Cleanup CarouselPageRenderer * [MacOS] Add MasterDetailPage renderer * [MacOS] MDP renderer don't allow drag of splitter * [MacOS] Add TabbedPage renderer * [MacOS] Initial sketch of NavigationPageRenderer * [MacOS] Send disappearing of CurrentPage on Dispose on NavigationPageRenderer * [MacOS] Add Gallery page for Mac * [MacOS] Add MacOSExpressionSearch * [MacOS] Fix ColorExtension * [MacOS] Fix MDP renderer layout * [MacOS] Implement native selection on ListViewRenderer * [MacOS] Deselect a item on NSTableView * [MacOS] Remove previous SplitViewItems * [MacOS] Fix navigationpage height * [MacOS] Add toolbar for NavigationPageRenderer * [MacOS] Don't remove selection for now (crashing) * [MacOS] Refactor page and back button title on NavigationPageRenderer * [MacOS] Fix bug when native navigate back * [MacOS] Hide layer when transition * [MacOS] ListviewRenderer fix BbackgroundColor * [MacOS] Fix background on ScrollViewRenderer * [MacOS] Fix header measure on ListViewRenderer * [MacOS] Add Mac twitter demo * [Controls] Spaces for easy reading * [MacOS] More xaml cleanup * [Core] Add Mac as aTargetPlatform * [MacOS] Add alerts and actionsheets * [MacOS] Add GestureRecognizers * [MacOS] Fix Layout issues when adding children, enable transformations * [MacOS] Fix title on tab item, move to tabbed navigation based on segmented control * [MacOS] Hide toolbar when not needed, this allows to work with tabbed page, cleanup * [MacOS] Add NativeBindings and NativeViewWrapper * [MacOS] Fix AssemblyInfo * [MacOS] FIX NRE on SetBackgroundColor BoxView * [MacOS] Fix NavigationPageRenderer * [MacOS] Fix build * [MacOS] Also update page when it resizes * [MacOS] Add LayoutRenderer for handle items position when the bounds change. * [MacOS] Refactor/Cleanup * [MacOS] Add toolbar items support to NavigationPage * [MacOS] Resize images for TabViewITems * [MacOS] Fix TabbedPage resize issues , allow users to override some features when creating TVI * [MacOS] Fix hide/show Navigation toolbar * [MacOS] Redo CarouselPageRenderer with NSPageController * [MacOS] Add support for Modal pages * [MacOS] Refactor navigation from platform * [Nuget] Add nuget for MacOS * [Nuget]Fix nuspec * [Nuget] Add variables for CI * [Controls] Remove MainMenu from MacOS * [MacOS] Add TableView renderer (no headers yet) * [MacOS] Refactoring, marking extensions as internal * [MacOS] Add group headers for TableViewRenderer * [MacOS] Workaround for updates on listview collection * [MacOS] Handle updates of rows in the ListViewRenderer properly * [MacOS] Fix navigation animation * Fix navigation header issues with modal pages * [MacOS] Fix MDP issues with resizing * [MacOS] Fix general dispose * [MacOS] Add a ViewControllerWrapper for NSSplitView * [MacOS] MDP renderer fix animation * [MacOS] Fix ListView selection bug * [MacOS] Fix rendering MDP Layout inside wrappers * [MacOS] Re write the MainToolbar handler * [MacOS] Don't use Sierra new extensions so we can run in stable channel * [MacOS] Another way to hide the toolbar (smarter i think) * [MacOS] Fix MDP bug and remove debug color * [Controls] Add HanselForms sample * [MacOS] Fix NRE WebviewRenderer * [MacOS] Fix uneven rows on ListView renderer * [MacOS] Fix NRE on load (can+t find the reason this happens) * [MacOS] Fix uneven rows * [MacOS] Fix header sizing on ListViewRenderer * [Controls] More stuff on HanselForms * [MacOS] Remove warning from ListViewRenderer * [MacOS] Fix PageRenderer bug double init * [MacOS] Don't calculate height if RowHeight is provided * [Controls] More Hanselforms stuff * [MacOS] Once again a new implementation for the NavigationBar, this time using a custom view to support BackgroundColor * [MacOS] Fix build * [MacOS] Refactoring AwesomeBar related controls * Fix build * [MacOS] NavigationBar update background and t test colors * [MacOS] Fix when we remove navigation so it works when the NavigationRenderer wasn't removed from the parent controller like in a TabbedPage * [MacOS] Add support for ListView grouping * [MacOS] Fix image extension method. * [MacOS] Add base Maps project * [MacOS] Export MapRenderer * [MacOS] Add pin click and geocoderbacked for Maps * [MacOS] Add extra binding project for API not in stable. * [MacOS] Add MacOS Maps lib * [MacOS]Fix build on alpha * [MacOS] Remove MacOS Maps extra binding * [UITest] Basic macOS setup * [UITest] Add MacOSApp wrapper implementation * [MacOS] Set AutomationID * [UITests] Add ActionSheetUITests to MacOS UITest * [MacOS] Fix bug on Picker * [UITests] Link basic uitest basefixture and related files * [MacOS] Fix pickers reuse * [UItests] Fix MacOS app path * [UITest] Ignore UItest for appearing on macOS for now * [UITest] Update macOS for 2.0.3 * [UITest] Refactor EnterText MacOS app * [UITest]Fix ViewQuery on MacOS * [UITest]Fix IsEnabled UItest on macOS * [UITest] Implement Enter, mark some tests inconclusive fix others * [MacOS] Implement Entry Completed event * [UITests] Fix UITest for IsVisible, ignore ToolbarItem test for now * [UITests] Fix ISVisible again add extra category * [Controls] Cleanup macOS gallery * [MacOS] Fix Assembly info * [Docs] Fix docs * Fix build * [Nuget] Fix nuspec * [Controls] Link files on MacOS * [Core] Update Forms stack before firing a event saying page was removed, possible breaking change * [MacOS] Implement RemovePage on NavigationPAgeRenderer * [UItest] Ignore some , implement back on MacOS UITest app * [MacOS] Add default back button name (needs to be translated) * [MacOS] Fix dispose * [UITest] Make 29257 work on MacOS * [MacOS] Rename stuff * [MacOS] More renaming and cleanup * [MacOS] Share implementations for iOS * [MacOS] Reuse more IOS extensions * [MacOS] Reuse FontExtensions * [MacOS] Share NativeViewWrapper related stuff * [MAcOS] Share event args and ExportRenderer * [MacOS] Share platform effect * [MacOS] Fix build * [Docs]Fixing docs * [MacOS] Fix ViewCell reuse * [Core] Support ListView CachingStrategy on MacOS * [MacOS] Fix issues with TextCell and ImageCell (we can’t set null to a NSControl value) * [MacOS] Fix MDP child sizing bug [UITest] Query marked by id and text * [MacOS] Comment test related with context actions * [MacOS] Implement missing stuff on ticker * [MacOS] Make sure VisualElemenTracker calls the ticker update * [UITests]Ignore context actions and not possible to test * [MacOS] Fix Grouping bug on Listview * [MacOS] Fix selection on Listview when using grouping * [MacOS] Update navbar when page is popped * [MacOS] Cleanup NavigationBar * [Controls] More info on exceptions * [MacOS] Fix bug animation pop modal * [MacOS] Bring back BackgroundColor of NavigationBar * [MacOS] Fix UITest animation delay * [MacOS] Treat warnings as errors * [MacOS] Center title on toolbar * [Core] Add Platform configuration specific for MacOS * [MacOS] Implement TabbedPage platform specific to handle TabItems on NavigationPage bar * [MacOS] Fix warning * [MacOS] Fix bug on SearchBar color * [MacOS]Fix build * [MacOS] remove extra dll from maps * [Docs] Update docs * [MacOS]Cleanup and refactoring * Revert "[MacOS] remove extra dll from maps" This reverts commit 73b948937001fea3f28449a963d0b94943e07aa0. * [MacOS] Fix wrong refactoring * [MacOS] dix formatting * [MacOS] Fix build * [MacOS] Fix bug on TabbedPageRenderer no title * [MacOS,UITest] Update packages * [MacOS ,UITest] Add delay when tapping something, and focus with double click * [MacOS,UITest] Ignore UITest, not possible to test with current version * [MacOS,UITest] Ignore test that uses Frame, UITest doesn’t return it * [MacOS] Fix bug when no title on toolbar items * [MacOS] Remove FormsNSView * [MacOS] Cleanup on dispose on MDP renderer * [MacOS] Different way to test leak of MDP, need to look at this again after * [MacOS] Update current page when source changes * [MacOS] More cleanup * [MacOS,UITest] Implement ClearText * [MacOS,UITest] ClearText doesn’t work for now on MacOS uitest * [MacOS] Make sure we show the previous page when popping a Modal * [MacOS] Fix issue with sizing the Header and visibility, remove for now header renderer reuse * [MacOS] Clean CustomNSTableView * [MacOS] Share LabelRenderer with iOS * [MacOS,UITest] Don’t try to scroll for the element * [MacOS] Share ResourcesProvider with iOS * [MAcoS] Share VisualElementPackager with iOS * [MacOS] Share ViewRenderer with iOS * [MacOS] Merge with VisualElementTracker from iOS * [MacOS] Merge with EventTracker from iOS * [MacOS] Merge with VisualElementRenderer of iOS * [MacOS] Make sure we always have a layer * [MacOS] Fix Tracker merge with iOS version * [MacOS] Fix bug with tabbed page on modal without navigation * [Core] Rever change on core * [Controls] Add missing image * [MacOS] Clear renderers before setting them MDP * [MacOS] Update tabbedPage ContainerArea * [Controls] Add Custom renderers tests * [MacOS] Fix ListViewRenderer * [MacOS,UITest] Refactoring, implement index * [MacOS] Make sure we don’t pass null to TextField string value * [MacOS] Support for multiple clicks in same selected item on NSTableView * [MacOS, UITest] Fix bug on Back because of refactoring * [MacOS,UITest] Ignore UITest because we’d-not have ScrollDownTo yet * [MacOS] Support Focus on EntryRenderer * [MacOS,UITest] Ignore more a couple of tests that we can’t test on UITest Desktop * [MacOS,UITest] MacOSApp looks for StaticText fields too * [MacOS, UITest] Fix EnterText for marked Entry * [MacOS] Fix index bug on TablevIewDataSource * [MacOS] Fix SelectedItem TableViewDataSource * [Nuget] Add Mac to Maps nuspec * [Nuget]Fix path * [Controls] Add basic FormsGallery sample * [macOS] Fixed Tab NSImage crash in TabbedPageRenderer (#705) * [macOS] Fixed Tab NSImage crash in TabbedPageRenderer * Coding Style * Coding Style * [MacOS] Fix previous merge with master * [MacOS] Possible simple fix for click on views overlapping * [UItest] Ignore this part of the test we can’t click on NSViews yet * [MacOS] Rename to IsOnViewCell * fix docs * [MacOS] Cleanup, Address feedback from Samantha’s review * [MacOS] Add ContextActions * [Controls] Remove FormsGalery for now * [Docs] Update docs * [MacOS] Implement ContextActions * [MacOS,UITests] Enable and support UITests of ContextActions --- Xamarin.Forms.Core.macOS.UITests/MacOSApp.cs | 702 +++++++++++++++++++++ .../Properties/AssemblyInfo.cs | 26 + .../Xamarin.Forms.Core.macOS.UITests.csproj | 232 +++++++ Xamarin.Forms.Core.macOS.UITests/packages.config | 10 + 4 files changed, 970 insertions(+) create mode 100644 Xamarin.Forms.Core.macOS.UITests/MacOSApp.cs create mode 100644 Xamarin.Forms.Core.macOS.UITests/Properties/AssemblyInfo.cs create mode 100644 Xamarin.Forms.Core.macOS.UITests/Xamarin.Forms.Core.macOS.UITests.csproj create mode 100644 Xamarin.Forms.Core.macOS.UITests/packages.config (limited to 'Xamarin.Forms.Core.macOS.UITests') diff --git a/Xamarin.Forms.Core.macOS.UITests/MacOSApp.cs b/Xamarin.Forms.Core.macOS.UITests/MacOSApp.cs new file mode 100644 index 00000000..08c3118d --- /dev/null +++ b/Xamarin.Forms.Core.macOS.UITests/MacOSApp.cs @@ -0,0 +1,702 @@ +using System; +using System.IO; +using System.Collections.Generic; +using Xamarin.UITest; +using Xamarin.UITest.Desktop; +using Xamarin.UITest.Queries; +using System.Linq; +using System.Diagnostics; +using System.Threading; +using System.Drawing; + +namespace Xamarin.Forms.Core.macOS.UITests +{ + public static class MacOSAppExtensions + { + public static UITest.Queries.AppResult ToUITestResult(this UITest.Desktop.AppResult result) + { + return new UITest.Queries.AppResult + { + Id = result.Id ?? result.TestId, + Label = result.Label, + Text = result.Text ?? result.Value, + Enabled = result.Enabled, + Class = result.Class, + Rect = new UITest.Queries.AppRect + { + X = result.Rect.X, + Y = result.Rect.Y, + Width = result.Rect.Width, + Height = result.Rect.Height, + CenterX = result.Rect.CenterX, + CenterY = result.Rect.CenterY + } + }; + } + } + + + public class MacOSApp : Xamarin.UITest.IApp + { + string _backButtonIdentifier = "NSBackButton"; + static CocoaApp _cocoaApp; + public MacOSApp(CocoaApp app) + { + _cocoaApp = app; + } + public IDevice Device + { + get + { + return null; + } + } + + public AppPrintHelper Print + { + get + { + return null; + } + } + + public ITestServer TestServer + { + get + { + return null; + } + } + + public void Back() + { + Tap(_backButtonIdentifier); + } + + public void ClearText() + { + _cocoaApp.ClearText(); + } + + public void ClearText(string marked) + { + var textField = _cocoaApp.QueryById(marked).FirstOrDefault((arg) => arg.Class.Contains("SearchField") || arg.Class.Contains("TextField")); + ClearText(textField.Rect.CenterX, textField.Rect.CenterY); + } + + public void ClearText(Func query) + { + + } + + public void ClearText(Func query) + { + var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString(); + + var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b"); + if (isMarked) + { + var markedWord = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'"); + var isAll = markedWord[0].Trim() == "*"; + var marked = markedWord[1].Replace("'", ""); + ClearText(marked); + } + } + + public void DismissKeyboard() + { + + } + + public void DoubleTap(string marked) + { + + } + + public void DoubleTap(Func query) + { + + } + + public void DoubleTapCoordinates(float x, float y) + { + + } + + public void DragAndDrop(string from, string to) + { + + } + + public void DragAndDrop(Func from, Func to) + { + + } + + public void DragCoordinates(float fromX, float fromY, float toX, float toY) + { + + } + + public void EnterText(string text) + { + var all = _cocoaApp.Query(); + var staticText = _cocoaApp.QueryByType("StaticText"); + var textFields = _cocoaApp.QueryByType("Textfield"); + var textField = staticText.Union(textFields).FirstOrDefault(); + EnterText(text, textField.Rect.CenterX, textField.Rect.CenterY); + } + + public void EnterText(Func query, string text) + { + + } + + public void EnterText(string marked, string text) + { + var textField = _cocoaApp.QueryById(marked).FirstOrDefault((arg) => arg.Class.Contains("SearchField") || arg.Class.Contains("TextField")); + EnterText(text, textField.Rect.CenterX, textField.Rect.CenterY); + } + + public void EnterText(Func query, string text) + { + string markedWord = string.Empty; + int indexMarked = 0; + + if (ExtractInfo(query, out markedWord, out indexMarked)) + EnterText(markedWord, indexMarked, text); + } + + public UITest.Queries.AppResult[] Flash(string marked) + { + var resulr = new List(); + return resulr.ToArray(); + } + + public UITest.Queries.AppResult[] Flash(Func query = null) + { + var resulr = new List(); + return resulr.ToArray(); + } + + public object Invoke(string methodName, object[] arguments) + { + return null; + } + + public object Invoke(string methodName, object argument = null) + { + return null; + } + + public void PinchToZoomIn(string marked, TimeSpan? duration = default(TimeSpan?)) + { + + } + + public void PinchToZoomIn(Func query, TimeSpan? duration = default(TimeSpan?)) + { + + } + + public void PinchToZoomInCoordinates(float x, float y, TimeSpan? duration) + { + + } + + public void PinchToZoomOut(string marked, TimeSpan? duration = default(TimeSpan?)) + { + + } + + public void PinchToZoomOut(Func query, TimeSpan? duration = default(TimeSpan?)) + { + + } + + public void PinchToZoomOutCoordinates(float x, float y, TimeSpan? duration) + { + + } + + public void PressEnter() + { + _cocoaApp.SendKey(13, KeyModifier.None); + } + + public void PressVolumeDown() + { + + } + + public void PressVolumeUp() + { + + } + + public AppWebResult[] Query(Func query) + { + var resulr = new List(); + return resulr.ToArray(); + } + + public string[] Query(Func query) + { + return new List().ToArray(); + } + + public UITest.Queries.AppResult[] Query(string marked) + { + var results = new List(); + var allResults = _cocoaApp.Query(); + var allResultsById = _cocoaApp.QueryById(marked); + foreach (var result in allResultsById) + results.Add(result.ToUITestResult()); + var allResultsByText = _cocoaApp.QueryByText(marked); + foreach (var result in allResultsByText) + results.Add(result.ToUITestResult()); + return results.ToArray(); + } + + public UITest.Queries.AppResult[] Query(Func query = null) + { + var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString(); + var results = new List(); + var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b"); + var isText = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\btext\b"); + if (isMarked) + { + var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'"); + var isAll = markedWords[0].Trim() == "*"; + var markedWord = markedWords[1].Remove(markedWords[1].Length - 1).Trim(); + return Query(markedWord); + } + if (isText) + { + var textWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\btext\b:'"); + var isAll = textWords[0].Trim() == "*"; + var textWord = textWords[1].Remove(textWords[1].Length - 1).Trim(); + return Query(textWord); + } + else if (queryStr.Contains("* index:0")) + { + var allREsults = _cocoaApp.Query(); + var result = allREsults[0].Children[0]; + results.Add(result.ToUITestResult()); + } + else if (queryStr.Contains("* index:7")) + { + var allREsults = _cocoaApp.Query(); + var result = allREsults[0].Children[0].Children[0].Children[1]; + results.Add(result.ToUITestResult()); + } + + return results.ToArray(); + } + + public T[] Query(Func> query) + { + + var results = new List(); + var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString(); + var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b"); + if (isMarked) + { + var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'"); + var isAll = markedWords[0].Trim() == "*"; + var markedWord = markedWords[1].Replace("'", ""); + var ss = Query(markedWord); + + } + else if (queryStr.Contains("* index:0")) + { + + var allREsults = _cocoaApp.Query(); + var result = allREsults[0].Children[0]; + // results.Add(result.ToUITestResult()); + } + else if (queryStr.Contains("* index:7")) + { + var allREsults = _cocoaApp.Query(); + var result = allREsults[0].Children[0].Children[0].Children[1]; + // results.Add(result.ToUITestResult()); + } + + return results.ToArray(); + } + + public void Repl() + { + + } + + public FileInfo Screenshot(string title) + { + return null; + } + + public void ScrollDown(string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void ScrollDown(Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void ScrollDownTo(Func toQuery, Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void ScrollDownTo(Func toQuery, Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void ScrollDownTo(Func toQuery, string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void ScrollDownTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void ScrollTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void ScrollUp(string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void ScrollUp(Func query = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void ScrollUpTo(Func toQuery, string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void ScrollUpTo(Func toQuery, Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void ScrollUpTo(Func toQuery, Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void ScrollUpTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = default(TimeSpan?)) + { + + } + + public void SetOrientationLandscape() + { + + } + + public void SetOrientationPortrait() + { + + } + + public void SetSliderValue(Func query, double value) + { + + } + + public void SetSliderValue(string marked, double value) + { + + } + + public void SwipeLeft() + { + + } + + public void SwipeLeftToRight(double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void SwipeLeftToRight(Func query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void SwipeLeftToRight(Func query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + throw new NotImplementedException(); + } + + public void SwipeLeftToRight(string marked, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void SwipeRight() + { + + } + + public void SwipeRightToLeft(double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void SwipeRightToLeft(Func query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + throw new NotImplementedException(); + } + + public void SwipeRightToLeft(Func query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void SwipeRightToLeft(string marked, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) + { + + } + + public void Tap(Func query) + { + + } + + public void Tap(string marked) + { + Tap(marked, 0); + } + + public void Tap(Func query) + { + string markedWord = string.Empty; + int indexMarked = 0; + + if (ExtractInfo(query, out markedWord, out indexMarked)) + Tap(markedWord, indexMarked); + } + + public void TapCoordinates(float x, float y) + { + + } + + public void TouchAndHold(string marked) + { + TouchAndHold(marked, 0); + } + + void TouchAndHold(string marked, int index) + { + var safeIndex = Math.Max(index, 0); + var queryById = _cocoaApp.QueryById(marked.Trim())[safeIndex]; + TouchAndHoldCoordinates(queryById.Rect.CenterX, queryById.Rect.CenterY); + + } + + public void TouchAndHold(Func query) + { + string markedWord = string.Empty; + int indexMarked = 0; + + if (ExtractInfo(query, out markedWord, out indexMarked)) + TouchAndHold(markedWord, indexMarked); + } + + public void TouchAndHoldCoordinates(float x, float y) + { + _cocoaApp.RightClick(x, y); + Thread.Sleep(1000); + } + + public void WaitFor(Func predicate, string timeoutMessage = "Timed out waiting...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?)) + { + + } + + public AppWebResult[] WaitForElement(Func query, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?)) + { + var resulr = new List(); + return resulr.ToArray(); + } + + public UITest.Queries.AppResult[] WaitForElement(string marked, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?)) + { + var results = new List(); + + var queryById = _cocoaApp.QueryById(marked); + foreach (var res in queryById) + { + results.Add(res.ToUITestResult()); + } + Stopwatch s = new Stopwatch(); + s.Start(); + bool foundElement = false; + while (s.Elapsed < timeout && !foundElement) + { + var allResultsById = _cocoaApp.QueryById(marked); + foreach (var res in queryById) + { + results.Add(res.ToUITestResult()); + } + foundElement = results.Count > 0; + System.Diagnostics.Debug.WriteLine(foundElement); + } + s.Stop(); + + return results.ToArray(); + } + + public UITest.Queries.AppResult[] WaitForElement(Func query, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?)) + { + var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString(); + var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b"); + if (isMarked) + { + var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'"); + var isAll = markedWords[0].Trim() == "*"; + var markedWord = markedWords[1].Replace("'", "").Trim(); + return WaitForElement(markedWord, timeoutMessage, timeout, retryFrequency, postTimeout); + } + return new List().ToArray(); + } + + public void WaitForNoElement(Func query, string timeoutMessage = "Timed out waiting for no element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?)) + { + + + } + + public void WaitForNoElement(string marked, string timeoutMessage = "Timed out waiting for no element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?)) + { + Stopwatch s = new Stopwatch(); + s.Start(); + bool noElement = false; + while (s.Elapsed < timeout && !noElement) + { + var allResultsById = _cocoaApp.QueryById(marked); + noElement = allResultsById.Length == 0; + System.Diagnostics.Debug.WriteLine(noElement); + } + s.Stop(); + if (s.Elapsed < timeout && !noElement) + throw (new Exception(timeoutMessage)); + + } + + public void WaitForNoElement(Func query, string timeoutMessage = "Timed out waiting for no element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?)) + { + var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString(); + var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b"); + if (isMarked) + { + var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'"); + var isAll = markedWords[0].Trim() == "*"; + var markedWord = markedWords[1].Replace("'", "").Trim(); + WaitForNoElement(markedWord, timeoutMessage, timeout, retryFrequency, postTimeout); + } + } + + static bool ExtractInfo(Func query, out string markedWord, out int indexMarked) + { + indexMarked = 0; + markedWord = string.Empty; + var isSuccess = false; + var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString(); + var isIndex = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bindex\b"); + if (isIndex) + { + var indexWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bindex\b:"); + var indexWord = indexWords[1]; + int.TryParse(indexWord, out indexMarked); + queryStr = indexWords[0].Trim(); + } + var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b"); + if (isMarked) + { + var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'"); + var isAll = markedWords[0].Trim() == "*"; + markedWord = markedWords[1].Replace("'", "").Trim(); + isSuccess = true; + + } + var isText = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\btext\b"); + if (isText) + { + var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\btext\b:'"); + var isAll = markedWords[0].Trim() == "*"; + markedWord = markedWords[1].Replace("'", "").Trim(); + isSuccess = true; + } + return isSuccess; + } + + void Tap(string marked, int index) + { + var safeIndex = Math.Max(index, 0); + var queryById = _cocoaApp.QueryById(marked.Trim())[safeIndex]; + _cocoaApp.Click(queryById.Rect.CenterX, queryById.Rect.CenterY); + Thread.Sleep(1000); + } + + static void EnterText(string marked, int index, string text) + { + UITest.Desktop.AppResult textField = null; + var safeIndex = Math.Max(index, 0); + var textFields = _cocoaApp.QueryById(marked).Where((arg) => arg.Class.Contains("SearchField") || arg.Class.Contains("TextField")); + if (textFields.Count() > 0) + { + textField = textFields.ElementAt(safeIndex); + } + else + { + var markedField = _cocoaApp.QueryById(marked); + if (markedField.Length > 0) + { + textField = markedField[0]; + } + else + { + + var allTextFields = _cocoaApp.QueryByType("TextField"); + textField = allTextFields[0]; + } + } + + if (textField != null) + EnterText(text, textField.Rect.CenterX, textField.Rect.CenterY); + + } + + static void EnterText(string text, float x, float y) + { + _cocoaApp.Click(x, y); + _cocoaApp.Click(x, y); + Thread.Sleep(500); + _cocoaApp.EnterText(text); + Thread.Sleep(500); + } + + static void ClearText(float x, float y) + { + _cocoaApp.Click(x, y); + _cocoaApp.Click(x, y); + Thread.Sleep(500); + _cocoaApp.ClearText(); + Thread.Sleep(500); + } + } +} diff --git a/Xamarin.Forms.Core.macOS.UITests/Properties/AssemblyInfo.cs b/Xamarin.Forms.Core.macOS.UITests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..ae37f172 --- /dev/null +++ b/Xamarin.Forms.Core.macOS.UITests/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Xamarin.Forms.Core.macOS.UITests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Xamarin.Forms.Core.macOS.UITests/Xamarin.Forms.Core.macOS.UITests.csproj b/Xamarin.Forms.Core.macOS.UITests/Xamarin.Forms.Core.macOS.UITests.csproj new file mode 100644 index 00000000..e70ae03b --- /dev/null +++ b/Xamarin.Forms.Core.macOS.UITests/Xamarin.Forms.Core.macOS.UITests.csproj @@ -0,0 +1,232 @@ + + + + Debug + AnyCPU + {9DB0CABB-24CC-4538-88EC-6E0A0FE40248} + Library + Xamarin.Forms.Core.macOS.UITests + Xamarin.Forms.Core.macOS.UITests + v4.5 + + + true + full + false + bin\Debug + DEBUG;__MACOS__;UITEST + prompt + 4 + false + + + true + bin\Release + prompt + 4 + false + + + + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\ServiceStack.Interfaces.4.5.4\lib\portable-wp80+sl5+net45+win8+wpa81+monotouch+monoandroid+xamarin.ios10\ServiceStack.Interfaces.dll + + + ..\packages\ServiceStack.Text.4.5.4\lib\net45\ServiceStack.Text.dll + + + ..\packages\ServiceStack.Client.4.5.4\lib\net45\ServiceStack.Client.dll + + + ..\packages\Xamarin.UITest.Desktop.0.0.7\lib\net45\Xamarin.UITest.Desktop.dll + + + + + + + + + + + + + + + + + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + + ..\packages\Xamarin.UITest.2.0.5\lib\Xamarin.UITest.dll + + + + + + Tests\ActionSheetUITests.cs + + + BaseTestFixture.cs + + + UITestCategories.cs + + + Queries.cs + + + Utilities\AppExtensions.cs + + + PlatformQueries.cs + + + Utilities\Drag.cs + + + Utilities\Gestures.cs + + + Utilities\UITestCustomExceptions.cs + + + + Tests\ActivityIndicatorUITests.cs + + + Tests\ViewUITests.cs + + + Remotes\BaseViewContainerRemote.cs + + + Remotes\EventViewContainerRemote.cs + + + Remotes\LayeredViewContainerRemote.cs + + + Remotes\StateViewContainerRemote.cs + + + Remotes\ViewContainerRemote.cs + + + Utilities\ViewInspector.cs + + + Utilities\Logger.cs + + + Utilities\NumericExtensions.cs + + + Utilities\ParsingUtils.cs + + + Tests\AppearingUITests.cs + + + Tests\AutomationIDUITests.cs + + + Tests\BoxViewUITests.cs + + + Tests\ButtonUITests.cs + + + Tests\ContextActionsUITests.cs + + + Tests\DatePickerUITests.cs + + + Tests\DisplayAlertUITests.cs + + + Tests\EditorUITests.cs + + + Tests\EntryUITests.cs + + + Tests\FrameUITests.cs + + + Tests\ImageUITests.cs + + + Tests\LabelUITests.cs + + + Tests\Legacy-CellsUITests.cs + + + Tests\Legacy-UnevenListTests.cs + + + Tests\PickerUITests.cs + + + Tests\ProgressBarUITests.cs + + + Tests\RootGalleryUITests.cs + + + Tests\ScrollViewUITests.cs + + + Tests\SearchBarUITests.cs + + + Tests\SliderUITests.cs + + + Tests\StepperUITests.cs + + + Tests\SwitchUITests.cs + + + Tests\TimePickerUITests.cs + + + Tests\ToolbarItemTests.cs + + + Tests\WebViewUITests.cs + + + + + + + + + + + + {4DCD0420-1168-4B77-86DB-6196EE4BD491} + Xamarin.Forms.CustomAttributes + + + {57B8B73D-C3B5-4C42-869E-7B2F17D354AC} + Xamarin.Forms.Core + + + {7D13BAC2-C6A4-416A-B07E-C169B199E52B} + Xamarin.Forms.Maps + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Core.macOS.UITests/packages.config b/Xamarin.Forms.Core.macOS.UITests/packages.config new file mode 100644 index 00000000..49c66041 --- /dev/null +++ b/Xamarin.Forms.Core.macOS.UITests/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3