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

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

FilesHelper.cs

Source:FilesHelper.cs Github

copy

Full Screen

...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)378 {379 WaitForFileOfGivenName(waitTime, filesName, folder, true);380 }381 /// <summary>382 /// Waits for file of given name with LongTimeout, checks the size of the current file.383 /// </summary>384 /// <param name="filesName">Name of the files.</param>385 /// <param name="folder">The folder.</param>386 /// <example>How to use it: <code>387 /// var file = "some-file.txt"388 /// this.Driver.GetElement(this.fileLink.Format(file), "Click on file").Click();389 /// FilesHelper.WaitForFileOfGivenName(file, this.DriverContext.DownloadFolder);390 /// </code></example>391 public static void WaitForFileOfGivenName(string filesName, string folder)392 {393 WaitForFileOfGivenName(BaseConfiguration.LongTimeout, filesName, folder);394 }395 /// <summary>396 /// Waits for file of given name with LongTimeout, checks the size of the current file.397 /// </summary>398 /// <param name="filesName">Name of the files.</param>399 /// <param name="folder">The folder.</param>400 /// <param name="checkSize">Check if the size, in bytes, of the current file > 0.</param>401 /// <example>How to use it: <code>402 /// var file = "some-file.txt"403 /// this.Driver.GetElement(this.fileLink.Format(file), "Click on file").Click();404 /// FilesHelper.WaitForFileOfGivenName(file, this.DriverContext.DownloadFolder, true);405 /// </code></example>406 public static void WaitForFileOfGivenName(string filesName, string folder, bool checkSize)407 {408 WaitForFileOfGivenName(BaseConfiguration.LongTimeout, filesName, folder, checkSize);409 }410 /// <summary>411 /// Waits for file for given timeout till number of files increase in sub folder, checks the size of the current file.412 /// </summary>413 /// <param name="waitTime">Wait timeout</param>414 /// <param name="filesNumber">The initial files number.</param>415 /// <param name="folder">The folder.</param>416 /// <param name="checkSize">Check if the size, in bytes, of the current file > 0.</param>417 /// <example>How to use it:<code>418 /// var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder);419 /// this.Driver.GetElement(this.fileLink.Format("some-file.txt")).Click();420 /// FilesHelper.WaitForFile(BaseConfiguration.LongTimeout, filesNumber, this.DriverContext.DownloadFolder, true);421 /// </code></example>422 public static void WaitForFile(double waitTime, int filesNumber, string folder, bool checkSize)423 {424 Logger.Debug("Wait for file");425 var timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Waiting for file number to increase in {0}", folder);426 WaitHelper.Wait(427 () => CountFiles(folder) > filesNumber, TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);428 Logger.Debug("Number of files increased");429 if (checkSize)430 {431 Logger.Debug("checking if size of last file > 0 bytes");432 timeoutMessage = "Checking if size of last file > 0 bytes";433 WaitHelper.Wait(434 () => GetLastFile(folder).Length > 0, TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);435 }436 }437 /// <summary>438 /// Waits for file with LongTimeout till number of files increase in sub folder, checks the size of the current file.439 /// </summary>440 /// <param name="filesNumber">The initial files number.</param>441 /// <param name="folder">The folder.</param>442 /// <example>How to use it: <code>443 /// var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder);444 /// this.Driver.GetElement(this.fileLink.Format("some-file.txt")).Click();445 /// FilesHelper.WaitForFile(filesNumber, this.DriverContext.DownloadFolder);446 /// </code></example>447 public static void WaitForFile(int filesNumber, string folder)448 {449 WaitForFile(BaseConfiguration.LongTimeout, filesNumber, folder, true);450 }451 /// <summary>452 /// Rename the file and check if file was renamed with given timeout, shorten the name of file if needed be removing "_".453 /// </summary>454 /// <param name="waitTime">Timeout for checking if file was removed</param>455 /// <param name="oldName">The old name.</param>456 /// <param name="newName">The new name.</param>457 /// <param name="subFolder">The subFolder.</param>458 /// <returns>The new name in case its shorten</returns>459 /// <example>How to use it: <code>460 /// string newName = FilesHelper.RenameFile(BaseConfiguration.ShortTimeout, "filename.txt", "newname.txt", this.DriverContext.DownloadFolder);461 /// </code></example>462 public static string RenameFile(double waitTime, string oldName, string newName, string subFolder)463 {...

Full Screen

Full Screen

DownloadPage.cs

Source:DownloadPage.cs Github

copy

Full Screen

...54 || BaseConfiguration.TestBrowser == BrowserType.Chrome55 || BaseConfiguration.TestBrowser == BrowserType.RemoteWebDriver)56 {57 this.Driver.GetElement(this.fileLink.Format(fileName), "Click on file").Click();58 FilesHelper.WaitForFileOfGivenName(fileName, this.DriverContext.DownloadFolder, false);59 FilesHelper.RenameFile(fileName, newName, this.DriverContext.DownloadFolder, FileType.Csv);60 }61 else62 {63 Logger.Info(CultureInfo.CurrentCulture, "Downloading files in browser {0} is not supported", BaseConfiguration.TestBrowser);64 }65 return this;66 }67 public DownloadPage SaveFile(string newName)68 {69 if (BaseConfiguration.TestBrowser == BrowserType.Firefox70 || BaseConfiguration.TestBrowser == BrowserType.Chrome71 || BaseConfiguration.TestBrowser == BrowserType.RemoteWebDriver)72 {73 var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder, FileType.Txt);74 this.Driver.GetElement(this.fileLink.Format("ObjectivityTestAutomationCSHarpFramework.txt")).Click();75 FilesHelper.WaitForFileOfGivenType(FileType.Txt, filesNumber, this.DriverContext.DownloadFolder);76 FileInfo file = FilesHelper.GetLastFile(this.DriverContext.DownloadFolder, FileType.Txt);77 FilesHelper.RenameFile(file.Name, newName, this.DriverContext.DownloadFolder, FileType.Txt);78 }79 else80 {81 Logger.Info(CultureInfo.CurrentCulture, "Downloading files in browser {0} is not supported", BaseConfiguration.TestBrowser);82 }83 return this;84 }85 public DownloadPage SaveAnyFile()86 {87 if (BaseConfiguration.TestBrowser == BrowserType.Firefox88 || BaseConfiguration.TestBrowser == BrowserType.Chrome89 || BaseConfiguration.TestBrowser == BrowserType.RemoteWebDriver)90 {91 var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder);92 this.Driver.GetElement(this.fileLink.Format("ObjectivityTestAutomationCSHarpFramework.txt")).Click();93 FilesHelper.WaitForFile(filesNumber, this.DriverContext.DownloadFolder);94 FileInfo file = FilesHelper.GetLastFile(this.DriverContext.DownloadFolder);95 FilesHelper.RenameFile(BaseConfiguration.ShortTimeout, file.Name, "name_of_file_branch.txt", this.DriverContext.DownloadFolder);96 }97 else98 {99 Logger.Info(CultureInfo.CurrentCulture, "Downloading files in browser {0} is not supported", BaseConfiguration.TestBrowser);100 }101 return this;102 }103 public string CheckIfScreenShotIsSaved(int screenShotNumber)104 {105 Logger.Info(CultureInfo.CurrentCulture, "Number of files {0}", screenShotNumber);106 FilesHelper.WaitForFileOfGivenType(FileType.Png, 10, screenShotNumber, this.DriverContext.ScreenShotFolder, true);107 var nameOfFile = FilesHelper.GetLastFile(this.DriverContext.ScreenShotFolder, FileType.Png);108 return nameOfFile.FullName;109 }110 public string SaveWebDriverScreenShot()111 {112 return this.DriverContext.SaveScreenshot(new ErrorDetail(this.DriverContext.TakeScreenshot(), DateTime.Now, null), this.DriverContext.ScreenShotFolder, this.DriverContext.TestTitle);113 }114 }115}...

Full Screen

Full Screen

WaitForFile

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using Microsoft.VisualStudio.TestTools.UnitTesting;4using System.Threading;5{6 {7 public void TestMethod1()8 {9 FilesHelper.WaitForFile(@"C:\Users\Public\TestFolder\test.txt", 10);10 FilesHelper.DeleteFile(@"C:\Users\Public\TestFolder\test.txt");11 }12 }13}14using Ocaramba;15using Ocaramba.Helpers;16using Microsoft.VisualStudio.TestTools.UnitTesting;17using System.Threading;18{19 {20 public void TestMethod1()21 {22 FilesHelper.WaitForFile(@"C:\Users\Public\TestFolder\test.txt", 10);23 FilesHelper.DeleteFile(@"C:\Users\Public\TestFolder\test.txt");24 }25 }26}27using Ocaramba;28using Ocaramba.Helpers;29using Microsoft.VisualStudio.TestTools.UnitTesting;30using System.Threading;31{32 {33 public void TestMethod1()34 {35 FilesHelper.WaitForFile(@"C:\Users\Public\TestFolder\test.txt", 10);36 FilesHelper.DeleteFile(@"C:\Users\Public\TestFolder\test.txt");37 }38 }39}40using Ocaramba;41using Ocaramba.Helpers;42using Microsoft.VisualStudio.TestTools.UnitTesting;43using System.Threading;44{45 {46 public void TestMethod1()47 {48 FilesHelper.WaitForFile(@"C:\Users\Public\TestFolder\test.txt

Full Screen

Full Screen

WaitForFile

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using NUnit.Framework;4using System.IO;5using System;6{7 {8 public void WaitForFileTest()9 {10 var tempFile = Path.GetTempFileName();11 File.Delete(tempFile);12 var result = FilesHelper.WaitForFile(tempFile, TimeSpan.FromSeconds(30));13 Assert.IsFalse(result);14 }15 }16}

Full Screen

Full Screen

WaitForFile

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using NUnit.Framework;4using System;5using System.IO;6{7 {8 private string _pathToSaveFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.txt");9 public void WaitForFileTest()10 {11 FilesHelper.WaitForFile(_pathToSaveFile, 30);12 Assert.IsTrue(File.Exists(_pathToSaveFile));13 }14 }15}16using Ocaramba;17using Ocaramba.Helpers;18using NUnit.Framework;19using System;20using System.IO;21{22 {23 private string _pathToSaveFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.txt");24 public void WaitForFileTest()25 {26 FilesHelper.WaitForFile(_pathToSaveFile, 30);27 Assert.IsTrue(File.Exists(_pathToSaveFile));28 }29 }30}31using Ocaramba;32using Ocaramba.Helpers;33using NUnit.Framework;34using System;35using System.IO;36{37 {38 private string _pathToSaveFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.txt");39 public void WaitForFileTest()40 {41 FilesHelper.WaitForFile(_pathToSaveFile, 30);42 Assert.IsTrue(File.Exists(_pathToSaveFile));43 }44 }45}46using Ocaramba;47using Ocaramba.Helpers;48using NUnit.Framework;49using System;50using System.IO;51{52 {53 private string _pathToSaveFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.txt");54 public void WaitForFileTest()55 {56 FilesHelper.WaitForFile(_pathToSaveFile, 30);57 Assert.IsTrue(File.Exists(_pathToSave

Full Screen

Full Screen

WaitForFile

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Threading;4using Ocaramba;5using Ocaramba.Helpers;6using NUnit.Framework;7using System.Diagnostics;8{9 {10 private string testFile = "testfile.txt";11 private string testFile2 = "testfile2.txt";12 private string testFolder = "testfolder";13 private string testFolder2 = "testfolder2";14 private string testPath;15 private string testPath2;16 public void WaitForFile()17 {18 Directory.CreateDirectory(testFolder);19 File.Create(testFile);20 File.Move(testFile, testFolder + "\\" + testFile);21 testPath = Path.GetFullPath(testFolder + "\\" + testFile);22 FilesHelper.WaitForFile(testPath, 5000);23 Assert.IsTrue(File.Exists(testPath));24 File.Delete(testPath);25 Directory.Delete(testFolder);26 }27 public void WaitForFileWithTimeout()28 {29 Directory.CreateDirectory(testFolder2);30 testPath2 = Path.GetFullPath(testFolder2 + "\\" + testFile2);31 bool result = FilesHelper.WaitForFile(testPath2, 5000);32 Assert.IsFalse(File.Exists(testPath2));33 Directory.Delete(testFolder2);34 }35 public void WaitForFileWithWrongPath()36 {37 bool result = FilesHelper.WaitForFile("wrong path", 5000);38 Assert.IsFalse(result);39 }40 }41}42using System;43using System.IO;44using System.Threading;45using Ocaramba;46using Ocaramba.Helpers;

Full Screen

Full Screen

WaitForFile

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using Ocaramba;4using Ocaramba.Helpers;5using NUnit.Framework;6{7 {8 public void WaitForFile()9 {10 string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.txt");11 File.WriteAllText(path, "test");12 FilesHelper.WaitForFile(path, 20000);13 File.Delete(path);14 }15 }16}17using System;18using System.IO;19using Ocaramba;20using Ocaramba.Helpers;21using NUnit.Framework;22{23 {24 public void WaitForFile()25 {26 string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.txt");27 File.WriteAllText(path, "test");28 FilesHelper.WaitForFile(path, 20000);29 File.Delete(path);30 }31 }32}33using System;34using System.IO;35using Ocaramba;36using Ocaramba.Helpers;37using NUnit.Framework;38{39 {40 public void WaitForFile()41 {42 string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.txt");43 File.WriteAllText(path, "test");44 FilesHelper.WaitForFile(path, 20000);45 File.Delete(path);46 }47 }48}49using System;50using System.IO;51using Ocaramba;52using Ocaramba.Helpers;53using NUnit.Framework;54{55 {56 public void WaitForFile()57 {

Full Screen

Full Screen

WaitForFile

Using AI Code Generation

copy

Full Screen

1 {2 public void WaitForFileTest()3 {4 var filePath = @"C:\path\to\file\test.txt";5 var timeout = 30;6 FilesHelper.WaitForFile(filePath, timeout);7 Assert.True(File.Exists(filePath));8 }9 }10 {11 public void WaitForFileTest()12 {13 var filePath = @"C:\path\to\file\test.txt";14 var timeout = 30;15 FilesHelper.WaitForFile(filePath, timeout);16 Assert.True(File.Exists(filePath));17 }18 }19 {20 public void WaitForFileTest()21 {22 var filePath = @"C:\path\to\file\test.txt";23 var timeout = 30;24 FilesHelper.WaitForFile(filePath, timeout);25 Assert.True(File.Exists(filePath));26 }27 }28 {29 public void WaitForFileTest()30 {31 var filePath = @"C:\path\to\file\test.txt";32 var timeout = 30;33 FilesHelper.WaitForFile(filePath, timeout);34 Assert.True(File.Exists(filePath));35 }36 }37 {38 public void WaitForFileTest()39 {40 var filePath = @"C:\path\to\file\test.txt";41 var timeout = 30;

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