public void CaptureScreenshotNoExistingDirectory() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); string screenShotPath = SeleniumUtilities.CaptureScreenshot(WebDriver, TestObject, "TempTestDirectory", "CapScreenShotNoDir", SeleniumUtilities.GetScreenShotFormat()); Assert.IsTrue(File.Exists(screenShotPath), "Fail to find screenshot"); File.Delete(screenShotPath); }
public void CaptureScreenshotTiffFormat() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); string screenShotPath = SeleniumUtilities.CaptureScreenshot(WebDriver, TestObject, "TempTestDirectory", "TempTestFilePath", ScreenshotImageFormat.Tiff); Assert.IsTrue(File.Exists(screenShotPath), "Fail to find screenshot"); Assert.AreEqual(".Tiff", Path.GetExtension(screenShotPath), "The screenshot format was not in '.Tiff' format"); File.Delete(screenShotPath); }
public void TryScreenshot() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); SeleniumUtilities.CaptureScreenshot(this.WebDriver, this.TestObject); string filePath = Path.ChangeExtension(((IFileLogger)TestObject.Log).FilePath, ".Png"); Assert.IsTrue(File.Exists(filePath), "Fail to find screenshot"); File.Delete(filePath); }
public void CapturedScreenshotTestObjectAssociation() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); string pagePicPath = SeleniumUtilities.CaptureScreenshot(WebDriver, TestObject, "TempTestDirectory", "TestObjAssocTest"); Assert.IsTrue(TestObject.ContainsAssociatedFile(pagePicPath), "The captured screenshot wasn't added to the associated files"); File.Delete(pagePicPath); }
public void CaptureScreenshotNoExistingDirectoryDeprecated() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); #pragma warning disable CS0618 // Type or member is obsolete string screenShotPath = SeleniumUtilities.CaptureScreenshot(WebDriver, "TempTestDirectory", "OldCapScreenShotNoDir", SeleniumUtilities.GetScreenShotFormat()); #pragma warning restore CS0618 // Type or member is obsolete Assert.IsTrue(File.Exists(screenShotPath), "Fail to find screenshot"); File.Delete(screenShotPath); }
public void TryScreenshotImageFormat() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); SeleniumUtilities.CaptureScreenshot(this.WebDriver, this.TestObject); string filePath = Path.ChangeExtension(((IFileLogger)this.Log).FilePath, SeleniumUtilities.GetScreenShotFormat().ToString()); Assert.IsTrue(File.Exists(filePath), "Fail to find screenshot"); Assert.AreEqual(Path.GetExtension(filePath), "." + SeleniumUtilities.GetScreenShotFormat().ToString(), "The screenshot format was not in correct Format"); File.Delete(filePath); }
public void TryScreenshotDeprecated() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); #pragma warning disable CS0618 // Type or member is obsolete SeleniumUtilities.CaptureScreenshot(this.WebDriver, this.Log); #pragma warning restore CS0618 // Type or member is obsolete string filePath = Path.ChangeExtension(((FileLogger)this.Log).FilePath, ".Jpeg"); Assert.IsTrue(File.Exists(filePath), "Fail to find screenshot"); File.Delete(filePath); }
public void TryScreenshotWithHTMLFileLogger() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); // Create a console logger and calculate the file location HtmlFileLogger htmlFileLogger = new HtmlFileLogger(LoggingConfig.GetLogDirectory()); TestObject.Log = htmlFileLogger; // Take a screenshot SeleniumUtilities.CaptureScreenshot(this.WebDriver, this.TestObject, "Delete"); Stream fileStream = null; string logContents = string.Empty; // This will open the Log file and read in the text try { fileStream = new FileStream(htmlFileLogger.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using (StreamReader textReader = new StreamReader(fileStream)) { fileStream = null; logContents = textReader.ReadToEnd(); } } finally { if (fileStream != null) { fileStream.Dispose(); } } // Find the base64 encoded string Regex pattern = new Regex("src='data:image/png;base64, (?<image>[^']+)'"); var matches = pattern.Match(logContents); // Try to convert the Base 64 string to find if it is a valid string try { Convert.FromBase64String(matches.Groups["image"].Value); } catch (FormatException) { Assert.Fail("image saves was not a Base64 string"); } finally { File.Delete(htmlFileLogger.FilePath); } }
public void CaptureScreenshotThrownException() { FileLogger tempLogger = new FileLogger { FilePath = "<>\0" // illegal file path }; TestObject.Log = tempLogger; WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); bool successfullyCaptured = SeleniumUtilities.CaptureScreenshot(WebDriver, TestObject); Assert.IsFalse(successfullyCaptured); }
public void CaptureScreenshotThrownExceptionDeprecated() { FileLogger tempLogger = new FileLogger { FilePath = "<>" // illegal file path }; WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); #pragma warning disable CS0618 // Type or member is obsolete bool successfullyCaptured = SeleniumUtilities.CaptureScreenshot(WebDriver, tempLogger); #pragma warning restore CS0618 // Type or member is obsolete Assert.IsFalse(successfullyCaptured); }
public void TryScreenshotWithConsoleLogger() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); // Create a console logger and calculate the file location ConsoleLogger consoleLogger = new ConsoleLogger(); TestObject.Log = consoleLogger; string expectedPath = Path.Combine(LoggingConfig.GetLogDirectory(), "ScreenCapDelete.Png"); // Take a screenshot SeleniumUtilities.CaptureScreenshot(this.WebDriver, this.TestObject, "Delete"); // Make sure we got the screenshot and than cleanup Assert.IsTrue(File.Exists(expectedPath), $"Fail to find screenshot at {expectedPath}"); File.Delete(expectedPath); }
public void TryScreenshotWithConsoleLoggerDeprecated() { WebDriver.Navigate().GoToUrl(TestSiteUrl); WebDriver.Wait().ForPageLoad(); // Create a console logger and calculate the file location ConsoleLogger consoleLogger = new ConsoleLogger(); string expectedPath = Path.Combine(LoggingConfig.GetLogDirectory(), "ScreenCapDelete.Jpeg"); // Take a screenshot #pragma warning disable CS0618 // Type or member is obsolete SeleniumUtilities.CaptureScreenshot(this.WebDriver, consoleLogger, "Delete"); #pragma warning restore CS0618 // Type or member is obsolete // Make sure we got the screenshot and than cleanup Assert.IsTrue(File.Exists(expectedPath), "Fail to find screenshot"); File.Delete(expectedPath); }