How to use Save method of Ocaramba.Helpers.TakeScreenShot class

Best Ocaramba code snippet using Ocaramba.Helpers.TakeScreenShot.Save

TakeScreenShot.cs

Source:TakeScreenShot.cs Github

copy

Full Screen

...66 return (Bitmap)bitmap.Clone();67 }68 }69 /// <summary>70 /// Saves the specified bitmap.71 /// </summary>72 /// <param name="bitmap">The bitmap.</param>73 /// <param name="format">The format.</param>74 /// <param name="folder">The folder.</param>75 /// <param name="title">The title.</param>76 /// <returns>The path to the saved bitmap, null if not saved.</returns>77 public static string Save(Bitmap bitmap, ImageFormat format, string folder, string title)78 {79 var fileName = string.Format(CultureInfo.CurrentCulture, "{0}_{1}_{2}.png", title, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff", CultureInfo.CurrentCulture), "fullscreen");80 fileName = Regex.Replace(fileName, "[^0-9a-zA-Z._]+", "_");81 fileName = NameHelper.ShortenFileName(folder, fileName, "_", 255);82 var filePath = Path.Combine(folder, fileName);83 if (bitmap == null)84 {85 Logger.Error("Full screenshot is not saved");86 }87 else88 {89 bitmap.Save(filePath, format);90 bitmap.Dispose();91 Logger.Error(CultureInfo.CurrentCulture, "Test failed: full screenshot saved to {0}.", filePath);92 FilesHelper.WaitForFileOfGivenName(BaseConfiguration.ShortTimeout, fileName, folder);93 Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath));94 return filePath;95 }96 return null;97 }98 /// <summary>99 /// Takes screen shot of specific element.100 /// </summary>101 /// <param name="element">Element to take screenshot.</param>102 /// <param name="folder">Folder to save screenshot.</param>103 /// <param name="screenshotName">Name of screenshot.</param>104 /// <returns>Full path to taken screenshot.</returns>105 /// <example>How to use it: <code>106 /// var el = this.Driver.GetElement(this.menu);107 /// var fullPath = TakeScreenShot.TakeScreenShotOfElement(el, Directory.GetCurrentDirectory() + BaseConfiguration.ScreenShotFolder, "MenuOutSideTheIFrame");108 /// </code></example>109 public static string TakeScreenShotOfElement(IWebElement element, string folder, string screenshotName)110 {111 Logger.Debug("Taking screenhot of element not within iframe");112 return TakeScreenShotOfElement(0, 0, element, folder, screenshotName);113 }114 /// <summary>115 /// Takes screen shot of specific element within iframe.116 /// </summary>117 /// <param name="iframeLocationX">X coordinate of iframe.</param>118 /// <param name="iframeLocationY">Y coordinate of iframe.</param>119 /// <param name="element">Element to take screenshot.</param>120 /// <param name="folder">Folder to save screenshot.</param>121 /// <param name="screenshotName">Name of screenshot.</param>122 /// <returns>Full path to taken screenshot.</returns>123 /// <example>How to use it: <code>124 /// var iFrame = this.Driver.GetElement(this.iframe);125 /// int x = iFrame.Location.X;126 /// int y = iFrame.Location.Y;127 /// this.Driver.SwitchTo().Frame(0);128 /// var el = this.Driver.GetElement(this.elelemtInIFrame);129 /// var fullPath = TakeScreenShot.TakeScreenShotOfElement(x, y, el, Directory.GetCurrentDirectory() + BaseConfiguration.ScreenShotFolder, "MenuOutSideTheIFrame");130 /// </code></example>131 public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLocationY, IWebElement element, string folder, string screenshotName)132 {133 Logger.Debug("Taking screenhot of iframe LocationX:{0} LocationY:{1}", iframeLocationX, iframeLocationY);134 var locationX = iframeLocationX;135 var locationY = iframeLocationY;136 var driver = element.ToDriver();137 var screenshotDriver = (ITakesScreenshot)driver;138 var screenshot = screenshotDriver.GetScreenshot();139 var filePath = Path.Combine(folder, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff", CultureInfo.CurrentCulture) + "temporary_fullscreen.png");140 Logger.Debug(CultureInfo.CurrentCulture, "Taking full screenshot {0}", filePath);141 screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png);142 if (BaseConfiguration.TestBrowser == BrowserType.Chrome)143 {144 locationX = element.Location.X + locationX;145 locationY = element.Location.Y + locationY;146 }147 else148 {149 locationX = element.Location.X;150 locationY = element.Location.Y;151 }152 var elementWidth = element.Size.Width;153 var elementHeight = element.Size.Height;154 return CutOutScreenShot(folder, screenshotName, locationX, locationY, elementWidth, elementHeight, filePath);155 }156 /// <summary>157 /// Cut out the screen shot by giving locationX, locationY, elementWidth, elementHeight.158 /// </summary>159 /// <param name="folder">Folder to save new screenshot.</param>160 /// <param name="newScreenShotName">Name of new screenshot.</param>161 /// <param name="locationX">The x-coordinate of the upper-left corner of the new rectangle.</param>162 /// <param name="locationY">The y-coordinate of the upper-left corner of the new rectangle.</param>163 /// <param name="elementWidth">The width of the new rectangle.</param>164 /// <param name="elementHeight">The height of the new rectangle.</param>165 /// <param name="fullPathToScreenShotToCutOut">Full path to the screenshot to be cut out.</param>166 /// <returns>Full path of cutted out screenshot.</returns>167 /// <example>How to use it: <code>168 /// var fullPath = CutOutScreenShot(folder, screenshotName, locationX, locationY, elementWidth, elementHeight, fullPathToScreenShotToCutOut);169 /// </code></example>170 public static string CutOutScreenShot(string folder, string newScreenShotName, int locationX, int locationY, int elementWidth, int elementHeight, string fullPathToScreenShotToCutOut)171 {172 Logger.Debug(CultureInfo.CurrentCulture, "Trying to cut out screenshot locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3}", locationX, locationY, elementWidth, elementHeight);173 string newFilePath;174 Bitmap importFile = null;175 Bitmap cloneFile;176 try177 {178 importFile = new Bitmap(fullPathToScreenShotToCutOut);179 Logger.Debug(CultureInfo.CurrentCulture, "Size of imported screenshot Width:{0} Height:{1}", importFile.Size.Width, importFile.Size.Height);180 ////Check if new size of image is not bigger than imported.181 if (locationY > importFile.Size.Height || locationX > importFile.Size.Width)182 {183 Logger.Error(CultureInfo.CurrentCulture, "Cutting out screenshot locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3} is not possible", locationX, locationY, elementWidth, elementHeight);184 return null;185 }186 if (importFile.Size.Height - locationY < elementHeight)187 {188 elementHeight = importFile.Size.Height - locationY;189 }190 if (importFile.Size.Width - locationX < elementWidth)191 {192 elementWidth = importFile.Size.Width - locationX;193 }194 Logger.Debug(CultureInfo.CurrentCulture, "Cutting out screenshot locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3}", locationX, locationY, elementWidth, elementHeight);195 var image = new Rectangle(locationX, locationY, elementWidth, elementHeight);196 newFilePath = Path.Combine(folder, newScreenShotName + ".png");197 cloneFile = (Bitmap)importFile.Clone(image, importFile.PixelFormat);198 }199 finally200 {201 importFile?.Dispose();202 }203 Logger.Debug(CultureInfo.CurrentCulture, "Saving new screenshot {0}", newFilePath);204 cloneFile.Save(newFilePath);205 File.Delete(fullPathToScreenShotToCutOut);206 return newFilePath;207 }208 }209}210#endif...

