-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenshots.cs
More file actions
41 lines (34 loc) · 1.7 KB
/
Screenshots.cs
File metadata and controls
41 lines (34 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Drawing.Imaging;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
public static class Screenshots {
public static void TakeScreenShot(IWebDriver webDriver, string screenShotFileNameWithoutExtension, ImageFormat imageFormat, string screenShotDirectoryPath) {
Screenshot screenShot = null;
var browserName = string.Empty;
if (webDriver.GetType() == typeof(InternetExplorerDriver)) {
screenShot = ((InternetExplorerDriver)webDriver).GetScreenshot();
browserName = "IE";
}
if (webDriver.GetType() == typeof(FirefoxDriver)) {
screenShot = ((FirefoxDriver)webDriver).GetScreenshot();
browserName = "Firefox";
}
if (webDriver.GetType() == typeof(ChromeDriver)) {
screenShot = ((ChromeDriver)webDriver).GetScreenshot();
browserName = "Chrome";
}
var screenShotFileName = screenShotFileNameWithoutExtension + "." + imageFormat.ToString().ToLower();
if (screenShot != null) {
if (!string.IsNullOrEmpty(screenShotDirectoryPath)) {
Directory.CreateDirectory(screenShotDirectoryPath).CreateSubdirectory(browserName);
var browserScreenShotDirectoryPath = Path.Combine(screenShotDirectoryPath, browserName);
Directory.CreateDirectory(browserScreenShotDirectoryPath);
var screenShotFileFullPath = Path.Combine(browserScreenShotDirectoryPath, screenShotFileName);
screenShot.SaveAsFile(screenShotFileFullPath, imageFormat);
}
}
}
}