Skip to content

Commit

Permalink
Added MagickImage for comparing images
Browse files Browse the repository at this point in the history
  • Loading branch information
raczeja committed Jul 10, 2018
1 parent 89643b3 commit 35e9943
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLoca

var screenshotDriver = (ITakesScreenshot)driver;
var screenshot = screenshotDriver.GetScreenshot();
var filePath = Path.Combine(folder, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff", CultureInfo.CurrentCulture) + "temporary_fullscreen.jpeg");
var filePath = Path.Combine(folder, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff", CultureInfo.CurrentCulture) + "temporary_fullscreen.png");
Logger.Debug(CultureInfo.CurrentCulture, "Taking full screenshot {0}", filePath);
screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Jpeg);
screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png);

if (BaseConfiguration.TestBrowser == BrowserType.Chrome)
{
Expand All @@ -171,7 +171,7 @@ public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLoca
Bitmap cloneFile;
try
{
newFilePath = Path.Combine(folder, screenshotName + ".jpeg");
newFilePath = Path.Combine(folder, screenshotName + ".png");
cloneFile = (Bitmap)importFile.Clone(image, importFile.PixelFormat);
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ public IFramePage(DriverContext driverContext)
{
}

public void TakeScreenShotsOfTextInIFrame(string folder, string name)
public string TakeScreenShotsOfTextInIFrame(string folder, string name)
{
Logger.Info(CultureInfo.CurrentCulture, "Take Screen Shots");
var iFrame = this.Driver.GetElement(this.iframe);
int x = iFrame.Location.X;
int y = iFrame.Location.Y;
this.Driver.SwitchTo().Frame(0);
var el = this.Driver.GetElement(this.elelemtInIFrame);
TakeScreenShot.TakeScreenShotOfElement(x, y, el, folder, name);
return TakeScreenShot.TakeScreenShotOfElement(x, y, el, folder, name);
}

public void TakeScreenShotsOfMenu(string folder, string name)
public string TakeScreenShotsOfMenu(string folder, string name)
{
Logger.Info(CultureInfo.CurrentCulture, "Take Screen Shots");
var el = this.Driver.GetElement(this.menu);
TakeScreenShot.TakeScreenShotOfElement(el, folder, name);
return TakeScreenShot.TakeScreenShotOfElement(el, folder, name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Magick.NET-Q16-AnyCPU, Version=7.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">
<HintPath>..\packages\Magick.NET-Q16-AnyCPU.7.0.3.502\lib\net40-client\Magick.NET-Q16-AnyCPU.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.5\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
Expand All @@ -47,6 +50,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="WebDriver">
<HintPath>..\packages\Selenium.WebDriver.3.12.1\lib\net40\WebDriver.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -90,6 +94,11 @@
<Name>Objectivity.Test.Automation.Tests.PageObjects</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="TestOutput\TextWithinIFrameChromeError.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// SOFTWARE.
// </license>

using ImageMagick;
using NUnit.Framework;
using Objectivity.Test.Automation.Common;
using Objectivity.Test.Automation.Tests.NUnit;
Expand All @@ -39,7 +40,24 @@ public void TakingScreehShotsOfElementInIFrameTest()
internetPage.GoToIFramePage();

IFramePage page = new IFramePage(this.DriverContext);
page.TakeScreenShotsOfTextInIFrame(TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder, "TextWithinIFrame" + BaseConfiguration.TestBrowser);
var path = page.TakeScreenShotsOfTextInIFrame(TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder, "TextWithinIFrame" + BaseConfiguration.TestBrowser);
var path2 = TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder + "\\TextWithinIFrameChromeError.png";
bool flag = true;
using (var img1 = new MagickImage(path))
{
using (var img2 = new MagickImage(path2))
{
using (var imgDiff = new MagickImage())
{
img1.Compose = CompositeOperator.Src;
double diff = img1.Compare(img2, new ErrorMetric(), imgDiff);
flag = img1.Equals(img2);
imgDiff.Write(TestContext.CurrentContext.TestDirectory + BaseConfiguration.ScreenShotFolder + "\\TextWithinIFrameDIFF.png");
}
}
}

Assert.IsFalse(flag);
}

[Test]
Expand Down
3 changes: 2 additions & 1 deletion Objectivity.Test.Automation.UnitTests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<packages>
<package id="coveralls.net" version="0.7.0" targetFramework="net45" developmentDependency="true" />
<package id="EWSoftware.SHFB" version="2017.12.30.2" targetFramework="net45" />
<package id="OpenCover" version="4.6.519" targetFramework="net45" />
<package id="Magick.NET-Q16-AnyCPU" version="7.0.3.502" targetFramework="net452" />
<package id="NLog" version="4.3.5" targetFramework="net452" />
<package id="NUnit" version="3.10.1" targetFramework="net452" />
<package id="OpenCover" version="4.6.519" targetFramework="net45" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.38.0.1" targetFramework="net452" />
<package id="Selenium.WebDriver.GeckoDriver" version="0.20.1" targetFramework="net452" />
<package id="Selenium.WebDriver.IEDriver" version="3.12.0" targetFramework="net452" />
Expand Down
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ test_script:
7z a testresults_$env:appveyor_build_version.zip .\Objectivity.Test.Automation.UnitTests\bin\Release\**\*.png
7z a testresults_$env:appveyor_build_version.zip .\Objectivity.Test.Automation.UnitTests\bin\Release\**\*.jpeg
7z a testresults_$env:appveyor_build_version.zip .\Objectivity.Test.Automation.UnitTests\bin\Release\**\*.html
7z a testresults_$env:appveyor_build_version.zip .\Objectivity.Test.Automation.UnitTests\bin\Release\*.log
Expand Down

0 comments on commit 35e9943

Please sign in to comment.