• <legend id='3WbWG'><style id='3WbWG'><dir id='3WbWG'><q id='3WbWG'></q></dir></style></legend>

          <bdo id='3WbWG'></bdo><ul id='3WbWG'></ul>

        <small id='3WbWG'></small><noframes id='3WbWG'>

        <tfoot id='3WbWG'></tfoot>

        <i id='3WbWG'><tr id='3WbWG'><dt id='3WbWG'><q id='3WbWG'><span id='3WbWG'><b id='3WbWG'><form id='3WbWG'><ins id='3WbWG'></ins><ul id='3WbWG'></ul><sub id='3WbWG'></sub></form><legend id='3WbWG'></legend><bdo id='3WbWG'><pre id='3WbWG'><center id='3WbWG'></center></pre></bdo></b><th id='3WbWG'></th></span></q></dt></tr></i><div id='3WbWG'><tfoot id='3WbWG'></tfoot><dl id='3WbWG'><fieldset id='3WbWG'></fieldset></dl></div>

        在 Selenium 2 中截取测试屏幕截图的最佳方法是什么?

        时间:2023-09-13

      1. <legend id='37UDc'><style id='37UDc'><dir id='37UDc'><q id='37UDc'></q></dir></style></legend>
        • <tfoot id='37UDc'></tfoot>

          <small id='37UDc'></small><noframes id='37UDc'>

            <tbody id='37UDc'></tbody>

              <i id='37UDc'><tr id='37UDc'><dt id='37UDc'><q id='37UDc'><span id='37UDc'><b id='37UDc'><form id='37UDc'><ins id='37UDc'></ins><ul id='37UDc'></ul><sub id='37UDc'></sub></form><legend id='37UDc'></legend><bdo id='37UDc'><pre id='37UDc'><center id='37UDc'></center></pre></bdo></b><th id='37UDc'></th></span></q></dt></tr></i><div id='37UDc'><tfoot id='37UDc'></tfoot><dl id='37UDc'><fieldset id='37UDc'></fieldset></dl></div>

                  <bdo id='37UDc'></bdo><ul id='37UDc'></ul>

                  本文介绍了在 Selenium 2 中截取测试屏幕截图的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要一种方法来截取我的功能测试的屏幕截图.现在我正在使用带有 C# 绑定的 Selenium 2.我非常想在测试结束时截屏以确保显示所需的页面.你们知道我可以将哪些特定工具合并到我的 C# 代码中来触发屏幕截图吗?我找不到内置的 Selenium 2 解决方案(不仔细看).

                  I need a way to take screenshots of my functional tests. Right now I'm using Selenium 2 with C# bindings. I pretty much want to take a screenshot at the end of the test to make sure the desired page is displayed. Are there any particular tools you guys know of that I can incorporate into my C# code that will trigger a screenshot? I couldn't find a built-in Selenium 2 solution (without looking it over).

                  推荐答案

                  要在 Selenium 2 中进行屏幕截图,您需要执行以下操作

                  To do screenshots in Selenium 2 you need to do the following

                  driver = new FireFoxDriver(); // Should work in other Browser Drivers
                  driver.Navigate().GoToUrl("http://www.theautomatedtester.co.uk");
                  Screenshot ss = ((ITakesScreenshot) driver).GetScreenshot();
                  
                  //Use it as you want now
                  string screenshot = ss.AsBase64EncodedString;
                  byte[] screenshotAsByteArray = ss.AsByteArray;
                  ss.SaveAsFile("filename", ImageFormat.Png); //use any of the built in image formating
                  ss.ToString();//same as string screenshot = ss.AsBase64EncodedString;
                  

                  该代码应该可以工作,因为我在 IronPython Repl 中快速对其进行了测试.请参阅下面的 IronPython 代码

                  That code should work, as I quickly tested it in IronPython Repl. See the IronPython code below

                  import clr
                  clr.AddReference("WebDriver.Common.dll")
                  clr.AddReference("WebDriver.Firefox.dll")
                  from OpenQA.Selenium import *
                  from OpenQA.Selenium.Firefox import *
                  driver = FirefoxDriver()
                  driver.Navigate().GoToUrl("http://www.theautomatedtester.co.uk")
                  s = driver.GetScreenshot()
                  s.AsBaseEncodedString
                  # HUGE string appears in the REPL
                  

                  这篇关于在 Selenium 2 中截取测试屏幕截图的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Webdriver:文件上传 下一篇:Webdriver如何等到元素在webdriver C#中可点击

                  相关文章

                    <legend id='HTJVL'><style id='HTJVL'><dir id='HTJVL'><q id='HTJVL'></q></dir></style></legend><tfoot id='HTJVL'></tfoot>

                      <small id='HTJVL'></small><noframes id='HTJVL'>

                    1. <i id='HTJVL'><tr id='HTJVL'><dt id='HTJVL'><q id='HTJVL'><span id='HTJVL'><b id='HTJVL'><form id='HTJVL'><ins id='HTJVL'></ins><ul id='HTJVL'></ul><sub id='HTJVL'></sub></form><legend id='HTJVL'></legend><bdo id='HTJVL'><pre id='HTJVL'><center id='HTJVL'></center></pre></bdo></b><th id='HTJVL'></th></span></q></dt></tr></i><div id='HTJVL'><tfoot id='HTJVL'></tfoot><dl id='HTJVL'><fieldset id='HTJVL'></fieldset></dl></div>
                      • <bdo id='HTJVL'></bdo><ul id='HTJVL'></ul>