示例#1
0
        public static byte[] TakeScreenshot(
            this IWebElement element,
            IWebDriver driver,
            IConfigurationProvider configuration)
        {
            var pageSize                = driver.PageSize();
            var browserSize             = driver.ViewPort();
            var screenshotConfiguration = configuration.Get(ScreenshotTakerConfiguration.Default);

            byte[] imageBytes;

            if (pageSize.Width < browserSize.Width && pageSize.Height < browserSize.Height)
            {
                imageBytes = ((ITakesScreenshot)driver).GetScreenshot().AsByteArray;
            }
            else
            {
                using (var screenshotTaker = new ScreenshotTaker(driver, screenshotConfiguration))
                    imageBytes = screenshotTaker.TakeImage();
            }

            var elementArea = element.Area();

            elementArea.Inflate(screenshotConfiguration.Margin, screenshotConfiguration.Margin);
            return(imageBytes.Crop(elementArea));
        }