How to use GetFileByName method of Ocaramba.Helpers.FilesHelper class

Best Ocaramba code snippet using Ocaramba.Helpers.FilesHelper.GetFileByName

FilesHelper.cs

Source:FilesHelper.cs Github

copy

Full Screen

...210 /// </summary>211 /// <param name="folder">The folder</param>212 /// <param name="fileName">The file name</param>213 /// <returns>FileInfo of file</returns>214 public static FileInfo GetFileByName(string folder, string fileName)215 {216 Logger.Debug("Get File '{0}' from '{1}'", fileName, folder);217 FileInfo file =218 new DirectoryInfo(folder)219 .GetFiles(fileName).First();220 return file;221 }222 /// <summary>223 /// Counts the files of given type.224 /// </summary>225 /// <param name="folder">The folder.</param>226 /// <param name="type">The type.</param>227 /// <returns>228 /// Number of files in subfolder229 /// </returns>230 /// <example>How to use it: <code>231 /// var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder, FileType.Txt);232 /// </code></example>233 public static int CountFiles(string folder, FileType type)234 {235 Logger.Debug(CultureInfo.CurrentCulture, "Count {0} Files in '{1}'", type, folder);236 var fileNumber = GetFilesOfGivenType(folder, type).Count;237 Logger.Debug(CultureInfo.CurrentCulture, "Number of files in '{0}': {1}", folder, fileNumber);238 return fileNumber;239 }240 /// <summary>241 /// Counts the files.242 /// </summary>243 /// <param name="folder">The folder.</param>244 /// <returns>245 /// Number of files in subfolder246 /// </returns>247 /// <example>How to use it: <code>248 /// var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder);249 /// </code></example>250 public static int CountFiles(string folder)251 {252 Logger.Debug(CultureInfo.CurrentCulture, "Count all Files in '{0}'", folder);253 var fileNumber = GetAllFiles(folder).Count;254 Logger.Debug(CultureInfo.CurrentCulture, "Number of files in '{0}': {1}", folder, fileNumber);255 return fileNumber;256 }257 /// <summary>258 /// Gets the last file of given type.259 /// </summary>260 /// <param name="folder">The folder.</param>261 /// <param name="type">The type of file.</param>262 /// <returns>Last file of given type</returns>263 /// <example>How to use it: <code>264 /// FilesHelper.GetLastFile(this.DriverContext.ScreenShotFolder, FileType.Png);265 /// </code></example>266 public static FileInfo GetLastFile(string folder, FileType type)267 {268 Logger.Debug(CultureInfo.CurrentCulture, "Get Last File of given type {0}", type);269 var lastFile =270 new DirectoryInfo(folder).GetFiles()271 .Where(f => f.Extension == ReturnFileExtension(type))272 .OrderByDescending(f => f.LastWriteTime)273 .First();274 Logger.Trace("Last File: {0}", lastFile);275 return lastFile;276 }277 /// <summary>278 /// Gets the last file.279 /// </summary>280 /// <param name="folder">The folder.</param>281 /// <returns>282 /// Last file of given type283 /// </returns>284 /// <example>How to use it: <code>285 /// FilesHelper.GetLastFile(this.DriverContext.ScreenShotFolder);286 /// </code></example>287 public static FileInfo GetLastFile(string folder)288 {289 Logger.Debug("Get Last File");290 var lastFile = new DirectoryInfo(folder).GetFiles()291 .OrderByDescending(f => f.LastWriteTime)292 .First();293 Logger.Trace("Last File: {0}", lastFile);294 return lastFile;295 }296 /// <summary>297 /// Waits for file of given type for given timeout till number of files increase in sub folder,checks the size of the current file.298 /// </summary>299 /// <param name="type">The type of file.</param>300 /// <param name="waitTime">Wait timeout</param>301 /// <param name="filesNumber">The initial files number.</param>302 /// <param name="folder">The folder.</param>303 /// <param name="checkSize">Check if the size, in bytes, of the current file > 0.</param>304 /// <example>How to use it: <code>305 /// var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder, FileType.Txt);306 /// this.Driver.GetElement(this.fileLink.Format("some-file.txt")).Click();307 /// FilesHelper.WaitForFileOfGivenType(FileType.Txt, BaseConfiguration.LongTimeout, filesNumber, this.DriverContext.DownloadFolder);308 /// </code></example>309 public static void WaitForFileOfGivenType(FileType type, double waitTime, int filesNumber, string folder, bool checkSize)310 {311 Logger.Debug("Wait for file: {0}", type);312 var timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Waiting for file number to increase in {0}", folder);313 WaitHelper.Wait(314 () => CountFiles(folder, type) > filesNumber, TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);315 Logger.Debug("Number of files increased");316 if (checkSize)317 {318 Logger.Debug("Checking if size of last file of given type {0} > 0 bytes", type);319 timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Checking if size of last file of given type {0} > 0 bytes", type);320 WaitHelper.Wait(321 () => GetLastFile(folder, type).Length > 0, TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);322 }323 }324 /// <summary>325 /// Waits for file of given type for LongTimeout till number of files increase in sub folder, checks the size of the current file.326 /// </summary>327 /// <param name="type">The type.</param>328 /// <param name="filesNumber">The files number.</param>329 /// <param name="folder">The folder.</param>330 /// <example>How to use it: <code>331 /// var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder, FileType.Txt);332 /// this.Driver.GetElement(this.fileLink.Format("some-file.txt")).Click();333 /// FilesHelper.WaitForFileOfGivenType(FileType.Txt, filesNumber, this.DriverContext.DownloadFolder);334 /// </code></example>335 public static void WaitForFileOfGivenType(FileType type, int filesNumber, string folder)336 {337 WaitForFileOfGivenType(type, BaseConfiguration.LongTimeout, filesNumber, folder, true);338 }339 /// <summary>340 /// Waits for file with given name with given timeout, checks the size of the current file.341 /// </summary>342 /// <param name="waitTime">Wait timeout</param>343 /// <param name="filesName">Name of the files.</param>344 /// <param name="folder">The folder.</param>345 /// <param name="checkSize">If true, check the size, in bytes, of the current file > 0.</param>346 /// <example>How to use it: <code>347 /// var file = "some-file.txt"348 /// this.Driver.GetElement(this.fileLink.Format(file), "Click on file").Click();349 /// FilesHelper.WaitForFileOfGivenName(BaseConfiguration.LongTimeout, file, this.DriverContext.DownloadFolder, true);350 /// </code></example>351 public static void WaitForFileOfGivenName(double waitTime, string filesName, string folder, bool checkSize)352 {353 Logger.Debug(CultureInfo.CurrentCulture, "Wait for file: {0}", filesName);354 var timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Waiting for file {0} in folder {1}", filesName, folder);355 WaitHelper.Wait(356 () => File.Exists(folder + Separator + filesName), TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);357 Logger.Debug("File exists");358 if (checkSize)359 {360 Logger.Debug("Checking if size of last file > 0 bytes");361 timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Checking if size of file {0} > 0 bytes", filesName);362 WaitHelper.Wait(363 () => GetFileByName(folder, filesName).Length > 0, TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);364 }365 }366 /// <summary>367 /// Waits for file with given name with given timeout, checks the size of the current file.368 /// </summary>369 /// <param name="waitTime">Wait timeout</param>370 /// <param name="filesName">Name of the files.</param>371 /// <param name="folder">The folder.</param>372 /// <example>How to use it: <code>373 /// var file = "some-file.txt"374 /// this.Driver.GetElement(this.fileLink.Format(file), "Click on file").Click();375 /// FilesHelper.WaitForFileOfGivenName(BaseConfiguration.LongTimeout, file, this.DriverContext.DownloadFolder);376 /// </code></example>377 public static void WaitForFileOfGivenName(double waitTime, string filesName, string folder)...

