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

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

TakeScreenShot.cs

Source:TakeScreenShot.cs Github

copy

Full Screen

...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;...

Full Screen

Full Screen

CutOutScreenShot

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Ocaramba;7using Ocaramba.Extensions;8using Ocaramba.Types;9using Ocaramba.Helpers;10using Ocaramba.UITests.TestHelpers;11using NUnit.Framework;12using OpenQA.Selenium;13using OpenQA.Selenium.Remote;14{15 {16 private readonly string _cutOutScreenShotPath = @"C:\Temp\cutOutScreenShot.png";17 public void CutOutScreenShotTest()18 {19 TakeScreenShot.CutOutScreenShot(DriverContext.Current.Driver, new Point(0, 0), new Size(800, 600), _cutOutScreenShotPath);20 Assert.IsTrue(System.IO.File.Exists(_cutOutScreenShotPath));21 System.IO.File.Delete(_cutOutScreenShotPath);22 }23 }24}25using System;26using System.Collections.Generic;27using System.Linq;28using System.Text;29using System.Threading.Tasks;30using Ocaramba;31using Ocaramba.Extensions;32using Ocaramba.Types;33using Ocaramba.Helpers;34using Ocaramba.UITests.TestHelpers;35using NUnit.Framework;36using OpenQA.Selenium;37using OpenQA.Selenium.Remote;38{39 {40 private readonly string _cutOutScreenShotPath = @"C:\Temp\cutOutScreenShot.png";41 public void CutOutScreenShotTest()42 {43 TakeScreenShot.CutOutScreenShot(DriverContext.Current.Driver, new Point(0, 0), new Size(800, 600), _cutOutScreenShotPath);44 Assert.IsTrue(System.IO.File.Exists(_cutOutScreenShotPath));

Full Screen

Full Screen

CutOutScreenShot

Using AI Code Generation

copy

Full Screen

1using System;2using System.Drawing;3using System.Drawing.Imaging;4using System.IO;5using System.Reflection;6using System.Threading;7using System.Windows.Forms;8using NUnit.Framework;9using Ocaramba;10using Ocaramba.Extensions;11using Ocaramba.Helpers;12using Ocaramba.Types;13using OpenQA.Selenium;14using OpenQA.Selenium.Support.UI;15using OpenQA.Selenium.Interactions;16using OpenQA.Selenium.Remote;17using System.Collections.Generic;18using System.Linq;19using System.Text;20using System.Threading.Tasks;21{22 {23 public void TestMethod()24 {25 var currentTest = TestContext.CurrentContext.Test.Name;26 var currentDir = TestContext.CurrentContext.TestDirectory;27 var currentAssembly = Assembly.GetExecutingAssembly().GetName().Name;28 var currentAssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);29 var currentAssemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);30 Assert.AreEqual("Google", this.Driver.Title);31 var screenshot = ((ITakesScreenshot)this.Driver).GetScreenshot();32 screenshot.SaveAsFile(currentDir + "\\" + currentTest + ".png", ScreenshotImageFormat.Png);33 var screenShot = new TakeScreenShot(this.Driver);34 screenShot.CutOutScreenShot(new Point(0, 0), new Size(100, 100), currentDir + "\\" + currentTest + "_part.png");35 }36 }37}38using System;39using System.Drawing;40using System.Drawing.Imaging;41using System.IO;42using System.Reflection;43using System.Threading;44using System.Windows.Forms;45using NUnit.Framework;46using Ocaramba;47using Ocaramba.Extensions;48using Ocaramba.Helpers;49using Ocaramba.Types;50using OpenQA.Selenium;51using OpenQA.Selenium.Support.UI;52using OpenQA.Selenium.Interactions;53using OpenQA.Selenium.Remote;54using System.Collections.Generic;55using System.Linq;56using System.Text;57using System.Threading.Tasks;58{59 {

Full Screen

Full Screen

CutOutScreenShot

Using AI Code Generation

copy

Full Screen

1using System.Drawing;2using System.Drawing.Imaging;3using System.IO;4using Ocaramba;5using Ocaramba.Extensions;6using Ocaramba.Helpers;7using NUnit.Framework;8using Ocaramba.Types;9using System;10{11 {12 public void CutOutScreenShotTest()13 {14 var path = Path.Combine(Directory.GetCurrentDirectory(), "cutOutScreenShot.png");15 var expected = new Bitmap(path);16 var element = this.Driver.FindElement(By.Id("image"));17 var elementLocation = element.Location;18 var elementSize = element.Size;19 var rectangle = new Rectangle(elementLocation.X, elementLocation.Y, elementSize.Width, elementSize.Height);20 var actual = TakeScreenShot.CutOutScreenShot(this.Driver, rectangle);21 Assert.AreEqual(expected.Height, actual.Height);22 Assert.AreEqual(expected.Width, actual.Width);23 Assert.AreEqual(expected.PixelFormat, actual.PixelFormat);24 }25 }26}27using System.Drawing;28using System.Drawing.Imaging;29using System.IO;30using Ocaramba;31using Ocaramba.Extensions;32using Ocaramba.Helpers;33using NUnit.Framework;34using Ocaramba.Types;35using System;36{37 {38 public void TakeScreenShotTest()39 {40 var path = Path.Combine(Directory.GetCurrentDirectory(), "screenShot.png");41 var expected = new Bitmap(path);42 var actual = TakeScreenShot.TakeScreenShot(this.Driver);43 Assert.AreEqual(expected.Height, actual.Height);44 Assert.AreEqual(expected.Width, actual.Width);45 Assert.AreEqual(expected.PixelFormat, actual.PixelFormat);46 }47 }48}49using System.Drawing;50using System.Drawing.Imaging;51using System.IO;52using Ocaramba;53using Ocaramba.Extensions;54using Ocaramba.Helpers;55using NUnit.Framework;56using Ocaramba.Types;57using System;58{

Full Screen

Full Screen

CutOutScreenShot

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Ocaramba;7using Ocaramba.Extensions;8using Ocaramba.Types;9using NUnit.Framework;10using NUnit.Framework.Interfaces;11using OpenQA.Selenium;12{13 {14 public CutOutScreenShotTest(ParallelConfig parallelConfig) : base(parallelConfig)15 {16 }17 public void CutOutScreenShotTest1()18 {19 this.Driver.WaitForPageLoaded();20 var element = this.Driver.FindElement(By.Id("wrongId"));21 var cutOutScreenShot = new CutOutScreenShot(this.Driver);22 cutOutScreenShot.CutOutScreenShot(element, "WrongId");23 }24 }25}26using System;27using System.Collections.Generic;28using System.Linq;29using System.Text;30using System.Threading.Tasks;31using Ocaramba;32using Ocaramba.Extensions;33using Ocaramba.Types;34using NUnit.Framework;35using NUnit.Framework.Interfaces;36using OpenQA.Selenium;37{38 {39 public CutOutScreenShotTest(ParallelConfig parallelConfig) : base(parallelConfig)40 {41 }42 public void CutOutScreenShotTest1()43 {44 this.Driver.WaitForPageLoaded();45 var element = this.Driver.FindElement(By.Id("wrongId"));46 var cutOutScreenShot = new CutOutScreenShot(this.Driver);47 cutOutScreenShot.CutOutScreenShot(element, "WrongId");48 }49 }50}

Full Screen

Full Screen

CutOutScreenShot

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Reflection;4using System.Windows.Forms;5using Ocaramba;6using Ocaramba.Helpers;7using Ocaramba.Types;8using NUnit.Framework;9{10 {11 public void TestMethod()12 {13 string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);14 TakeScreenShot.CutOutScreenShot(path, "5.png", new Rectangle(0, 0, 500, 500));15 }16 }17}18using System;19using System.IO;20using System.Reflection;21using System.Windows.Forms;22using Ocaramba;23using Ocaramba.Helpers;24using Ocaramba.Types;25using NUnit.Framework;26{27 {28 public void TestMethod()29 {30 string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);31 TakeScreenShot.CutOutScreenShot(path, "6.png", Rectangle.Empty);32 }33 }34}35using System;36using System.IO;37using System.Reflection;38using System.Windows.Forms;39using Ocaramba;40using Ocaramba.Helpers;41using Ocaramba.Types;42using NUnit.Framework;43{44 {45 public void TestMethod()46 {47 string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);48 TakeScreenShot.CutOutScreenShot(path, "7.png");49 }50 }51}

Full Screen

Full Screen

CutOutScreenShot

Using AI Code Generation

copy

Full Screen

1public void TestMethod1()2{3 var driver = new FirefoxDriver();4 TakeScreenShot.CutOutScreenShot(driver, "D:\\test.png", 100, 100, 200, 200);5 Assert.AreEqual("Google", driver.Title);6}7public void TestMethod1()8{9 var driver = new FirefoxDriver();10 TakeScreenShot.CutOutScreenShot(driver, "D:\\test.png", 100, 100, 200, 200);11 Assert.AreEqual("Google", driver.Title);12}13public void TestMethod1()14{15 var driver = new FirefoxDriver();16 TakeScreenShot.CutOutScreenShot(driver, "D:\\test.png", 100, 100, 200, 200);17 Assert.AreEqual("Google", driver.Title);18}19public void TestMethod1()20{21 var driver = new FirefoxDriver();22 TakeScreenShot.CutOutScreenShot(driver, "D:\\test.png", 100, 100, 200, 200);23 Assert.AreEqual("Google", driver.Title);24}

Full Screen

Full Screen

CutOutScreenShot

Using AI Code Generation

copy

Full Screen

1using System;2using System.Drawing;3using System.IO;4using System.Reflection;5using System.Windows.Forms;6using Occasional_Bot;7using Occasional_Bot.Properties;8using Occasional_Bot.UI;9using Occasional_Bot.UI.Forms;10using Occasional_Bot.UI.Forms.MainForm;11using Occasional_Bot.UI.Forms.MainForm.Controls;12using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm;13using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls;14using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm;15using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls;16using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm;17using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls;18using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm;19using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm.Controls;20using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm;21using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls;22using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm;23using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls;24using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm;25using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls;26using Occasional_Bot.UI.Forms.MainForm.Controls.SettingsForm.Controls.AccountsForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm.Controls.AccountForm;

Full Screen

Full Screen

CutOutScreenShot

Using AI Code Generation

copy

Full Screen

1string path = @"C:\Users\Public\Pictures\Sample Pictures\test.png";2Ocaramba.Helpers.TakeScreenShot.CutOutScreenShot(0, 0, 100, 100, path);3string path = @"C:\Users\Public\Pictures\Sample Pictures\test.png";4Ocaramba.Helpers.TakeScreenShot.CutOutScreenShot(0, 0, 100, 100, path);5string path = @"C:\Users\Public\Pictures\Sample Pictures\test.png";6Ocaramba.Helpers.TakeScreenShot.CutOutScreenShot(0, 0, 100, 100, path);7string path = @"C:\Users\Public\Pictures\Sample Pictures\test.png";8Ocaramba.Helpers.TakeScreenShot.CutOutScreenShot(0, 0, 100, 100, path);9string path = @"C:\Users\Public\Pictures\Sample Pictures\test.png";10Ocaramba.Helpers.TakeScreenShot.CutOutScreenShot(0, 0, 100, 100, path);

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