Skip to content

Commit

Permalink
Use different method to take screenshot in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Jan 14, 2025
1 parent 5d7bc31 commit beda796
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/SystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System.Drawing;
using System.Windows.Automation;

namespace WinDynamicDesktop.Tests
Expand Down Expand Up @@ -54,11 +55,7 @@ public void ShouldUpdateWallpaper()
}
catch (WebDriverException)
{
try
{
driver.GetScreenshot().SaveAsFile(Path.Combine(Path.GetDirectoryName(AppPath), "screenshot.png"));
}
catch { /* Do nothing */ }
TakeScreenshot(Path.Combine(Path.GetDirectoryName(AppPath), "screenshot.png"));
throw;
}
}
Expand Down Expand Up @@ -89,5 +86,18 @@ private bool HandleLocationPrompt()
return key?.GetValue("WallPaper") as string;
}
}

private void TakeScreenshot(string filePath)
{
Rectangle bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size);
}
bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
}

0 comments on commit beda796

Please sign in to comment.