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

Commit 68f19a7

Browse files
authored
Apply internet check to additional tests (#12804)
1 parent 91b883e commit 68f19a7

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Helpers/UITestHelper.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Xamarin.UITest;
77
using NUnit.Framework;
88
using Xamarin.UITest.Queries;
9+
using System.Linq;
10+
using Xamarin.Forms.Core.UITests;
911

1012
namespace Xamarin.Forms.Controls.Issues
1113
{
@@ -35,6 +37,39 @@ public static void AssertHasText(this AppResult result, string text)
3537

3638
Assert.Fail();
3739
}
40+
41+
public static string[] GetTestCategories(Type testType)
42+
{
43+
var testClassName = TestContext.CurrentContext.Test.ClassName;
44+
45+
// TestContext.CurrentContext.Test.Properties["Category"]
46+
// Only gives you the categories on the test itself
47+
// There isn't a property I could find that gives you the Categories
48+
// on the Test Class
49+
return testType
50+
.Assembly
51+
.GetType(testClassName)
52+
.GetCustomAttributes(typeof(NUnit.Framework.CategoryAttribute), true)
53+
.OfType<NUnit.Framework.CategoryAttribute>()
54+
.Select(x => x.Name)
55+
.Union(TestContext.CurrentContext.Test.Properties["Category"].OfType<string>())
56+
.ToArray();
57+
}
58+
59+
public static void MarkTestInconclusiveIfNoInternetConnectionIsPresent(Type testType, IApp app)
60+
{
61+
if (GetTestCategories(testType).Contains(UITestCategories.RequiresInternetConnection))
62+
{
63+
var hasInternetAccess = $"{app.Invoke("hasInternetAccess")}";
64+
bool checkInternet;
65+
66+
if (bool.TryParse(hasInternetAccess, out checkInternet))
67+
{
68+
if (!checkInternet)
69+
Assert.Inconclusive("Device Has No Internet Connection");
70+
}
71+
}
72+
}
3873
}
3974
}
4075

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/ScreenshotConditionalApp.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using NUnit.Framework;
77
using NUnit.Framework.Interfaces;
8+
using Xamarin.Forms.Controls.Issues;
89
using Xamarin.Forms.Core.UITests;
910
using Xamarin.UITest;
1011
using Xamarin.UITest.Queries;
@@ -473,37 +474,10 @@ public void Restart()
473474
}
474475
#endif
475476

476-
string[] GetTestCategories()
477-
{
478-
var testClassName = TestContext.CurrentContext.Test.ClassName;
479-
480-
// TestContext.CurrentContext.Test.Properties["Category"]
481-
// Only gives you the categories on the test itself
482-
// There isn't a property I could find that gives you the Categories
483-
// on the Test Class
484-
return GetType()
485-
.Assembly
486-
.GetType(testClassName)
487-
.GetCustomAttributes(typeof(NUnit.Framework.CategoryAttribute), true)
488-
.OfType<NUnit.Framework.CategoryAttribute>()
489-
.Select(x => x.Name)
490-
.Union(TestContext.CurrentContext.Test.Properties["Category"].OfType<string>())
491-
.ToArray();
492-
}
493-
494477
public void TestSetup(Type testType, bool isolate)
495478
{
496-
if (GetTestCategories().Contains(UITestCategories.RequiresInternetConnection))
497-
{
498-
var hasInternetAccess = $"{_app.Invoke("hasInternetAccess")}";
499-
bool checkInternet;
500479

501-
if (bool.TryParse(hasInternetAccess, out checkInternet))
502-
{
503-
if (!checkInternet)
504-
Assert.Inconclusive("Device Has No Internet Connection");
505-
}
506-
}
480+
UITestHelper.MarkTestInconclusiveIfNoInternetConnectionIsPresent(testType, _app);
507481

508482
#if __WINDOWS__
509483
RestartIfAppIsClosed();

Xamarin.Forms.Core.UITests.Shared/BaseTestFixture.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics;
33
using NUnit.Framework;
44
using Xamarin.Forms.Controls;
5+
using Xamarin.Forms.Controls.Issues;
56
using Xamarin.UITest;
67
using Xamarin.UITest.Queries;
78

@@ -46,6 +47,7 @@ public void EnsureMemory()
4647
protected virtual void TestSetup()
4748
{
4849
//EnsureMemory();
50+
UITestHelper.MarkTestInconclusiveIfNoInternetConnectionIsPresent(GetType(), App);
4951
}
5052

5153
[TearDown]

0 commit comments

Comments
 (0)