-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#23 Migrate private UI Tests to public Uno
Elevation
- Loading branch information
1 parent
7477221
commit 24abb33
Showing
2 changed files
with
85 additions
and
14 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/SamplesApp/SamplesApp.UITests/Toolkit/UnoSamples_Tests.Elevation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Uno.UITest.Helpers; | ||
using Uno.UITest.Helpers.Queries; | ||
|
||
namespace SamplesApp.UITests.Toolkit | ||
{ | ||
|
||
[TestFixture] | ||
partial class UnoSamples_Tests : SampleControlUITestBase | ||
{ | ||
|
||
[Test] | ||
public void Elevation_Validation() | ||
{ | ||
Run("UITests.Shared.Toolkit.Elevation"); | ||
|
||
_app.WaitForElement(_app.Marked("TurnElevation_ON_Button")); | ||
|
||
var turnElevation_ON_Button = _app.Marked("TurnElevation_ON_Button"); | ||
|
||
// You can enter a different path to save the screenshots locally.E.g. @"C:\Users\{YourName}\source\repos"; | ||
System.Environment.CurrentDirectory = System.IO.Path.GetTempPath(); | ||
|
||
// Take ScreenShot with no elevation | ||
var screenshot_NoElevation = _app.Screenshot("Elevation - No Elevation"); | ||
|
||
turnElevation_ON_Button.Tap(); | ||
|
||
// Take ScreenShot of with elevation | ||
var screenshot_WithElevation = _app.Screenshot("Elevation - With Elevation"); | ||
|
||
Bitmap img1 = new Bitmap(screenshot_NoElevation.ToString()); | ||
Bitmap img2 = new Bitmap(screenshot_WithElevation.ToString()); | ||
|
||
float diffPercentage = 0; | ||
float diff = 0; | ||
|
||
if (img1.Size != img2.Size) | ||
{ | ||
throw new Exception("Images are of different sizes"); | ||
} | ||
else | ||
{ | ||
for (int x = 0; x < img1.Width; x++) | ||
{ | ||
for (int y = 0; y < img1.Height; y++) | ||
{ | ||
Color img1P = img1.GetPixel(x, y); | ||
Color img2P = img2.GetPixel(x, y); | ||
|
||
diff += Math.Abs(img1P.R - img2P.R); | ||
diff += Math.Abs(img1P.G - img2P.G); | ||
diff += Math.Abs(img1P.B - img2P.B); | ||
} | ||
} | ||
|
||
diffPercentage = 100 * (diff / 255) / (img1.Width * img1.Height * 3); | ||
if (diffPercentage < 0.5) | ||
{ | ||
Assert.Fail("Images are the same"); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters