Example #1
0
        /// <summary>Takes the screenshot of whole page</summary>
        /// <param name="driver">WebDriver instance</param>
        /// <returns>
        ///     Screenshot with whole page image and list of ignored areas on screenshot
        /// </returns>
        /// <seealso cref="AShotNet.Screenshot" />
        public virtual Screenshot TakeScreenshot(IWebDriver driver)
        {
            var screenshot = new Screenshot(this.taker.take(driver));

            screenshot.setIgnoredAreas(this.CompileIgnoredAreas(driver, CoordsPreparationStrategy.simple()));
            return(screenshot);
        }
Example #2
0
        /// <summary>
        ///     Takes the screenshot of given elements
        ///     If elements were not found screenshot of whole page will be returned
        /// </summary>
        /// <param name="driver">WebDriver instance</param>
        /// <returns>Screenshot with cropped image and list of ignored areas on screenshot</returns>
        /// <exception cref="System.Exception">when something goes wrong</exception>
        /// <seealso cref="AShotNet.Screenshot" />
        public virtual Screenshot TakeScreenshot(IWebDriver driver, ICollection <IWebElement> elements)
        {
            ICollection <Coords> elementCoords = this.coordsProvider.ofElements(driver, elements);
            Bitmap               shot          = this.taker.take(driver);
            Screenshot           screenshot    = this.cropper.crop(shot, elementCoords);
            ICollection <Coords> ignoredAreas  = this.CompileIgnoredAreas(driver, CoordsPreparationStrategy.intersectingWith(screenshot));

            screenshot.setIgnoredAreas(ignoredAreas);
            return(screenshot);
        }
Example #3
0
 protected internal virtual ICollection <Coords> CompileIgnoredAreas(IWebDriver driver, CoordsPreparationStrategy
                                                                     preparationStrategy)
 {
     lock (this)
     {
         ICollection <Coords> ignoredCoords = new HashSet <Coords>();
         foreach (By ignoredLocator in this.ignoredLocators)
         {
             IList <IWebElement> ignoredElements = driver.FindElements(ignoredLocator);
             if (!ignoredElements.IsEmpty())
             {
                 ignoredCoords.AddAll(preparationStrategy.prepare(this.coordsProvider.ofElements(driver, ignoredElements.AsEnumerable())));
             }
         }
         foreach (Coords ignoredArea in this.ignoredAreas)
         {
             ignoredCoords.AddAll(preparationStrategy.prepare(new List <Coords> {
                 ignoredArea
             }));
         }
         return(ignoredCoords);
     }
 }