Пример #1
0
        /// <summary>
        /// Copy the file and check if file was copied with given timeout, shorten the name of file if needed be removing "_".
        /// </summary>
        /// <param name="waitTime">Timeout for checking if file was removed</param>
        /// <param name="oldName">The old name.</param>
        /// <param name="newName">The new name.</param>
        /// <param name="oldSubFolder">The old subFolder.</param>
        /// <param name="newSubFolder">The new subFolder.</param>
        /// <returns>The new name in case its shorten</returns>
        /// <example>How to use it: <code>
        /// FilesHelper.CopyFile(BaseConfiguration.ShortTimeout, fileName, newName, this.DriverContext.DownloadFolder + "\\", this.DriverContext.DownloadFolder + "\\");
        /// </code></example>
        public static string CopyFile(double waitTime, string oldName, string newName, string oldSubFolder, string newSubFolder)
        {
            Logger.Debug(CultureInfo.CurrentCulture, "new file name: {0}\\{1}", newSubFolder, newName);

            newName = NameHelper.ShortenFileName(newSubFolder, newName, "_", 255);

            if (File.Exists(newSubFolder + Separator + newName))
            {
                File.Delete(newSubFolder + Separator + newName);
            }

            // Use ProcessStartInfo class
            string command = "/c copy " + '\u0022' + oldName + '\u0022' + " " + '\u0022' + newSubFolder + Separator + newName +
                             '\u0022';
            ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe")
            {
                WorkingDirectory = oldSubFolder,
                Arguments        = command
            };

            Thread.Sleep(1000);

            var timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Waiting till file will be copied {0}", newSubFolder);

            Process.Start(cmdsi);
            WaitHelper.Wait(() => File.Exists(newSubFolder + Separator + newName), TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);
            return(newName);
        }
Пример #2
0
        /// <summary>
        /// Waits for file with given name with given timeout, checks  the size of the current file.
        /// </summary>
        /// <param name="waitTime">Wait timeout</param>
        /// <param name="filesName">Name of the files.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="checkSize">If true, check the size, in bytes, of the current file > 0.</param>
        /// <example>How to use it: <code>
        /// var file = "some-file.txt"
        /// this.Driver.GetElement(this.fileLink.Format(file), "Click on file").Click();
        /// FilesHelper.WaitForFileOfGivenName(BaseConfiguration.LongTimeout, file, this.DriverContext.DownloadFolder, true);
        /// </code></example>
        public static void WaitForFileOfGivenName(double waitTime, string filesName, string folder, bool checkSize)
        {
            Logger.Debug(CultureInfo.CurrentCulture, "Wait for file: {0}", filesName);
            var timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Waiting for file {0} in folder {1}", filesName, folder);

            WaitHelper.Wait(
                () => File.Exists(folder + Separator + filesName), TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);

            Logger.Debug("File exists");
            if (checkSize)
            {
                Logger.Debug("Checking if size of last file > 0 bytes");
                timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Checking if size of file {0} > 0 bytes", filesName);
                WaitHelper.Wait(
                    () => GetFileByName(folder, filesName).Length > 0, TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);
            }
        }
Пример #3
0
        /// <summary>
        /// Waits for file for given timeout till number of files increase in sub folder, checks  the size of the current file.
        /// </summary>
        /// <param name="waitTime">Wait timeout</param>
        /// <param name="filesNumber">The initial files number.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="checkSize">Check if  the size, in bytes, of the current file > 0.</param>
        /// <example>How to use it:<code>
        /// var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder);
        /// this.Driver.GetElement(this.fileLink.Format("some-file.txt")).Click();
        /// FilesHelper.WaitForFile(BaseConfiguration.LongTimeout, filesNumber, this.DriverContext.DownloadFolder, true);
        /// </code></example>
        public static void WaitForFile(double waitTime, int filesNumber, string folder, bool checkSize)
        {
            Logger.Debug("Wait for file");
            var timeoutMessage = string.Format(CultureInfo.CurrentCulture, "Waiting for file number to increase in {0}", folder);

            WaitHelper.Wait(
                () => CountFiles(folder) > filesNumber, TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);

            Logger.Debug("Number of files increased");

            if (checkSize)
            {
                Logger.Debug("checking if size of last file > 0 bytes");
                timeoutMessage = "Checking if size of last file > 0 bytes";

                WaitHelper.Wait(
                    () => GetLastFile(folder).Length > 0, TimeSpan.FromSeconds(waitTime), TimeSpan.FromSeconds(1), timeoutMessage);
            }
        }