Skip to content

Commit beda796

Browse files
committed
Use different method to take screenshot in tests
1 parent 5d7bc31 commit beda796

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

test/SystemTests.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using OpenQA.Selenium;
33
using OpenQA.Selenium.Appium;
44
using OpenQA.Selenium.Appium.Windows;
5+
using System.Drawing;
56
using System.Windows.Automation;
67

78
namespace WinDynamicDesktop.Tests
@@ -54,11 +55,7 @@ public void ShouldUpdateWallpaper()
5455
}
5556
catch (WebDriverException)
5657
{
57-
try
58-
{
59-
driver.GetScreenshot().SaveAsFile(Path.Combine(Path.GetDirectoryName(AppPath), "screenshot.png"));
60-
}
61-
catch { /* Do nothing */ }
58+
TakeScreenshot(Path.Combine(Path.GetDirectoryName(AppPath), "screenshot.png"));
6259
throw;
6360
}
6461
}
@@ -89,5 +86,18 @@ private bool HandleLocationPrompt()
8986
return key?.GetValue("WallPaper") as string;
9087
}
9188
}
89+
90+
private void TakeScreenshot(string filePath)
91+
{
92+
Rectangle bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
93+
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
94+
{
95+
using (Graphics g = Graphics.FromImage(bitmap))
96+
{
97+
g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size);
98+
}
99+
bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
100+
}
101+
}
92102
}
93103
}

0 commit comments

Comments
 (0)