Full Screen

Full Screen

GetFileByName

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.Helpers;8using NUnit.Framework;9using OpenQA.Selenium;10using OpenQA.Selenium.Chrome;11using System.IO;12using System.Reflection;13{14 {15 public void GetFileByNameTest()16 {17 string filePath = FilesHelper.GetFileByName(@"..\..\TestFiles", "testFile.txt");18 Assert.AreEqual(@"..\..\TestFiles\testFile.txt", filePath);19 }20 }21}

Full Screen

Full Screen

GetFileByName

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using NUnit.Framework;4{5 {6 public void GetFileByNameTest()7 {8 var filePath = FilesHelper.GetFileByName(@"C:\Users\Public\Pictures\Sample Pictures", "Chrysanthemum.jpg");9 Assert.AreEqual(@"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg", filePath);10 }11 }12}13using Ocaramba;14using Ocaramba.Helpers;15using NUnit.Framework;16{17 {18 public void GetFileByNameTest()19 {20 var filePath = FilesHelper.GetFileByName(@"C:\Users\Public\Pictures\Sample Pictures", "Chrysanthemum.jpg");21 Assert.AreEqual(@"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg", filePath);22 }23 }24}25using Ocaramba;26using Ocaramba.Helpers;27using NUnit.Framework;28{29 {30 public void GetFileByNameTest()31 {32 var filePath = FilesHelper.GetFileByName(@"C:\Users\Public\Pictures\Sample Pictures", "Chrysanthemum.jpg");33 Assert.AreEqual(@"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg", filePath);34 }35 }36}37using Ocaramba;38using Ocaramba.Helpers;39using NUnit.Framework;40{41 {42 public void GetFileByNameTest()43 {44 var filePath = FilesHelper.GetFileByName(@"C:\Users\Public\Pictures\Sample Pictures", "Chrysanthemum.jpg");45 Assert.AreEqual(@"C:\Users

Full Screen

Full Screen

GetFileByName

Using AI Code Generation

copy

Full Screen

1public void TestMethod()2{3FilesHelper filesHelper = new FilesHelper();4string filePath = filesHelper.GetFileByName(@"C:\Users\Public\Documents", "test.txt");5Console.WriteLine(filePath);6}7public void TestMethod()8{9FilesHelper filesHelper = new FilesHelper();10string[] filePaths = filesHelper.GetFilesByExtension(@"C:\Users\Public\Documents", ".txt");11foreach (string path in filePaths)12{13Console.WriteLine(path);14}15}16public void TestMethod()17{18FilesHelper filesHelper = new FilesHelper();19string[] filePaths = filesHelper.GetFilesByExtension(@"C:\Users\Public\Documents", ".txt");20foreach (string path in filePaths)21{22Console.WriteLine(path);23}24}25public void TestMethod()26{27FilesHelper filesHelper = new FilesHelper();28string[] filePaths = filesHelper.GetFilesByExtension(@"C:\Users\Public\Documents", ".txt");29foreach (string path in filePaths)30{31Console.WriteLine(path);32}33}34public void TestMethod()35{36FilesHelper filesHelper = new FilesHelper();37string[] filePaths = filesHelper.GetFilesByExtension(@"C:\Users\Public\Documents", ".txt");38foreach (string path in filePaths)39{40Console.WriteLine(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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful