コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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();
        }