Skip to content

Commit 4234ba9

Browse files
committed
Reorganization and comments in Toolkit.UITests.Shared
1 parent caba8c3 commit 4234ba9

5 files changed

Lines changed: 58 additions & 43 deletions

File tree

src/Tests/UITests/Toolkit.UITests.Shared/Appium/AppiumTestBase.CrashHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public abstract partial class AppiumTestBase
66
{
77
private static bool HasAppCrashed = false;
88

9+
/// <summary>
10+
/// Tests running after a the App has crashed should immediately return inconclusive to avoid wasting time,
11+
/// and because it cannot be determined whether they would pass otherwise.
12+
/// </summary>
913
[TestInitialize]
1014
public void FailFastIfAppAlreadyCrashed()
1115
{
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using OpenQA.Selenium.Appium;
2+
using ImageMagick;
3+
4+
namespace Toolkit.UITest.Shared;
5+
6+
public abstract partial class AppiumTestBase
7+
{
8+
/// <summary>
9+
/// Takes a screenshot of the parameter element.
10+
/// </summary>
11+
/// <remarks>
12+
/// Appium screenshots work on the entire screen, not just a single element, or even a single window. This means elements
13+
/// may be partially or wholly blocked if covered by another element or window. Blue light filters will also affect color
14+
/// comparisons because of this.
15+
/// </remarks>
16+
protected MagickImage GetScreenshot(AppiumElement element)
17+
{
18+
var screenshot = element.GetScreenshot();
19+
return new MagickImage(screenshot.AsByteArray);
20+
}
21+
22+
/// <summary>
23+
/// Normalizes pixel values based on platform and device DPI. Normalized values are approximately equivalent to what renders
24+
/// on Windows at a screen density of 1 (96 DPI).
25+
/// </summary>
26+
protected double GetNormalizedPixelValue(int pixels)
27+
{
28+
#if WINDOWS_TEST || ANDROID_TEST
29+
return pixels / ScreenDensity;
30+
#elif IOS_TEST || MAC_TEST
31+
// XCUI tests already returns points rather than pixels
32+
return pixels;
33+
#else
34+
throw new NotImplementedException("GetNormalizedPixelValue(int) is not implemented for this platform.");
35+
#endif
36+
}
37+
38+
/// <summary>
39+
/// Returns the value corresponding to the target platform of the test runner.
40+
/// </summary>
41+
protected int PlatformSpecificPixelValue(int windows, int android, int ios, int mac)
42+
{
43+
#if WINDOWS_TEST
44+
return windows;
45+
#elif ANDROID_TEST
46+
return android;
47+
#elif IOS_TEST
48+
return ios;
49+
#elif MAC_TEST
50+
return mac;
51+
#endif
52+
}
53+
}

src/Tests/UITests/Toolkit.UITests.Shared/Appium/AppiumTestBase.Screenshots.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Tests/UITests/Toolkit.UITests.Shared/Appium/AppiumTestBase.Utils.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,4 @@ protected string GetElementText(AppiumElement element, TimeSpan? timeout = null)
118118
throw;
119119
}
120120
}
121-
122-
/// <summary>
123-
/// Normalizes pixel values based on platform and device DPI. Normalized values are approximately equivalent to what renders
124-
/// on Windows at a screen density of 1 (96 DPI).
125-
/// </summary>
126-
protected double GetNormalizedPixelValue(int pixels)
127-
{
128-
#if WINDOWS_TEST || ANDROID_TEST
129-
return pixels / ScreenDensity;
130-
#elif IOS_TEST || MAC_TEST
131-
// XCUI tests already returns points rather than pixels
132-
return pixels;
133-
#else
134-
throw new NotImplementedException("GetNormalizedPixelValue(int) is not implemented for this platform.");
135-
#endif
136-
}
137-
138-
protected int PlatformSpecificPixelValue(int windows, int android, int ios, int mac)
139-
{
140-
#if WINDOWS_TEST
141-
return windows;
142-
#elif ANDROID_TEST
143-
return android;
144-
#elif IOS_TEST
145-
return ios;
146-
#elif MAC_TEST
147-
return mac;
148-
#endif
149-
}
150121
}

src/Tests/UITests/Toolkit.UITests.Shared/Toolkit.UITests.Shared.projitems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Compile Include="$(MSBuildThisFileDirectory)AppiumTestBase.cs" />
1414
<Compile Include="$(MSBuildThisFileDirectory)Appium\AppiumTestBase.CrashHandler.cs" />
1515
<Compile Include="$(MSBuildThisFileDirectory)Appium\AppiumTestBase.Gestures.cs" />
16-
<Compile Include="$(MSBuildThisFileDirectory)Appium\AppiumTestBase.Screenshots.cs" />
16+
<Compile Include="$(MSBuildThisFileDirectory)Appium\AppiumTestBase.ImageAnalysis.cs" />
1717
<Compile Include="$(MSBuildThisFileDirectory)Appium\AppiumTestBase.Utils.cs" />
1818
<Compile Include="$(MSBuildThisFileDirectory)Tests\Compass\CompassTests.cs" />
1919
<Compile Include="$(MSBuildThisFileDirectory)Tests\ScaleLine\ScaleLineTests.cs" />

0 commit comments

Comments
 (0)