Full Screen

Full Screen

SaveScreenShotsPageSourceTestsNUnit.cs

Source:SaveScreenShotsPageSourceTestsNUnit.cs Github

copy

Full Screen

1// <copyright file="SaveScreenShotsPageSourceTestsNUnit.cs" company="Objectivity Bespoke Software Specialists">2// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved.3// </copyright>4// <license>5// The MIT License (MIT)6// Permission is hereby granted, free of charge, to any person obtaining a copy7// of this software and associated documentation files (the "Software"), to deal8// in the Software without restriction, including without limitation the rights9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10// copies of the Software, and to permit persons to whom the Software is11// furnished to do so, subject to the following conditions:12// The above copyright notice and this permission notice shall be included in all13// copies or substantial portions of the Software.14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20// SOFTWARE.21// </license>22namespace Ocaramba.Tests.NUnit.Tests23{24 using System.Drawing.Imaging;25 using System.Globalization;26 using global::NUnit.Framework;27 using Ocaramba.Helpers;28 using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;29 [TestFixture]30 public class SaveScreenShotsPageSourceTestsNUnit : ProjectTestBase31 {32 [Test]33 [Category("TakingScreehShots")]34 [Category("NotImplementedInCoreOrUploadDownload")]35 public void SaveFullScreenShotTest()36 {37 var downloadPage = new InternetPage(this.DriverContext).OpenHomePage().GoToFileDownloader();38 var screenShotNumber = FilesHelper.CountFiles(this.DriverContext.ScreenShotFolder, FileType.Png);39#if net4740 Assert.IsNotNull(TakeScreenShot.Save(TakeScreenShot.DoIt(), ImageFormat.Png, this.DriverContext.ScreenShotFolder, string.Format(CultureInfo.CurrentCulture, this.DriverContext.TestTitle + "_first")));41#endif42 var nameOfScreenShot = downloadPage.CheckIfScreenShotIsSaved(screenShotNumber);43 TestContext.AddTestAttachment(nameOfScreenShot);44 Assert.IsTrue(nameOfScreenShot.Contains(this.DriverContext.TestTitle), "Name of screenshot doesn't contain Test Title");45 Assert.IsNotNull(this.DriverContext.TakeAndSaveScreenshot());46 }47 [Test]48 public void SaveWebDriverScreenShotTest()49 {50 var downloadPage = new InternetPage(this.DriverContext).OpenHomePage().GoToFileDownloader();51 var screenShotNumber = FilesHelper.CountFiles(this.DriverContext.ScreenShotFolder, FileType.Png);52 Assert.IsNotNull(downloadPage.SaveWebDriverScreenShot());53 var nameOfScreenShot = downloadPage.CheckIfScreenShotIsSaved(screenShotNumber);54 TestContext.AddTestAttachment(nameOfScreenShot);55 Assert.IsTrue(nameOfScreenShot.Contains(this.DriverContext.TestTitle), "Name of screenshot doesn't contain Test Title");56 }57 [Test]58 [Category("NotImplementedInCoreOrUploadDownload")]59 public void SaveSourcePageTest()60 {61 var basicAuthPage = new InternetPage(this.DriverContext).OpenHomePageWithUserCredentials().GoToBasicAuthPage();62 var name = this.DriverContext.TestTitle + FilesHelper.ReturnFileExtension(FileType.Html);63 FilesHelper.DeleteFile(name, this.DriverContext.PageSourceFolder);64 var pageSourceNumber = FilesHelper.CountFiles(this.DriverContext.PageSourceFolder, FileType.Html);65 Assert.IsNotNull(basicAuthPage.SaveSourcePage());66 basicAuthPage.CheckIfPageSourceSaved();67 Assert.IsTrue(pageSourceNumber < FilesHelper.CountFiles(this.DriverContext.PageSourceFolder, FileType.Html), "Number of html files did not increase");68 }69 }70}...

Full Screen

Full Screen

Save

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using Ocaramba.Types;4using Microsoft.VisualStudio.TestTools.UnitTesting;5{6 {7 public void TestMethod1()8 {9 TakeScreenShot.Save(DriverContext.Current.Driver, "test1");10 }11 }12}13using Ocaramba;14using Ocaramba.Helpers;15using Ocaramba.Types;16using Microsoft.VisualStudio.TestTools.UnitTesting;17{18 {19 public void TestMethod1()20 {21 TakeScreenShot.Save(DriverContext.Current.Driver, "test1", ScreenshotImageFormat.Png);22 }23 }24}25using Ocaramba;26using Ocaramba.Helpers;27using Ocaramba.Types;28using Microsoft.VisualStudio.TestTools.UnitTesting;29{30 {31 public void TestMethod1()32 {33 TakeScreenShot.Save(DriverContext.Current.Driver, "test1", ScreenshotImageFormat.Png, 100);34 }35 }36}37using Ocaramba;38using Ocaramba.Helpers;39using Ocaramba.Types;40using Microsoft.VisualStudio.TestTools.UnitTesting;41{42 {43 public void TestMethod1()44 {45 TakeScreenShot.Save(DriverContext.Current.Driver, "test1", ScreenshotImageFormat.Png, 100, 100);46 }47 }48}

