GetScreenshot() public méthode

Gets a Screenshot object representing the image of the page on the screen.
public GetScreenshot ( ) : Screenshot
Résultat Screenshot
Exemple #1
0
        static void DoIt(string path)
        {
            string uri = @"file:///" + path;

            var d = new FirefoxDriver();
            d.Manage().Window.Size = new Size(2000, 2000);
            d.Navigate().GoToUrl(Path.Combine(uri, "a3.html"));

            var s = d.GetScreenshot();
            s.SaveAsFile(Path.Combine(path, "a3.png"), ImageFormat.Png);

            d.Quit();
        }
        public void SeleniumTets()
        {
            using (var driver = new FirefoxDriver(new FirefoxBinary("D:\\Program Files\\Mozilla Firefox\\firefox.exe"), new FirefoxProfile()))
            //using (var driver = new EdgeDriver())
            {
                //System.Threading.Thread.Sleep(10000);
                driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl("http://localhost:5956");

                //driver.Navigate().GoToUrl("http://localhost:5956");
                driver.GetScreenshot().SaveAsFile("data.png",ImageFormat.Png);
                driver.FindElements(By.TagName("a")).First(a => a.Text.Equals("About", StringComparison.InvariantCultureIgnoreCase)).Click();
                Assert.AreEqual(driver.Url, "http://localhost:5956/Home/About");
            }
        }
 public void TestMethod1()
 {
     var driver = new FirefoxDriver();
     try
     {
         driver.Navigate().GoToUrl("http://docs.seleniumhq.org/oops");
         driver.FindElement(By.Id("q")).Click();
         driver.Keyboard.SendKeys("Hello World!");
         driver.Keyboard.PressKey(Keys.Enter);
     }
     catch (Exception e)
     {
         var ss = driver.GetScreenshot(); 
         ss.SaveAsFile("failed-test-case.png", ImageFormat.Png);
         driver.Close();
         throw;
     }
 }
        public void StartScreenshotting(object parameters)
        {
            var parameter = parameters as object[];
            InstanceInfo instanceInfo = parameter[0] as InstanceInfo;
            DataTable urls = parameter[1] as DataTable;

            Log("Starting firefox...");
            FirefoxProfile ffProfile = new FirefoxProfile();
            JavaScriptError.AddExtension(ffProfile);

            using (var browser = new FirefoxDriver(ffProfile))
            {
                string targetDirectory = CreateTargetDirectory(instanceInfo);
                List<JavaScriptError> jsErrors = new List<JavaScriptError>();

                for (int i = 0; i < urls.Rows.Count; i++)
                {
                    try
                    {
                        Guid nodeGuid = (Guid)urls.Rows[i]["NodeGUID"];
                        Uri url = new Uri(instanceInfo.Url, "getdoc/" + nodeGuid);

                        Log("Screenshotting [{0}/{1}]: {2}", i, urls.Rows.Count, nodeGuid);

                        browser.Navigate().GoToUrl(url);
                        string fileName = GetFileName(targetDirectory, browser.Url);
                        browser.GetScreenshot()
                            .SaveAsFile(fileName, ImageFormat.Jpeg);

                        jsErrors.AddRange(JavaScriptError.ReadErrors(browser));
                    }
                    catch (Exception e)
                    {
                        Log("Exception: {0}", e.Message);
                    }
                }

                SaveJavaScriptErrorsToFile(jsErrors, targetDirectory);
                Log("Screenshotting finished.");
                browser.Close();
            }
        }