Save filename with current date

4 Answers 102 Views
Coded Steps Dialog Test Configuration Test Execution
Michael
Top achievements
Rank 1
Iron
Michael asked on 11 Sep 2023, 09:53 PM

Hi again.

Moving from iMb to Test Studio working out a few issues.

We save files using a name that includes the current date like below.

"New_File_all_all_20230911_001.csv"

We use the following string in iMb using a variable for the file number at the end(which we don't HAVE to have but it would be nice).

ONDOWNLOAD FOLDER=Z:\folder\folder_name\{{!NOW:yyyymmdd}} FILE=New_Filet_all_all_{{!NOW:yyyymmdd}}_00{{!VAR2}}.csv

Is this possible with Test Studio?

Thanks!

4 Answers, 1 is accepted

Sort by
1
Alexander
Telerik team
answered on 13 Sep 2023, 11:36 AM

Hi Michael,

To handle the download dialog I suggest using the "Download" step under "Dialogs" from the step builder. This step also gets recorded automatically if a download dialog is handled during a test recording session

It has a field where you can specify the download path. This field can also be bound to a predefined string variable from the step properties.

 

The desired download path is created in a coded step. Here is one way of doing it. 

--

            DateTime currentDate = DateTime.Now;
            string dateFormated = currentDate.ToString("yyyyMMdd");
            string fileName = "New_File_all_all_";
            int fileOrderNum = 1;
            
            StringBuilder sb = new StringBuilder();
            
            sb.Append(@"Z:\folder\folder_name\");
            sb.Append(fileName);
            sb.Append(dateFormated);
            sb.Append("_");
            sb.Append(fileOrderNum.ToString("000"));
            
            SetExtractedValue("DownloadFilePath", sb.ToString());  

--

DateTime.Now gets the current date then in "dateFormated" it is formatted in the desired format.

"fileName" contains the name of the file and it can be easily changed from there. The same goes for the "fileOrderNum". The logic of how to choose an order number is up to you. 

string builder creates the whole file path. The "000" in "ToString" is to add the leading zeros in the order number.

 

After the download path is created it must be set to the "Download" step. The first thing to do is to use the "SetExtractedValue" method. The first argument (DownloadFilePath) is value the is entered in the binding properties panel. The second is the value that is going to be used in the step.

When everything is set up select the "Download" step -> go to its properties -> select the three-dots drop-down menu next to "{Bindings}" -> enter the first argument of the :SetExtractedValue" method in the textbox -> click on "set"

 

I hope that this will help you.

Regards, Alexander Progress Telerik

Virtual Classroom is the free self-paced technical training portal that gets you up to speed with Telerik and Kendo UI products including Telerik Test Studio! Check it out at https://learn.telerik.com/.
Michael
Top achievements
Rank 1
Iron
commented on 13 Sep 2023, 05:30 PM | edited

Thank you for the reply!!

I will see what I can do with it.

One thing I forgot to mention was that the path would need to include the folder with today's date(20230913) as the filename and it would need to change each day to the updated date. Would that be possible to include?

Alexander
Telerik team
commented on 14 Sep 2023, 09:04 AM

Hi,

As long as you run the test that has the coded step, the date will be updated. 

If the folder in the path is not created before running the test, the "Download" handler will create it. This way you can add before the file name ("New_all_all_20230914_001.pdf) the date with some other text (or not) which will be the folder's name. 

           DateTime currentDate = DateTime.Now;
            string dateFormated = currentDate.ToString("yyyyMMdd");
            string fileName = "New_File_all_all_";

            string fileType= ".pdf";

            int fileOrderNum = 1;

            StringBuilder sb = new StringBuilder();

            sb.Append(@"Z:\folder\folder_name_");

           sb.Append(dateFormated);

           sb.Append(@"\");

            sb.Append(fileName);
            sb.Append(dateFormated);
            sb.Append("_");
            sb.Append(fileOrderNum.ToString("000"));
            sb.Append(fileType);

            SetExtractedValue("DownloadFilePath", sb.ToString());

-

 

Important thing that i have missed mentioning is that you have to specify the file type (e.g. ".pdf") at the end. Otherwise the file won't be saved properly.

The above step will create new folder for every new date. Then the downloaded files can be saved using different names.

Hope this was what you were looking for.

Regards, 
Alexander

 

                                    
Michael
Top achievements
Rank 1
Iron
commented on 05 Oct 2023, 02:57 PM | edited

Still not able to figure this out. We are not programmers and just don't have the skill to make it work. Waiting on my company to approve some consulting but that is taking forever and we are running out of time. Any way someone can just walk me through setting this up once or twice? This is the main thing stopping us from using Test Studio. 

Also had another thought. Would it be possible to do this using an Excel spreadsheet with cells populated with the dates we need? Like just have Test Studio link to a certain cell in the csv to grab the date and put it into the date box on the website.

Thanks!

 

1
Alexander
Telerik team
answered on 06 Oct 2023, 11:45 AM

Hi Michael,

Yes, it is possible to do it with excel. 

Using the data bind feature for external sources. 
First, create an Excel file. The first row of the file contains names which are used for the data bind.

Every row of these columns that is populated represents an iteration in the test. For example, if you have 3 rows that contains some text in the first column, that will run the test 3 times with each value of that column. The iterations can be seen after the test is completed above the test step panel.

After the file is created, use the binding tab section to bind it to your project.

Here is described how to bind an Excel file to you project.

Then the particular step that e.g enters text or handles download dialogs has to be bound to the specific column of the Excel file.
That is done from the step properties panel. See this article for step-by-step guide.

That's in general how to bind a data source to a test.

 

I am attaching a zip with a sample project made for your particular case with the download path (without any code). The test uses the first sheet of "Book1". All the formatting is done in sheet 2. 

Please keep in mind that formulas like "TODAY()" will not update automatically every single day.  To update them there is one manual step that has to be done one time per day before running the tests. Follow these steps:

Select the edit button of the bound Excel file. That will open the file. Check if everything is behaving as expected (e.g. dates from formulas are updated). Then save the file and close it.

Bound Excel files can be edited only this way. If you open them from your computer the changes won't apply.

 

That is how to achieve this without any code. However that is not a fully automated process. If you are still interested in the scenario with the coded step, I can make a sample project with it so its reusable for your application.

Also I want to mention that you have the option to contact us through a private support thread where we can discuss the case in further depth.

And if there is anything unclear about the sample project or the steps above, don't hesitate to ask.

Regards, Alexander Progress Telerik

Virtual Classroom is the free self-paced technical training portal that gets you up to speed with Telerik and Kendo UI products including Telerik Test Studio! Check it out at https://learn.telerik.com/.
Michael
Top achievements
Rank 1
Iron
commented on 06 Oct 2023, 12:49 PM

Thank you again for the reply! 
If you don't mind sending the sample of the first solution that would be great. Not being completely automated would be ok but we would rather not have to manually update it daily. I think most of my problem is I am unsure where everything goes when setting up the binding. A working example would help tremendously I think. Thank you!

1
Alexander
Telerik team
answered on 09 Oct 2023, 12:42 PM

Hi Michael, 

The sample project with the coded step is attached as a zip. 

Just switch the file path in the coded step with the one you are going to use. There are also comments added to help you better understand what each line is doing. You can also copy that step and reuse it for handling download dialogs in other projects. Just remember to bind the file path variable (explained in previous answers) with the "Handle Download Dialog" step.

If any questions occur while exploring the test, don't hesitate to ask. 

Regards,
Alexander
Progress Telerik

Virtual Classroom is the free self-paced technical training portal that gets you up to speed with Telerik and Kendo UI products including Telerik Test Studio! Check it out at https://learn.telerik.com/.
Michael
Top achievements
Rank 1
Iron
commented on 09 Oct 2023, 01:43 PM

Thank you so much Alexander! I will give this a shot today.

 

Michael
Top achievements
Rank 1
Iron
commented on 09 Oct 2023, 06:49 PM

Hi Alexander, I am having a problem executing the test. It will open the browser then close as soon as it is loaded. Does not go to the link in the test. I did change the path to a local folder just for testing purposes same drive with a different folder but I kept the _ after the folder name like it is in the test in the zip file. I don't remember if the path will create a folder in the file with the same date as we need in the filename or will it just save the file in the folder in the path? We do need it to create a folder like "Z:\folder\folder_name_20231009"

Below is the log.

Overall Result: NotRun
------------------------------------------------------------
'10/9/2023 1:37:32 PM' - Executing test: 'WebTest', path: 'WebTest.tstest.'
'10/9/2023 1:37:32 PM' - Using .Net Runtime version: '4.0.30319.42000' for test execution. Build version is '2023.2.801.1'.
'10/9/2023 1:37:32 PM' - Starting execution....
------------------------------------------------------------
'10/9/2023 1:37:32 PM' - Tip: The current monitor(s) setup is not at 100% scale!
For best recording and execution experience please set all monitor scaling to 100%.
'10/9/2023 1:37:44 PM' - Detected custom code in test. Locating test assembly: SavePathDemo.dll.
'10/9/2023 1:37:44 PM' - Assembly Found: Y:\shared folder\Telerik Test Studio\SavePathDemo\bin\SavePathDemo.dll
'10/9/2023 1:37:44 PM' - Loading code class: 'SavePathDemo.WebTest'.
------------------------------------------------------------
------------------------------------------------------------
'10/9/2023 1:37:44 PM' - Detected DataDriven Test. Starting data iterations.
'10/9/2023 1:37:44 PM' - There is no data to execute the test with.
------------------------------------------------------------
'10/9/2023 1:37:44 PM' - Overall Result: NotRun
'10/9/2023 1:37:44 PM' - Duration: [0 min: 0 sec: 2 msec]
------------------------------------------------------------
'10/9/2023 1:37:45 PM' - Test completed!
Alexander
Telerik team
commented on 10 Oct 2023, 10:16 AM

Hi Michael,

This is probably happening because the test from the last sample project i sent you is also bound to an excel file. Check the following steps and try executing again:

1. If the bound excel workbook is opened when starting the test, close it.

2. If the excel file is not needed anymore, unbound it from the project 

3. Check if the "handle dialog" step is bound to the value from the coded step

 

Start the test and if this happens again, let me now.

Michael
Top achievements
Rank 1
Iron
commented on 11 Oct 2023, 06:01 PM | edited

That worked thank you! I can run that test now no problem. 

Edited to remove question, it already did what I needed and I didn't catch it. 

Edited again for one more question.

Does the coded step have to be just before the download dialog or can it be at the beginning of the test then just bind each individual download dialog to the coded step? Say we have 10 files that will be downloaded 4 of them with one name ending with 001-004 then 3 of them with a different name ending in 001-003 and 3 more file named differently but need the end of the file name to be consecutive numbers. Would I need three individual coded steps then bind each download dialog step to the coded step needed for each set of different filenames?

Thanks again Alexander for your help!  

 

0
Alexander
Telerik team
answered on 12 Oct 2023, 12:41 PM

HI Micheal, 

I've attached the modified project.

What I've managed to do is to make a step which can be copied and then pasted before every "download dialog handler" step. 

With it the order number (that's how I called the "001" at the end of the file name) will increase with 1 for every download you make. If you run the same test twice e.g. it will stack the saved files even though they are the same:

for example:

file1_001
file2_002
file3_003
file1_004
file2_005
file3_006

 

If you don't want this to happen I've added another step which will clear the folder in which the files are saved. You can add it and just check/uncheck when you need it.

 

What is needed from your side it to enter the folder path and file type, file name (optional)

 

//enter folder path without dates (if not created locally it will be automatically), keep the "@"
        private string folderPath = @"C:\AK\Test Studio Tests\Demo Tests\SavePathDemo\SaveFolder";
        //enter file type with "." (dot) at the beggining
        private string fileType = ".pdf";
        private string fileName = "New_File_all_all_";

 

 

Hope this helps. If you want to change the name as well there is a way using "GetExtractedValue" method. If you have any other questions don't hesitate to ask.

Regards, Alexander Progress Telerik

Virtual Classroom is the free self-paced technical training portal that gets you up to speed with Telerik and Kendo UI products including Telerik Test Studio! Check it out at https://learn.telerik.com/.
Michael
Top achievements
Rank 1
Iron
commented on 20 Oct 2023, 05:33 PM

Alexander, 

Ok so I am back on this but I may be confused. I tried to copy and paste the "new coded step" into my test right before the download dialog handler and keep getting syntax errors. I tried to also copy and paste the code inside the step into a coded step and it was even worse. Any idea? I have not changed anything in the step until I get this error cleared. 

Thanks!

 

 

 

Alexander
Telerik team
commented on 23 Oct 2023, 12:41 PM

Hi Michael,

I see that you are using Visual Basic for this project. The coded steps I made were written in C#, so there will be differences in the syntax if you paste them in a VB environment. 

The easiest fix here will be to create a new project with the same steps but this time you have to choose C# instead of VB when creating a coded step for the first time. Then you can use the code as it is without the need to change anything.

However, if you insist on using VB, let me know and I'll convert the coded step so it can be used with VB.

Michael
Top achievements
Rank 1
Iron
commented on 23 Oct 2023, 02:49 PM

Thanks Alexander. Our background is with VB coming from iMacros so that would be super helpful if you could convert it. I do plan on eventually using C# but we are just trying to get everything moved over asap so we don't have a drop off in our data. 

Thanks again for your help!

Alexander
Telerik team
commented on 24 Oct 2023, 03:05 PM

Hi Michael,

Here is the new Visual Basic project with the changed coded step.

If you have any question, don't hesitate to ask.

Michael
Top achievements
Rank 1
Iron
commented on 24 Oct 2023, 04:33 PM

Thanks again Alexander! 
I am able to get the VB one to run but it is leaving out the date from the filename. It had the folder name correct except for an underscore at the beginning of the file name. I commented out that so the folder name is correct now but the file name is "New_File_all_all_002.pdf" instead of "New_File_all_all_20231024_002.pdf. It also starts with 002 instead of 001 and I can't seem to figure out how to change that.

Thank you!

 
Elena
Telerik team
commented on 25 Oct 2023, 01:02 PM

Hi Michael, 

There were small adjustments needed in the coded step - similar to the commented line you mentioned. Find the updated project attached.

Regards,
Elena

Michael
Top achievements
Rank 1
Iron
commented on 26 Oct 2023, 06:54 PM

Thank you Elena!

I don't know what I am doing wrong. I was able to run the new version and everything worked fine. Copied the step to paste into my test and it will not copy the entire step. Even when I select all and copy/paste it changes the code. First ss is the orig step and the second is the same step in my test. 


Then when I was able to get it close I tried to run the test after binding and changing the path and file name it gives me the following errors. 

[ Compiler ]
13:51:45 'ERROR' > Y:\shared folder\Telerik Test Studio\Mike\Matrix_Boards\AR_Northwest.tstest.vb(97,0) : error BC30451: 'Directory' is not declared. It may be inaccessible due to its protection level.
13:51:45 'ERROR' > Y:\shared folder\Telerik Test Studio\Mike\Matrix_Boards\AR_Northwest.tstest.vb(98,0) : error BC30451: 'Directory' is not declared. It may be inaccessible due to its protection level.
13:51:45 'ERROR' > Y:\shared folder\Telerik Test Studio\Mike\Matrix_Boards\AR_Northwest.tstest.vb(106,0) : error BC30451: 'Directory' is not declared. It may be inaccessible due to its protection level.
13:51:45 'ERROR' > Y:\shared folder\Telerik Test Studio\Mike\Matrix_Boards\AR_Northwest.tstest.vb(129,0) : error BC30451: 'Directory' is not declared. It may be inaccessible due to its protection level.
13:51:45 'ERROR' > Y:\shared folder\Telerik Test Studio\Mike\Matrix_Boards\AR_Northwest.tstest.vb(132,0) : error BC30451: 'File' is not declared. It may be inaccessible due to its protection level.
13:51:45 'INFO' > Build Failed

I really appreciate your help. I just don't understand why I can't figure this out.

Thanks

 

Alexander
Telerik team
commented on 27 Oct 2023, 09:08 AM

Hi Michael,

 The coded step is just a visualization for the VB file in the project folder. What I meant is to copy the code from my sample project then paste it in yours. After that copy-paste the coded step to handle each dialog handler.

Here is the project with these errors fixed, order num and file names changed. Give it a try and let me know if anything comes up.

 

Michael
Top achievements
Rank 1
Iron
commented on 31 Oct 2023, 05:31 PM

Hi Alexander, 

I have been trying to get the 10/27 file to run after only adjusting the download folder like in the previous versions and I keep getting this error.

 

ArtOfTest.Common.Design.Exceptions.ExecutionException: Exception thrown executing coded step: 'New Coded Step'. ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Int32.Parse(String s)
   at SavePathVB.WebTest.GetLastorderNum() in Y:\shared folder\Telerik Test Studio\SavePathVB\WebTest.tstest.vb:line 102
   at SavePathVB.WebTest.CraeteFilePath() in Y:\shared folder\Telerik Test Studio\SavePathVB\WebTest.tstest.vb:line 66
   --- End of inner exception stack trace ---
Alexander
Telerik team
commented on 01 Nov 2023, 02:09 PM

Apologies Michael, 

In the function "GetLastorderNum" change the highlighted line from "return maxNum" ==> "GetLastorderNum = maxNum"

 

Michael
Top achievements
Rank 1
Iron
commented on 01 Nov 2023, 05:29 PM

Alexander, 

So sorry for being such a pain. I do really appreciate your help.

Still having the same error after changing the last line.

ArtOfTest.Common.Design.Exceptions.ExecutionException: Exception thrown executing coded step: 'New Coded Step'. ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Int32.Parse(String s)
   at SavePathVB.WebTest.GetLastorderNum() in Y:\shared folder\Telerik Test Studio\SavePathVB\WebTest.tstest.vb:line 102
   at SavePathVB.WebTest.CraeteFilePath() in Y:\shared folder\Telerik Test Studio\SavePathVB\WebTest.tstest.vb:line 66
   --- End of inner exception stack trace ---

Alexander
Telerik team
commented on 06 Nov 2023, 02:57 PM

HI Michael,

This error is thrown when trying to convert the order number from string to integer. You can see that it is happening on row 102 inside GetLastOrderNum. So, it is connected to the files that are already in your save folder.

What I can suggest now is to double check the followings and correct if needed:

1. Empty spaces here:

 

2. The folder where the files are saved should not have other files than those which end with order number (e.g. 001) 

They can be different types but they must end with order number.

 

3. Check if the path you use leads to save folder

If you specify in the path a folder which does not exist, Test Studio will crete it for you.

 

If those are like this there should be no errors of this type. 

 

 

Michael
Top achievements
Rank 1
Iron
commented on 07 Nov 2023, 05:47 PM

Not sure what is going on. I changed the path to the test folder on my system I am using, it has no files in it. I have not made it to the point where I can copy the coded step into my own test because I cannot get the sample you uploaded to work on it's own. 

When I run the test just how you uploaded it only changing the path that I want to save the test download I am getting the above error. Nothing else was changed. Previous versions of the sample test worked just not the last two VB versions that were uploaded.  I am not concerned with having the step number the files in order anymore so if it makes it easier we can remove that.  I just need to have a step I can use to save a single file with the naming format we need with the date and 001. Until I can figure that out having multiple numbered files doesn't matter. 

 

Elena
Telerik team
commented on 10 Nov 2023, 09:59 AM

Hi Michael, 

Let me step into this thread as my colleague Alexander is out of office today. 

The error you see upon execution is somehow caused from the existing files in the folder where you download the new files. The function is designed to expect that the last three characters of the file name can be converted to integer - as this is the overall requirement. 

It seems that there is a file in the folder which name doesn't end with the three numbers and thus the conversion from string to integer fails. 

Please, check the content of the folder where you download the files and ensure it contains only files which meet the requirement for naming the files. Another option is to set a new empty folder as download destination. 

I hope this information is useful for you.

Regards,
Elena

Michael
Top achievements
Rank 1
Iron
commented on 10 Nov 2023, 05:49 PM

Hi Elena I appreciate you replying, 

There are no files that have been downloaded. I cannot get the test to get to the point of downloading the sample file. 

And I may be wrong here but I am not seeing where in the sample test that it will create a folder with the date like this 20231110 as the folder name then put the downloaded files into that folder. The previous sample tests Alexander uploaded for me would do that. Just not the VP sample test.

Thank you for helping with this.

Mike

Michael
Top achievements
Rank 1
Iron
commented on 10 Nov 2023, 06:33 PM

Ok I got it to work, I had to add a folder name to the end of the path. It seems somewhere along the line we lost the folder creation part of the code. 

I am not seeing anything like this in the latest sample test.

I tried copy/paste into the current sample test and it give me errors so I must have done something wrong.

Private Function CreateFolderCurrentDate() As String
        Dim currentDate As DateTime = DateTime.Now
        Dim dateFormated As String = currentDate.ToString("yyyyMMdd")
        Dim sb As StringBuilder = New StringBuilder()
        sb.Append(folderPath)
        sb.Append("_")
        sb.Append(dateFormated)
        Dim filePath = sb.ToString
        
        If Not Directory.Exists(filePath) Then
            Directory.CreateDirectory(filePath)
        End If
Alexander
Telerik team
commented on 14 Nov 2023, 12:06 PM

Hi Michael,

What I can recommend now is to move the discussion to a private thread.
As a client you can open a ticket where you can share your Test Studio project so we can easily resolve this issue.

If you still want to keep the communication here, I'll need to see what errors occur when trying to paste the step or execute it. 
The failure log will be of great help or a screenshot if those are compile errors.

Regards,
Alexander

Michael
Top achievements
Rank 1
Iron
commented on 13 Feb 2024, 05:04 PM

Hi Alexander,

I have been trying for the last month to get this to work with no success so I think we are going to just stick with using batch files to move/rename files once they are downloaded.

Do you know how we would be able to do that with what you know of our process?

Should be to just run the test and have Firefox or Chrome auto save the downloaded files then once they are finished downloading we would get Test Studio to execute the .bat file from the server at the end of the test to rename/move the downloaded files.

I would think that would be an easier step to duplicate across all of our tests.

Thoughts?

Thank You,

Michael

Elena
Telerik team
commented on 16 Feb 2024, 01:05 PM

Hi Michael, 

Let me step into this thread as my colleague Alexander is out of the office.

Test Studio requires some specific settings for the browsers and part of these are related to how downloads are handled. In order to process the download action Test Studio needs the download to always prompt for download location. With that said your idea to automatically download the files will not be an option. 

You still can download the files with some preset names and then use your bat file to rename and move them as you wish.

I am not sure what your struggles are and what is that you can't setup. So, if the above information is not helpful for you, I will encourage you to submit a support thread where you can share more information for the issues you observe, the code you use and the steps in the scenarios for the scenarios you have troubles with. 

Thank you for your understanding in advance.

Regards,
Elena

Tags
Coded Steps Dialog Test Configuration Test Execution
Asked by
Michael
Top achievements
Rank 1
Iron
Answers by
Alexander
Telerik team
Share this question
or