示例#1
0
 public void SavePic(string path, ScreenshotImageFormat type = ScreenshotImageFormat.Jpeg, bool isFull = false)
 {
     if (isFull)
     {
         string str = path;
         ((ChromeDriver)_driver).ExecuteChromeCommand("Emulation.setDeviceMetricsOverride", new Dictionary <string, object>()
         {
             ["width"]             = ((RemoteWebDriver)_driver).ExecuteScript("return Math.max(window.innerWidth,document.body.scrollWidth,document.documentElement.scrollWidth)", Array.Empty <object>()),
             ["height"]            = ((RemoteWebDriver)_driver).ExecuteScript("return Math.max(window.innerHeight,document.body.scrollHeight,document.documentElement.scrollHeight)", Array.Empty <object>()),
             ["deviceScaleFactor"] = ((RemoteWebDriver)_driver).ExecuteScript("return window.devicePixelRatio", Array.Empty <object>()),
             ["mobile"]            = ((RemoteWebDriver)_driver).ExecuteScript("return typeof window.orientation !== 'undefined'", Array.Empty <object>())
         });
         ((RemoteWebDriver)_driver).GetScreenshot().SaveAsFile(str, ScreenshotImageFormat.Png);
     }
     else
     {
         WebDriverExtensions.TakeScreenshot(_driver).SaveAsFile(path, type);
     }
 }
示例#2
0
        public void AfterScenario()
        {
            try
            {
                if (_scenarioContext.TestError != null)
                {
                    WebDriverExtensions.TakeScreenshot(Driver);
                }
            }

            catch (Exception e)
            {
                Console.WriteLine($"Unable to execute AfterScenario step due to {e.Message}");
            }

            finally
            {
                WebDriverExtensions.CloseHangingWindows(Driver, OriginalHandle);
                Driver.Manage().Cookies.DeleteAllCookies();
            }
        }