summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs
blob: c60ef35cd345d4a98bc33ff4f9e4f06013ae334e (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
´╗┐using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using NUnit.Framework;
using Xamarin.Forms.Controls;
using Xamarin.UITest;
using Xamarin.UITest.Queries;

namespace Xamarin.Forms.Core.UITests
{
	internal abstract class BaseTestFixture
	{
		// TODO: Landscape tests

	 	public static IApp App { get; private set; }
		public string PlatformViewType { get; protected set; }
		public bool ShouldResetPerFixture { get; protected set; }
		public AppRect ScreenBounds { get; private set; }

		protected BaseTestFixture ()
		{
			ShouldResetPerFixture = true;
		}

		protected abstract void NavigateToGallery ();

#pragma warning disable 618
		[TestFixtureSetUp]
#pragma warning restore 618
		protected virtual void FixtureSetup ()
		{
			try
			{
				if (ShouldResetPerFixture)
				{
					RelaunchApp();
				}
			}
			catch (Exception ex)
			{
				Debug.WriteLine(ex);
				throw;
			}
		}

#pragma warning disable 618
		[TestFixtureTearDown]
#pragma warning restore 618
		protected virtual void FixtureTeardown ()
		{	
		}

		[SetUp]
		protected virtual void TestSetup () 
		{
			if (!ShouldResetPerFixture) {
				RelaunchApp ();
			}
			App.Screenshot ("Begin Test");
		}

		[TearDown]
		protected virtual void TestTearDown ()
		{
			App.Screenshot ("Test complete");
		}

		void RelaunchApp ()
		{
			App = null;
			RunningApp.App = null;

			try {
				RunningApp.Restart ();
			} catch (Exception ex) {
				// if at first you dont succeed
				RunningApp.Restart ();
			}

			// Wrap the app in ScreenshotConditional so it only takes screenshots if the SCREENSHOTS symbol is specified
			App = new ScreenshotConditionalApp(RunningApp.App);

			App.SetOrientationPortrait ();
			ScreenBounds = App.RootViewRect ();
			NavigateToGallery ();
		}
	}
}