public void TestTakeScreenshotWhenNotSupportedDoesNothing() { var driver = new Mock <IWebDriver>(MockBehavior.Strict); var logger = new Mock <ILogger>(MockBehavior.Loose); var browser = new SeleniumBrowser(new Lazy <IWebDriver>(() => driver.Object), logger.Object); var fullPath = browser.TakeScreenshot(@"C:\somepath", "fileBase"); Assert.IsNull(fullPath); driver.VerifyAll(); }
public void TestTakeScreenshotWhenScreenshotErrorsReturnsNothing() { var driver = new Mock <IWebDriver>(MockBehavior.Strict); driver.As <ITakesScreenshot>().Setup(s => s.GetScreenshot()).Throws <InvalidOperationException>(); var logger = new Mock <ILogger>(MockBehavior.Loose); var browser = new SeleniumBrowser(new Lazy <IWebDriver>(() => driver.Object), logger.Object); var fullPath = browser.TakeScreenshot(@"C:\somepath", "fileBase"); Assert.IsNull(fullPath); driver.VerifyAll(); }
public void TestTakeScreenshotWhenCalledWithoutErrorTakesScreenshot() { var driver = new Mock <IWebDriver>(MockBehavior.Strict); driver.As <ITakesScreenshot>().Setup(s => s.GetScreenshot()).Throws <InvalidOperationException>(); var basePath = Path.GetTempPath(); var fileName = Guid.NewGuid().ToString(); Screenshot screenshot; using (var ms = new MemoryStream()) { var image = TestResource.TestImage; image.Save(ms, ImageFormat.Jpeg); screenshot = new Screenshot(Convert.ToBase64String(ms.ToArray())); } var screenShot = driver.As <ITakesScreenshot>(); screenShot.Setup(s => s.GetScreenshot()).Returns(screenshot); var logger = new Mock <ILogger>(MockBehavior.Loose); var browser = new SeleniumBrowser(new Lazy <IWebDriver>(() => driver.Object), logger.Object); string fullPath = null; try { fullPath = browser.TakeScreenshot(basePath, fileName); } finally { if (fullPath != null && File.Exists(fullPath)) { File.Delete(fullPath); } } Assert.IsNotNull(fullPath); driver.VerifyAll(); }
public void TestTakeScreenshotWhenCalledWithoutErrorTakesScreenshot() { var driver = new Mock<IWebDriver>(MockBehavior.Strict); driver.As<ITakesScreenshot>().Setup(s => s.GetScreenshot()).Throws<InvalidOperationException>(); var basePath = Path.GetTempPath(); var fileName = Guid.NewGuid().ToString(); Screenshot screenshot; using (var ms = new MemoryStream()) { var image = TestResource.TestImage; image.Save(ms, ImageFormat.Jpeg); screenshot = new Screenshot(Convert.ToBase64String(ms.ToArray())); } var screenShot = driver.As<ITakesScreenshot>(); screenShot.Setup(s => s.GetScreenshot()).Returns(screenshot); var logger = new Mock<ILogger>(MockBehavior.Loose); var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object); string fullPath = null; try { fullPath = browser.TakeScreenshot(basePath, fileName); } finally { if (fullPath != null && File.Exists(fullPath)) { File.Delete(fullPath); } } Assert.IsNotNull(fullPath); driver.VerifyAll(); }
public void TestTakeScreenshotWhenScreenshotErrorsReturnsNothing() { var driver = new Mock<IWebDriver>(MockBehavior.Strict); driver.As<ITakesScreenshot>().Setup(s => s.GetScreenshot()).Throws<InvalidOperationException>(); var logger = new Mock<ILogger>(MockBehavior.Loose); var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object); var fullPath = browser.TakeScreenshot(@"C:\somepath", "fileBase"); Assert.IsNull(fullPath); driver.VerifyAll(); }
public void TestTakeScreenshotWhenNotSupportedDoesNothing() { var driver = new Mock<IWebDriver>(MockBehavior.Strict); var logger = new Mock<ILogger>(MockBehavior.Loose); var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object); var fullPath = browser.TakeScreenshot(@"C:\somepath", "fileBase"); Assert.IsNull(fullPath); driver.VerifyAll(); }