Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 32d2fd4

Browse files
authored
UI Test reliability updates (#12012)
* UI test reliability updates - retry text request on API 19 - change monkeys to load all from internal URLS * - more clicking * - adjust tests a bit more * - coalesce * - smaller monkies
1 parent 93f3cf8 commit 32d2fd4

File tree

3 files changed

+81
-12
lines changed

3 files changed

+81
-12
lines changed

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9682.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<ColumnDefinition Width="Auto" />
3737
<ColumnDefinition Width="*" />
3838
</Grid.ColumnDefinitions>
39-
<Image Aspect="AspectFill" AutomationId="MonkeyImages">
39+
<Image Aspect="AspectFit" AutomationId="MonkeyImages">
4040
<Image.Source>
4141
<UriImageSource Uri="{Binding Image}" CachingEnabled="False"></UriImageSource>
4242
</Image.Source>

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9682.xaml.cs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ public void MonkiesShouldLoad()
5050
{
5151
var images = RunningApp.WaitForElement("MonkeyImages");
5252

53-
if (images[0].Rect.Height < 50 || images[0].Rect.Width < 50)
53+
if (images[0].Rect.Height < 20 || images[0].Rect.Width < 20)
5454
return null;
5555

5656
return images;
5757
});
5858

59+
monkeyImages = monkeyImages ?? RunningApp.WaitForElement("MonkeyImages");
60+
5961
Assert.IsNotNull(monkeyImages);
60-
Assert.GreaterOrEqual(monkeyImages[0].Rect.Height, 50);
61-
Assert.GreaterOrEqual(monkeyImages[0].Rect.Width, 50);
62+
Assert.GreaterOrEqual(monkeyImages[0].Rect.Height, 20);
63+
Assert.GreaterOrEqual(monkeyImages[0].Rect.Width, 20);
6264
}
6365
#endif
6466
}
@@ -133,8 +135,46 @@ async Task GetMonkeysAsync()
133135
try
134136
{
135137
IsBusy = true;
136-
var json = await Client.GetStringAsync("https://montemagno.com/monkeys.json");
137-
Monkey[] monkeys = Monkey.FromJson(json);
138+
await Task.Delay(500);
139+
Monkey[] monkeys = new[]
140+
{
141+
new Monkey()
142+
{
143+
Details = "Climbs high buildings and enjoys swatting at planes",
144+
Latitude = 42,
145+
Longitude = 42,
146+
Location = "Empire State Building",
147+
Name = "King Kong",
148+
Image = "https://github.com/xamarin/Xamarin.Forms/blob/17881ec93d6b3fb0ee5e1a2be46d7eeadef23529/Xamarin.Forms.ControlGallery.Android/Resources/drawable/Fruits.jpg?raw=true"
149+
},
150+
new Monkey()
151+
{
152+
Details = "Monkeys aren't donkeys, Quit messing with my head!",
153+
Latitude = 42,
154+
Longitude = 42,
155+
Location = "The 90s",
156+
Name = "Donkey Kong",
157+
Image = "https://github.com/xamarin/Xamarin.Forms/blob/17881ec93d6b3fb0ee5e1a2be46d7eeadef23529/Xamarin.Forms.ControlGallery.Android/Resources/drawable/FlowerBuds.jpg?raw=true"
158+
},
159+
new Monkey()
160+
{
161+
Details = "Grape Ape, Grape Ape! Grape Ape, Grape Ape! Grape Ape, Grape Ape! Grape Ape, Grape Ape!",
162+
Latitude = 42,
163+
Longitude = 42,
164+
Location = "Sunday Mornings",
165+
Name = "Grape Ape",
166+
Image = "https://github.com/xamarin/Xamarin.Forms/blob/17881ec93d6b3fb0ee5e1a2be46d7eeadef23529/Xamarin.Forms.ControlGallery.Android/Resources/drawable/games.png?raw=true"
167+
},
168+
new Monkey()
169+
{
170+
Details = "Pretty but easily persuaded into doing others biddings",
171+
Latitude = 42,
172+
Longitude = 42,
173+
Location = "The Sky",
174+
Name = "Flying Monkey",
175+
Image = "https://github.com/xamarin/Xamarin.Forms/blob/17881ec93d6b3fb0ee5e1a2be46d7eeadef23529/Xamarin.Forms.ControlGallery.Android/Resources/drawable/gear.png?raw=true"
176+
},
177+
};
138178

139179
Monkeys.Clear();
140180
foreach (var monkey in monkeys)

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ShellBackButtonBehavior.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ public class BackButtonPage : ContentPage
4848
{
4949
BackButtonBehavior behavior = new BackButtonBehavior();
5050
Entry _commandParameter;
51-
Label _commandResult = new Label() { AutomationId = CommandResultId };
51+
Label _commandResult = new Label()
52+
{
53+
AutomationId = CommandResultId,
54+
BackgroundColor = Color.LightBlue,
55+
Text = "Label"
56+
};
5257

5358
public BackButtonPage()
5459
{
@@ -224,13 +229,28 @@ public void CommandTest()
224229
RunningApp.EnterText(EntryCommandParameter, "parameter");
225230
ShowFlyout();
226231

227-
var commandResult = RunningApp.WaitForElement(CommandResultId)[0].ReadText();
232+
// API 19 workaround
233+
var commandResult = RunningApp.QueryUntilPresent(() =>
234+
{
235+
ShowFlyout();
236+
if (RunningApp.WaitForElement(CommandResultId)[0].ReadText() == "parameter")
237+
return RunningApp.WaitForElement(CommandResultId);
238+
239+
return null;
240+
})?.FirstOrDefault()?.ReadText();
228241

229242
Assert.AreEqual("parameter", commandResult);
230243
RunningApp.EnterText(EntryCommandParameter, "canexecutetest");
231244
RunningApp.Tap(ToggleCommandCanExecuteId);
232245

233-
commandResult = RunningApp.WaitForElement(CommandResultId)[0].ReadText();
246+
commandResult = RunningApp.QueryUntilPresent(() =>
247+
{
248+
if (RunningApp.WaitForElement(CommandResultId)[0].ReadText() == "parameter")
249+
return RunningApp.WaitForElement(CommandResultId);
250+
251+
return null;
252+
})?.FirstOrDefault()?.ReadText();
253+
234254
Assert.AreEqual("parameter", commandResult);
235255
}
236256

@@ -241,13 +261,22 @@ public void CommandWorksWhenItsTheOnlyThingSet()
241261
RunningApp.Tap(ToggleCommandId);
242262
RunningApp.EnterText(EntryCommandParameter, "parameter");
243263

264+
// API 19 workaround
265+
var commandResult = RunningApp.QueryUntilPresent(() =>
266+
{
267+
244268
#if __ANDROID__
245-
base.TapBackArrow();
269+
TapBackArrow();
246270
#else
247-
RunningApp.Tap("Page 0");
271+
RunningApp.Tap("Page 0");
248272
#endif
249273

250-
var commandResult = RunningApp.WaitForElement(CommandResultId)[0].ReadText();
274+
if (RunningApp.WaitForElement(CommandResultId)[0].ReadText() == "parameter")
275+
return RunningApp.WaitForElement(CommandResultId);
276+
277+
return null;
278+
})?.FirstOrDefault()?.ReadText();
279+
251280
Assert.AreEqual(commandResult, "parameter");
252281
}
253282

0 commit comments

Comments
 (0)