summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.iOS.UITests/Tests/Legacy-CellsUITests.cs
blob: 4710c336eb72df0a02f11ddf0d65a7b4416c86cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
´╗┐using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;

using Xamarin.Forms.CustomAttributes;
using Xamarin.UITest;
using Xamarin.UITest.Android;
using Xamarin.UITest.Queries;

namespace Xamarin.Forms.Core.UITests
{
	[TestFixture]
	[Category("Cells")]
	internal class CellsGalleryTests : BaseTestFixture
	{
		// TODO find a way to test individula elements of cells
		// TODO port to new framework

		protected override void NavigateToGallery()
		{
			App.NavigateToGallery(GalleryQueries.CellsGalleryLegacy);
		}

		[Test]
		[Description("ListView with TextCells, all are present")]
		[UiTest(typeof(ListView))]
		[UiTest(typeof(TextCell))]
		public void CellsGalleryTextCellList()
		{
			App.ScrollForElement("* marked:'TextCell List'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));
			App.Tap(q => q.Marked("TextCell List"));
			App.WaitForElement(q => q.Marked("Text 0"), "Timeout : Text 0");

			App.Screenshot("At TextCell List Gallery");

			App.ScrollForElement("* marked:'Detail 99'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.WaitForElement(q => q.Marked("Detail 99"), "Timeout : Detail 99");

			App.Screenshot("All TextCells are present");
		}

		[Test]
		[Description("TableView with TextCells, all are present")]
		[UiTest(typeof(TableView))]
		[UiTest(typeof(TextCell))]
		public void CellsGalleryTextCellTable()
		{
			App.ScrollForElement("* marked:'TextCell Table'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Tap(q => q.Marked("TextCell Table"));
			App.WaitForElement(q => q.Marked("Text 1"), "Timeout : Text 1");

			App.Screenshot("At TextCell Table Gallery");

			App.ScrollForElement("* marked:'Detail 12'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.WaitForElement(q => q.Marked("Detail 12"), "Timeout : Detail 12");

			App.Screenshot("All TextCells are present");
		}

		[Test]
		[Description("ListView with ImageCells, all are present")]
		[UiTest(typeof(ListView))]
		[UiTest(typeof(ImageCell))]
		public void CellsGalleryImageCellList()
		{
			Thread.Sleep(2000);

			App.ScrollForElement("* marked:'ImageCell List'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			Thread.Sleep(2000);

			App.Tap(q => q.Marked("ImageCell List"));
			App.WaitForElement(q => q.Marked("Text 0"), "Timeout : Text 0");

			App.Screenshot("At ImageCell List Gallery");

			var scollBounds = App.Query(q => q.Marked("ImageCellListView")).First().Rect;
			App.ScrollForElement("* marked:'Detail 99'", new Drag(scollBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.WaitForElement(q => q.Marked("Detail 99"), "Timeout : Detail 99");

			App.Screenshot("All ImageCells are present");

			var numberOfImages = App.Query(q => q.Raw(PlatformViews.Image)).Length;
			// Check that there are images present. In Android, 
			// have to make sure that there are more than 2 for navigation.
			Assert.IsTrue(numberOfImages > 2);

			App.Screenshot("Images are present");
		}

		[Test]
		[Description("ListView with ImageCells, file access problems")]
		[UiTest(typeof(ListView))]
		[UiTest(typeof(ImageCell))]
		public async Task CellsGalleryImageUrlCellList()
		{

			App.ScrollForElement("* marked:'ImageCell Url List'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Tap(q => q.Marked("ImageCell Url List"));

			//var scollBounds = App.Query(q => q.Marked("ImageUrlCellListView")).First().Rect;
			//App.ScrollForElement("* marked:'Detail 200'", new Drag(scollBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));
			//App.ScrollUp();
			//App.WaitForElement(q => q.Marked("Detail 200"), "Timeout : Detail 200");

			App.Screenshot("All ImageCells are present");

			await Task.Delay(1000);
			var numberOfImages = App.Query(q => q.Raw(PlatformViews.Image)).Length;
			// Check that there are images present. In Android, 
			// have to make sure that there are more than 2 for navigation.
			Assert.IsTrue(numberOfImages > 2);

			App.Screenshot("Images are present");
		}




		[Test]
		[Description("TableView with ImageCells, all are present")]
		[UiTest(typeof(TableView))]
		[UiTest(typeof(ImageCell))]
		public void CellsGalleryImageCellTable()
		{
			App.ScrollForElement("* marked:'ImageCell Table'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Tap(q => q.Marked("ImageCell Table"));
			App.WaitForElement(q => q.Marked("Text 1"), "Timeout : Text 1");

			App.Screenshot("At ImageCell Table Gallery");

			App.ScrollForElement("* marked:'Detail 12'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.WaitForElement(q => q.Marked("Detail 12"), "Timeout : Detail 12");

			App.Screenshot("All ImageCells are present");

			var numberOfImages = App.Query(q => q.Raw(PlatformViews.Image)).Length;
			// Check that there are images present. In Android, 
			// have to make sure that there are more than 2 for navigation.
			Assert.IsTrue(numberOfImages > 2);

			App.Screenshot("Images are present");
		}

		[Test]
		[Description("ListView with SwitchCells, all are present")]
		[UiTest(typeof(ListView))]
		[UiTest(typeof(SwitchCell))]
		public void CellsGallerySwitchCellList()
		{
			App.ScrollForElement("* marked:'SwitchCell List'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Tap(q => q.Marked("SwitchCell List"));
			App.WaitForElement(q => q.Marked("Label 0"), "Timeout : Label 0");

			App.Screenshot("At SwitchCell List Gallery");

			App.ScrollForElement("* marked:'Label 99'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			var numberOfSwitches = App.Query(q => q.Raw(PlatformViews.Switch)).Length;
			Assert.IsTrue(numberOfSwitches > 2);

			App.Screenshot("Switches are present");
		}

		[Test]
		[Description("TableView with SwitchCells, all are present")]
		[UiTest(typeof(TableView))]
		[UiTest(typeof(SwitchCell))]
		public void CellsGallerySwitchCellTable()
		{
			App.ScrollForElement("* marked:'SwitchCell Table'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Tap(q => q.Marked("SwitchCell Table"));
			App.WaitForElement(q => q.Marked("text 1"), "Timeout : text 1");

			App.Screenshot("At SwitchCell Table Gallery");

			App.ScrollForElement("* marked:'text 32'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			var numberOfSwitches = App.Query(q => q.Raw(PlatformViews.Switch)).Length;
			Assert.IsTrue(numberOfSwitches > 2);

			App.Screenshot("Switches are present");
		}

		[Test]
		[Description("ListView with EntryCells, all are present")]
		[UiTest(typeof(ListView))]
		[UiTest(typeof(EntryCell))]
		public void CellsGalleryEntryCellList()
		{
			App.ScrollForElement("* marked:'EntryCell List'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Tap(q => q.Marked("EntryCell List"));
			App.WaitForElement(q => q.Marked("Label 0"), "Timeout : Label 0");

			App.Screenshot("At EntryCell List Gallery");

			App.ScrollForElement("* marked:'Label 99'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Screenshot("All EntryCells are present");
		}

		[Test]
		[Description("TableView with EntryCells, all are present")]
		[UiTest(typeof(TableView))]
		[UiTest(typeof(EntryCell))]
		public void CellsGalleryEntryCellTable()
		{
			App.ScrollForElement("* marked:'EntryCell Table'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Tap(q => q.Marked("EntryCell Table"));
			App.WaitForElement(q => q.Marked("Text 2"), "Timeout : Text 2");

			App.Screenshot("At EntryCell Table Gallery");

			App.ScrollForElement("* marked:'Text 32'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Screenshot("All EntryCells are present");
		}

		[Test]
		[Category("EntryCell")]
		[Description("EntryCell fires .Completed event")]
		[UiTest(typeof(EntryCell), "Completed")]
		public void CellsGalleryEntryCellCompleted()
		{
			App.ScrollForElement("* marked:'EntryCell Table'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Tap(q => q.Marked("EntryCell Table"));
			App.WaitForElement(q => q.Marked("Text 2"), "Timeout : Text 2");

			App.Screenshot("At EntryCell Table Gallery");
			App.ScrollForElement("* marked:'Enter text'", new Drag(ScreenBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium));

			App.Screenshot("Before clicking Entry");

#if !__IOS__
			App.Tap(PlatformQueries.EntryCellWithPlaceholder("I am a placeholder"));
			App.EnterText(PlatformQueries.EntryCellWithPlaceholder("I am a placeholder"), "Hi");
			App.Screenshot("Entered Text");
			App.PressEnter();

			App.WaitForElement(q => q.Marked("Entered: 1"));
			App.Screenshot("Completed should have changed label's text");
			
#endif
		}

		protected override void TestTearDown()
		{
			App.NavigateBack();
			base.TestTearDown();
		}
	}
}