From 229250aed7bf28dcb94fd883a0051adb6446691d Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Mon, 5 Aug 2019 14:26:34 -0600 Subject: [PATCH] [UITest] Change Query to WaitForElement on 45125 and change GetResult to await for Performance Gallery testing (#7057) * change query to waitforelement and use async over GetResult * - ConfigureAwait(false) --- .../Bugzilla45125.cs | 4 +-- .../PerformanceDataManager.cs | 10 +++---- .../PerformanceGallery/PerformanceGallery.cs | 29 +++++++++++++++---- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45125.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45125.cs index 9178cdcfb..64a7a9432 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45125.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45125.cs @@ -256,8 +256,8 @@ namespace Xamarin.Forms.Controls.Issues RunningApp.WaitForElement (q => q.Marked (DisappearingLabelId)); RunningApp.Screenshot ("There should be appearing and disappearing events for the Groups and Items."); - var appearing = int.Parse(RunningApp.Query(q => q.Marked(AppearingLabelId))[0].Text); - var disappearing = int.Parse(RunningApp.Query(q=> q.Marked(DisappearingLabelId))[0].Text); + var appearing = int.Parse(RunningApp.WaitForElement(AppearingLabelId)[0].ReadText()); + var disappearing = int.Parse(RunningApp.WaitForElement(DisappearingLabelId)[0].ReadText()); Assert.IsTrue(appearing > 0, $"Test {_TestNumber}: No appearing events for groups found."); Assert.IsTrue(disappearing > 0, $"Test {_TestNumber}: No disappearing events for groups found."); diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PerformanceGallery/PerformanceDataManager.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PerformanceGallery/PerformanceDataManager.cs index 3abd187d7..33b1ab7fd 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PerformanceGallery/PerformanceDataManager.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PerformanceGallery/PerformanceDataManager.cs @@ -38,7 +38,7 @@ namespace Xamarin.Forms.Controls.Issues public static async Task> GetScenarioResults(string deviceId) { - var response = await _client.GetAsync(GetScenarioResultsRoute + deviceId); + var response = await _client.GetAsync(GetScenarioResultsRoute + deviceId).ConfigureAwait(false); if (!response.IsSuccessStatusCode) return new Dictionary(); @@ -63,12 +63,12 @@ namespace Xamarin.Forms.Controls.Issues }; var json = JsonConvert.SerializeObject(data); var content = new StringContent(json, Encoding.UTF8, "application/json"); - var response = await _client.PostAsync(PostScenarioResultRoute + scenarioName, content); - var responseContent = await response.Content.ReadAsStringAsync(); + var response = await _client.PostAsync(PostScenarioResultRoute + scenarioName, content).ConfigureAwait(false); + var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var scenarioResult = JsonConvert.DeserializeObject(responseContent); - await PostScenarioResultDetails(scenarioResult.Id, details); + await PostScenarioResultDetails(scenarioResult.Id, details).ConfigureAwait(false); } static async Task PostScenarioResultDetails(Guid scenarioResultId, Dictionary details) @@ -84,7 +84,7 @@ namespace Xamarin.Forms.Controls.Issues Name = detail.Key }; var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json"); - await _client.PostAsync(PostScenarioResultDetailsRoute + scenarioResultId, content); + await _client.PostAsync(PostScenarioResultDetailsRoute + scenarioResultId, content).ConfigureAwait(false); } } diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PerformanceGallery/PerformanceGallery.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PerformanceGallery/PerformanceGallery.cs index ce07b5f92..060890dec 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PerformanceGallery/PerformanceGallery.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PerformanceGallery/PerformanceGallery.cs @@ -41,7 +41,7 @@ namespace Xamarin.Forms.Controls.Issues PerformanceTracker _PerformanceTracker = new PerformanceTracker(); List _TestCases = new List(); int _TestNumber = 0; - + Button nextButton; PerformanceViewModel ViewModel => BindingContext as PerformanceViewModel; protected override void Init() @@ -65,7 +65,7 @@ namespace Xamarin.Forms.Controls.Issues _TestCases.AddRange(InflatePerformanceScenarios()); - var nextButton = new Button { Text = Pending, IsEnabled = false, AutomationId = NextButtonId }; + nextButton = new Button { Text = Pending, IsEnabled = false, AutomationId = NextButtonId }; nextButton.Clicked += NextButton_Clicked; ViewModel.TestRunReferenceId = Guid.NewGuid(); @@ -82,11 +82,30 @@ namespace Xamarin.Forms.Controls.Issues }; Content = new StackLayout { Children = { testRunRef, nextButton, _PerformanceTracker } }; + GetBenchmarkResults(); + } - ViewModel.BenchmarkResults = Task.Run(() => PerformanceDataManager.GetScenarioResults(_DeviceIdentifier)).GetAwaiter().GetResult(); + async void GetBenchmarkResults(int tryCount = 0) + { + bool success = false; + try + { + ViewModel.BenchmarkResults = await PerformanceDataManager.GetScenarioResults(_DeviceIdentifier); + success = true; + } + catch(Exception exc) + { + if (tryCount < 3) + GetBenchmarkResults(++tryCount); + else + nextButton.Text = exc.ToString(); + } - nextButton.IsEnabled = true; - nextButton.Text = Next; + if (success) + { + nextButton.IsEnabled = true; + nextButton.Text = Next; + } } private static string GetBuildNumber()