public SaveAsFile ( string fileName, |
||
fileName | string | The full path and file name to save the screenshot to. |
format | A |
|
Результат | void |
/// <summary> /// Get a screen shot of the current window /// </summary> /// <param name="savePath"></param> public void TakeScreenshot(string savePath) { QA.Screenshot theScreenshot = null; switch (this.browser) { case Browsers.IE: { theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot(); }; break; case Browsers.Chrome: { theScreenshot = ((QA.Chrome.ChromeDriver)wd).GetScreenshot(); }; break; case Browsers.Firefox: { theScreenshot = ((QA.Firefox.FirefoxDriver)wd).GetScreenshot(); }; break; case Browsers.Safari: { theScreenshot = ((QA.Safari.SafariDriver)wd).GetScreenshot(); }; break; default: { theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot(); }; break; } if (theScreenshot != null) { theScreenshot.SaveAsFile(savePath, QA.ScreenshotImageFormat.Jpeg); } }
public RemoteWebDriver GetLoginedDriver(Account acc) { // RemoteWebDriver phantomJs = new PhantomJSDriver(); RemoteWebDriver driver = ChromeInstance.Driver(); driver.Url = "http://youlikehits.com/"; List <DCookie> dCookie; using (var reader = new StreamReader(this._dirPath + "/" + acc.Login + ".xml")) { XmlSerializer deserializer = new XmlSerializer(typeof(List <DCookie>), new XmlRootAttribute("list")); dCookie = (List <DCookie>)deserializer.Deserialize(reader); } foreach (var cookie in dCookie) { driver.Manage().Cookies.AddCookie(cookie.GetCookie()); } driver.Url = "https://youlikehits.com/"; OpenQA.Selenium.Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot(); screenshot.SaveAsFile("cookie.jpg", ScreenshotImageFormat.Jpeg); return(driver); }
/// <summary> /// Get a screen shot of the current window /// </summary> /// <param name="savePath"></param> protected void TakeScreenshot(string savePath) { QA.Screenshot theScreenshot = ((QA.PhantomJS.PhantomJSDriver)_WebDriver).GetScreenshot(); if (theScreenshot != null) { theScreenshot.SaveAsFile(savePath, System.Drawing.Imaging.ImageFormat.Png); } }
public void GetElementScreenshot() { WindowsDriver <WindowsElement> desktopSession = null; try { // Locate the AlarmPivotItem element in Alarms & Clock app to be captured WindowsElement alarmPivotItem1 = session.FindElementByAccessibilityId(AlarmTabAutomationId); OpenQA.Selenium.Screenshot alarmPivotItemScreenshot1 = alarmPivotItem1.GetScreenshot(); // Save the AlarmPivotItem screenshot capture locally on the machine running the test alarmPivotItemScreenshot1.SaveAsFile(@"ScreenshotAlarmPivotItem.png", ScreenshotImageFormat.Png); // Using the Desktop session, locate the same AlarmPivotItem element in Alarms & Clock app to be captured desktopSession = Utility.CreateNewSession(CommonTestSettings.DesktopAppId); WindowsElement alarmPivotItem2 = desktopSession.FindElementByAccessibilityId(AlarmTabAutomationId); OpenQA.Selenium.Screenshot alarmPivotItemScreenshot2 = alarmPivotItem2.GetScreenshot(); // Using the Desktop session, locate the Alarms & Clock app top level window to be captured WindowsElement alarmsClockWindowTopWindow = desktopSession.FindElementByName("Alarms & Clock"); OpenQA.Selenium.Screenshot alarmsClockWindowTopWindowScreenshot = alarmsClockWindowTopWindow.GetScreenshot(); using (MemoryStream msScreenshot1 = new MemoryStream(alarmPivotItemScreenshot1.AsByteArray)) using (MemoryStream msScreenshot2 = new MemoryStream(alarmPivotItemScreenshot2.AsByteArray)) using (MemoryStream msScreenshot3 = new MemoryStream(alarmsClockWindowTopWindowScreenshot.AsByteArray)) { // Verify that the element screenshot has a valid size Image screenshotImage1 = Image.FromStream(msScreenshot1); Assert.AreEqual(alarmPivotItem1.Size.Height, screenshotImage1.Height); Assert.AreEqual(alarmPivotItem1.Size.Width, screenshotImage1.Width); // Verify that the element screenshot captured using the Alarms & Clock session // is identical in size with the one taken using the desktop session Image screenshotImage2 = Image.FromStream(msScreenshot2); Assert.AreEqual(screenshotImage1.Height, screenshotImage2.Height); Assert.AreEqual(screenshotImage1.Width, screenshotImage2.Width); // Verify that the element screenshot is smaller in size compared to the application top level window Image screenshotImage3 = Image.FromStream(msScreenshot3); Assert.AreEqual(alarmsClockWindowTopWindow.Size.Height, screenshotImage3.Height); Assert.AreEqual(alarmsClockWindowTopWindow.Size.Width, screenshotImage3.Width); Assert.IsTrue(screenshotImage3.Height > screenshotImage1.Height); Assert.IsTrue(screenshotImage3.Width > screenshotImage1.Width); } } finally { if (desktopSession != null) { desktopSession.Quit(); } } }
public void TakeScreenShot(IWebDriver driver, string filename) { try { OpenQA.Selenium.Screenshot image = ((ITakesScreenshot)driver).GetScreenshot(); image.SaveAsFile(filename, ScreenshotImageFormat.Jpeg); } catch (Exception e) { Console.WriteLine(e); Assert.Fail("Could not screencapture. Exception: " + e); } }
/// <summary> /// Capture screen /// </summary> /// <returns></returns> public static string CaptureScreen() { try { ITakesScreenshot ssdriver = Browser.driver as ITakesScreenshot; OpenQA.Selenium.Screenshot screenshot = ssdriver.GetScreenshot(); screenshot.SaveAsFile(screenShotPath); return(screenShotPath); } catch (Exception e) { return(e.Message); } }
/// <summary> /// Get a screen shot of the current window /// </summary> /// <param name="savePath"></param> public void TakeScreenshot(string savePath) { QA.Screenshot theScreenshot = null; switch (this.browser) { case Browsers.IE: { theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot(); }; break; case Browsers.Chrome: { theScreenshot = ((QA.Chrome.ChromeDriver)wd).GetScreenshot(); }; break; case Browsers.Firefox: { theScreenshot = ((QA.Firefox.FirefoxDriver)wd).GetScreenshot(); }; break; case Browsers.Safari: { theScreenshot = ((QA.Safari.SafariDriver)wd).GetScreenshot(); }; break; default: { theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot(); }; break; } if (theScreenshot != null) { for (int i = 0; i < 5; i++) { try { theScreenshot.SaveAsFile(savePath, QA.ScreenshotImageFormat.Jpeg); return; } catch (Exception ex) { Commons.Wait(new Random().Next(3, 7)); } } } }
/// <summary> /// capture screen with screen shot /// </summary> /// <returns></returns> public static string CaptureScreenWithCallStack() { try { if (BoolScreenShotOnException) { screenShotPath = string.Empty; screenShotPath = ConfigurationManager.AppSettings["ScreenShotPath"] + DateTime.Now.ToLongDateString(); string filename = DateTime.Now.ToString("HH:mm"); string CallStack = GetCallStack(); screenShotPath = screenShotPath + "\\\\" + "_" + CallStack + "_" + filename.Replace(":", "_") + ".png"; ITakesScreenshot ssdriver = Browser.driver as ITakesScreenshot; OpenQA.Selenium.Screenshot screenshot = ssdriver.GetScreenshot(); screenshot.SaveAsFile(screenShotPath); return(screenShotPath); } else { return(string.Empty); } } catch (UnhandledAlertException ex) { AlertMessage Alert = new AlertMessage(); Alert.CloseAlertBox(); ITakesScreenshot ssdriver = Browser.driver as ITakesScreenshot; OpenQA.Selenium.Screenshot screenshot = ssdriver.GetScreenshot(); screenshot.SaveAsFile(screenShotPath); return(screenShotPath); } catch (Exception e) { return(screenShotPath); } }
private void HandleResult(ITestWorker testWorker, TestResult testResult) { if (testWorker.WorkItem != null && (testResult.TestState == TestState.Error || testResult.TestState == TestState.ErrorRepeat) && testWorker.WorkItem.RunCount < RegtestingServerConfiguration.MaxRunCount) { _testPool.ReAddWorkItem(testWorker.WorkItem); testWorker.WorkItem = null; return; } WorkItem workItem = testWorker.WorkItem; workItem.TestState = testResult.TestState; string imagefile = null; if (!String.IsNullOrEmpty(testResult.Screenshot)) { string folder = RegtestingServerConfiguration.Screenshotsfolder; string subFolder = DateTime.Now.Year + "-" + DateTime.Now.Month + "\\"; string fileName = "screen" + Helper.GetScreenshotString() + ".png"; Directory.CreateDirectory(folder + subFolder); imagefile = subFolder + fileName; Screenshot screenshot = new Screenshot(testResult.Screenshot); screenshot.SaveAsFile(folder + imagefile, ImageFormat.Png); } Result result = _resultRepository.Get(workItem.Testsystem, workItem.Testcase, workItem.Browser, workItem.Language); result.ResultCode = testResult.TestState; result.DetailLog = CreateLog(testResult.Log); result.Error = testResult.Error; result.Testtime = DateTime.Now; result.ScreenshotFile = imagefile; if (result.ResultCode == TestState.Error || result.ResultCode == TestState.ErrorRepeat || result.ResultCode == TestState.KnownError) { if (result.ErrorCount == null) { result.ErrorCount = 1; result.ErrorSince = result.Testtime; } else { result.ErrorCount = result.ErrorCount + 1; } } else { result.ErrorSince = null; result.ErrorCount = null; } _resultRepository.Store(result); workItem.Result = result; foreach (ITestJobManager testJobManager in workItem.TestJobManagers) { HistoryResult historyResult = Mapper.Map<HistoryResult>(workItem); historyResult.DetailLog = CreateLog(testResult.Log); historyResult.ResultCode = testResult.TestState; historyResult.Error = testResult.Error; historyResult.Testtime = DateTime.Now; historyResult.TestJob = testJobManager.TestJob; historyResult.ScreenshotFile = imagefile; _historyResultRepository.Store(historyResult); } lock (TestsystemSummariesCache.Cache.GetLock(workItem.Testsystem.ID)) { TestsystemSummariesCache.Cache.Set(workItem.Testsystem.ID, null); } testWorker.WorkItem = null; _testPool.WorkItemFinished(workItem); }
static void takeScreenshots() { screenshots = ((ITakesScreenshot)driver).GetScreenshot(); string cas = DateTime.Now.ToString("dd_MM_yy_HH_mm_ss"); screenshots.SaveAsFile("C:/Users/ivoss_000/Desktop/Selenium Test/Selenium Test/Screeny/test_" + cas + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); }
public void GetScreenshot() { WindowsDriver <WindowsElement> notepadSession = null; WindowsDriver <WindowsElement> desktopSession = null; try { // Launch and capture a screenshot of a maximized Notepad application. The steps below intentionally use // the Notepad application window to fully cover the Alarms & Clock application. This setup demonstrates // that capturing Alarms & Clock screenshot afterward will implicitly bring its window to foreground. notepadSession = Utility.CreateNewSession(CommonTestSettings.NotepadAppId); notepadSession.Manage().Window.Maximize(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); OpenQA.Selenium.Screenshot notepadScreenshot = notepadSession.GetScreenshot(); // Capture a screenshot of Alarms & Clock application // This implicitly brings the application window to foreground OpenQA.Selenium.Screenshot alarmsClockScreenshot = session.GetScreenshot(); // Save the application screenshot capture locally on the machine running the test alarmsClockScreenshot.SaveAsFile(@"ScreenshotAlarmsClockApplication.png", ScreenshotImageFormat.Png); // Capture the entire desktop using the Desktop session desktopSession = Utility.CreateNewSession(CommonTestSettings.DesktopAppId); OpenQA.Selenium.Screenshot desktopScreenshot = desktopSession.GetScreenshot(); // Save the desktop screenshot capture locally on the machine running the test desktopScreenshot.SaveAsFile(@"ScreenshotDesktop.png", ScreenshotImageFormat.Png); using (MemoryStream msScreenshot1 = new MemoryStream(alarmsClockScreenshot.AsByteArray)) using (MemoryStream msScreenshot2 = new MemoryStream(notepadScreenshot.AsByteArray)) using (MemoryStream msScreenshot3 = new MemoryStream(desktopScreenshot.AsByteArray)) { // Verify that the Alarms & Clock application screenshot has a valid size Image screenshotImage1 = Image.FromStream(msScreenshot1); Assert.AreEqual(session.Manage().Window.Size.Height, screenshotImage1.Height); Assert.AreEqual(session.Manage().Window.Size.Width, screenshotImage1.Width); // Verify that the maximized Notepad application screenshot has a valid size Image screenshotImage2 = Image.FromStream(msScreenshot2); Assert.AreEqual(notepadSession.Manage().Window.Size.Height, screenshotImage2.Height); Assert.AreEqual(notepadSession.Manage().Window.Size.Width, screenshotImage2.Width); // Verify that the application screenshot is smaller in size compared to the entire desktop Image screenshotImage3 = Image.FromStream(msScreenshot3); Assert.IsTrue(screenshotImage2.Height >= screenshotImage1.Height); Assert.IsTrue(screenshotImage2.Width >= screenshotImage1.Width); } } finally { if (notepadSession != null) { notepadSession.Quit(); } if (desktopSession != null) { desktopSession.Quit(); } } }
/// <summary> /// Takes screenshot and saves it in desired location /// </summary> /// <param name="format">Format of image file</param> public static void TakeScreenshot(ScreenshotImageFormat format = ScreenshotImageFormat.Png) { OpenQA.Selenium.Screenshot shot = ((ITakesScreenshot)Browser.Driver).GetScreenshot(); shot.SaveAsFile(ShotPath + ShotName, format); }
public static void SaveScreenshot(Screenshot screenshot) { screenshot.SaveAsFile(ConfigurationManager.AppSettings["remoteLocation"] + Test.testName + Test.testID + ".jpg", ImageFormat.Jpeg); }
public void SaveScreenshot(Screenshot screenshot, string path) { screenshot.SaveAsFile(path, System.Drawing.Imaging.ImageFormat.Png); }
private void SaveScreenshot(Screenshot screenshot, string fileName) { screenshot.SaveAsFile(string.Format("{0}{1}", ConfigurationHelper.FolderPicture, fileName), ImageFormat.Png); }