Sometime we require to check website pages whether site is displaying proper content or not. Before performing deployment or any other code changes to your website how is the content current displayed on website pages. To solve this problem we have created Website Page Capturer which will take screenshot of entire website page of mentioned URL's and store images in the folder. Below blog describes how to can create this console application.1. Create console application in Visual Studio.
2. Install below Package using Nugget Package Manager
- Selenium.Chrome.WebDriver
- Selenium.WebDriver
- Noksa.WebDriver.ScreenshotsExtensions
3. Add the below code in Program.cs file
using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Support.Extensions; using System; using System.IO; using System.Reflection; using System.Threading; using WDSE; using WDSE.Decorators; using WDSE.ScreenshotMaker; namespace WebsiteScreenshotsCapture { class Program { public static void FullWebPageScreenShotCapture() { try { string[] Urls = { "https://www.cleartrip.com/", "https://www.olx.in/", "https://www.amazon.com/", "https://www.ebay.com/" }; string ScreenShotsLocations = @"C:\User\Projects\WebsiteScreenshotsCapture\Pages\"; string DateTimeProperFormat = String.Format("{0}-{1}-{2}-{3}-{4}-{5}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); ChromeOptions options = new ChromeOptions(); options.AddArgument("headless");//Comment if we want to see the window. options.AddArgument("--log-level=3");// Hides log errors/warnings ChromeDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options); driver.Manage().Window.Maximize(); //Creating folder string foldername = String.Format(@"{0}/{1}/", ScreenShotsLocations,DateTimeProperFormat); System.IO.Directory.CreateDirectory(foldername); Console.Clear(); Console.WriteLine("Application Started"); Console.WriteLine("Starting to Take Screenshots.........."); for (int i = 0; i < Urls.Length; i++) { driver.Url = Urls[i]; VerticalCombineDecorator vcd = new VerticalCombineDecorator(new ScreenshotMaker().RemoveScrollBarsWhileShooting()); driver.TakeScreenshot(vcd).ToMagickImage().ToBitmap().Save(String.Format("{0}Image{1}.png", foldername, i + 1)); Console.WriteLine("{0}- Captured",Urls[i]); } Console.WriteLine("Task Completed.........."); driver.Quit(); } catch (Exception ex) { Console.WriteLine("Exception {0}",ex); } finally { Console.WriteLine("Press any key to exit......"); Console.ReadKey(); } } static void Main(string[] args) { FullWebPageScreenShotCapture(); } } }
Note: You can move configuration file in App.config for demonstration purpose I have added that in same file
After executing the application you will see folder is created on mentioned location in code and created folder will have screenshots of the website pages.
Console Output
Folder Created
Website Screenshots
Hope you find this blog useful 😀
No comments:
Post a Comment