Full Screen

Full Screen

Save

Using AI Code Generation

copy

Full Screen

1using System;2using Ocaramba;3using Ocaramba.Helpers;4using NUnit.Framework;5{6 {7 public void TakeScreenShotTest()8 {9 TakeScreenShot.Save(DriverContext.Current.Driver, "google");10 }11 }12}13using System;14using Ocaramba;15using Ocaramba.Helpers;16using NUnit.Framework;17{18 {19 public void TakeScreenShotTest()20 {21 TakeScreenShot.Save(DriverContext.Current.Driver, "google", "C:\\Users\\");22 }23 }24}25using System;26using Ocaramba;27using Ocaramba.Helpers;28using NUnit.Framework;29{30 {31 public void TakeScreenShotTest()32 {33 TakeScreenShot.Save(DriverContext.Current.Driver, "google", "C:\\Users\\", "jpg");34 }35 }36}37using System;38using Ocaramba;39using Ocaramba.Helpers;40using NUnit.Framework;41{42 {43 public void TakeScreenShotTest()44 {45 TakeScreenShot.Save(DriverContext.Current.Driver, "google", "C:\\Users\\", "jpg", 100);46 }47 }48}49using System;

Full Screen

Full Screen

Save

Using AI Code Generation

copy

Full Screen

1ScreenshotHelper.Save(browser, "2", ScreenshotImageFormat.Png);2ScreenshotHelper.Save(browser, "3", ScreenshotImageFormat.Png);3ScreenshotHelper.Save(browser, "4", ScreenshotImageFormat.Png);4ScreenshotHelper.Save(browser, "5", ScreenshotImageFormat.Png);5ScreenshotHelper.Save(browser, "6", ScreenshotImageFormat.Png);6ScreenshotHelper.Save(browser, "7", ScreenshotImageFormat.Png);7ScreenshotHelper.Save(browser, "8", ScreenshotImageFormat.Png);8ScreenshotHelper.Save(browser, "9", ScreenshotImageFormat.Png);9ScreenshotHelper.Save(browser, "10", ScreenshotImageFormat.Png);10ScreenshotHelper.Save(browser, "11", ScreenshotImageFormat.Png);11ScreenshotHelper.Save(browser, "12", ScreenshotImageFormat.Png);12ScreenshotHelper.Save(browser, "13", ScreenshotImageFormat.Png);13ScreenshotHelper.Save(browser, "14", ScreenshotImageFormat.Png);14ScreenshotHelper.Save(browser

Full Screen

Full Screen

Save

Using AI Code Generation

copy

Full Screen

1using Ocaramba.Helpers;2using NUnit.Framework;3{4 {5 public void TakeScreenShotTest1()6 {7 var screenShot = new TakeScreenShot(this.DriverContext);8 screenShot.Save();9 }10 }11}12using Ocaramba.Helpers;13using NUnit.Framework;14{15 {16 public void TakeScreenShotTest1()17 {18 var screenShot = new TakeScreenShot(this.DriverContext);19 screenShot.Save("screenShotName");20 }21 }22}23using Ocaramba.Helpers;24using NUnit.Framework;25{26 {27 public void TakeScreenShotTest1()28 {29 var screenShot = new TakeScreenShot(this.DriverContext);30 screenShot.Save("screenShotName", "screenShotFolder");31 }32 }33}34using Ocaramba.Helpers;35using NUnit.Framework;36{37 {38 public void TakeScreenShotTest1()39 {40 var screenShot = new TakeScreenShot(this.DriverContext);41 screenShot.Save("screenShotName", "screenShotFolder", "screenShotPath");42 }43 }44}45using Ocaramba.Helpers;46using NUnit.Framework;47{48 {49 public void TakeScreenShotTest1()50 {51 var screenShot = new TakeScreenShot(this.DriverContext);52 screenShot.Save("screenShotName", "screenShotFolder", "screenShotPath", "screenShotExtension");53 }54 }55}

Full Screen

Full Screen

Save

Using AI Code Generation

copy

Full Screen

1SaveScreenshot("MyScreenShot2");2SaveScreenshot("MyScreenShot3");3SaveScreenshot("MyScreenShot4");4SaveScreenshot("MyScreenShot5");5SaveScreenshot("MyScreenShot6");6SaveScreenshot("MyScreenShot7");7SaveScreenshot("MyScreenShot8");8SaveScreenshot("MyScreenShot9");9SaveScreenshot("MyScreenShot10");10SaveScreenshot("MyScreenShot11");11SaveScreenshot("MyScreenShot12");12SaveScreenshot("MyScreenShot13");13SaveScreenshot("MyScreenShot14");14SaveScreenshot("MyScreenShot15");15SaveScreenshot("MyScreenShot16");16SaveScreenshot("MyScreenShot17");

Full Screen

Full Screen

Save

Using AI Code Generation

copy

Full Screen

1var path = @"C:\Users\Public\Pictures\Sample Pictures\";2var fileName = "test.png";3var takeScreenShot = new TakeScreenShot(DriverContext.Driver);4takeScreenShot.Save(path, fileName);5var path = @"C:\Users\Public\Pictures\Sample Pictures\";6var fileName = "test.png";7var takeScreenShot = new TakeScreenShot(DriverContext.Driver);8takeScreenShot.Save(path, fileName, ScreenshotImageFormat.Png);9var path = @"C:\Users\Public\Pictures\Sample Pictures\";10var fileName = "test.png";11var takeScreenShot = new TakeScreenShot(DriverContext.Driver);12takeScreenShot.Save(path, fileName, ScreenshotImageFormat.Png, 100);13var path = @"C:\Users\Public\Pictures\Sample Pictures\";14var fileName = "test.png";15var takeScreenShot = new TakeScreenShot(DriverContext.Driver);16takeScreenShot.Save(path, fileName, ScreenshotImageFormat.Png, 100, 50, 50);17var path = @"C:\Users\Public\Pictures\Sample Pictures\";18var fileName = "test.png";19var takeScreenShot = new TakeScreenShot(DriverContext.Driver);20takeScreenShot.Save(path, fileName, ScreenshotImageFormat.Png, 100, 50, 50, 50, 50);21var path = @"C:\Users\Public\Pictures\Sample Pictures\";22var fileName = "test.png";23var takeScreenShot = new TakeScreenShot(DriverContext.Driver);24takeScreenShot.Save(path, fileName, ScreenshotImageFormat.Png, 100, 50, 50, 50, 50, 50);

Full Screen

Full Screen

Save

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using Ocaramba.Types;4using NUnit.Framework;5using System;6using System.Drawing;7using System.IO;8{9 {10 public void TakeScreenShotTest()11 {12 TakeScreenShot.Save(this.Driver, "2");13 }14 }15}16using Ocaramba;17using Ocaramba.Helpers;18using Ocaramba.Types;19using NUnit.Framework;20using System;21using System.Drawing;22using System.IO;23{24 {25 public void TakeScreenShotTest()26 {27 TakeScreenShot.Save(this.Driver, "3");28 }29 }30}31using Ocaramba;32using Ocaramba.Helpers;33using Ocaramba.Types;34using NUnit.Framework;35using System;36using System.Drawing;37using System.IO;38{39 {40 public void TakeScreenShotTest()41 {42 TakeScreenShot.Save(this.Driver, "

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ocaramba automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in TakeScreenShot

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful