How to enter the required days of the week and periods when automating tests using the Vanessa Automation tool

Hi all! I would like to share my solution for automating testing on the 1C platform, namely selecting the required days of the week or certain periods.

Correct selection of the document creation date is necessary to automate checks of any document in 1C. Typically, you can write either a static or a calculated value to it. Depending on the task at hand. In Vanessa Automation, in the Variables block, it looks like this:

Example for creating variables

Example for creating variables

As you can see, from the example above, the CurrentDate() function is used for the calculated date. Which returns the current date and time. And using the Format() function, we indicate the date format we need.

This is very convenient, because… The document always indicates the current date. Also, using the CurrentDate() function, you can calculate the previous day by subtracting the value 86400, and the future day by adding 86400. The value 86400 itself is 60 seconds * 60 minutes * 24 hours, i.e. number of seconds in one day.

But, if we want to automate the verification of the document “Work on weekends and holidays”, we need to indicate exactly the weekends. How can this be done?

Example document Work on weekends and holidays

Example document Work on weekends and holidays

Problem

As you know, a month can begin on any day of the week. If you look at the production calendar, you can easily verify this.

Production calendar

Production calendar

When a user creates a document “Work on weekends and holidays,” he can easily understand which date in the calendar is a weekend or holiday – it is colored red.

But, if we want to make an automated script, then we need to calculate the number of the day off.

Solution

As I indicated above – we can use the CurrentDate() function, which returns the current date and time of the current day. Next, we add the WeekDay() function to it, which returns the number of the day of the week. There are 7 possible values ​​in total.

It turns out that this is the line:

ТекущийДеньНедели = ДеньНедели(ТекущаяДата());

Let's say we want Sunday to always be indicated when creating a document “Work on weekends and holidays”. It turns out that if the current day is Monday, we need to add 6 days and we will get the date of Sunday. And if it’s Tuesday, then you need to add 5 days. We will add 7 days to Sunday to get the Sunday of the next week. To do this, I used the conditional operator If.

Если ТекущийДеньНедели = 1 Тогда
  ДатаВоскресения = Формат(ТекущаяДата() + 6*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 2 Тогда  
  ДатаВоскресения = Формат(ТекущаяДата() + 5*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 3 Тогда  
  ДатаВоскресения = Формат(ТекущаяДата() + 4*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 4 Тогда  
  ДатаВоскресения = Формат(ТекущаяДата() + 3*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 5 Тогда  
  ДатаВоскресения = Формат(ТекущаяДата() + 2*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 6 Тогда  
  ДатаВоскресения = Формат(ТекущаяДата() + 1*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 7 Тогда  
  ДатаВоскресения = Формат(ТекущаяДата() + 7*86400,"ДФ=дд.ММ.гггг;");        
КонецЕсли;  

And then we write the resulting date into the Context.

Контекст.Вставить("ДатаВыходногоДня", ДатаВоскресения);

As a result, the resulting piece of script will look like this (calculated on the server):

The resulting code for calculating the date of resurrection

The resulting code for calculating the date of resurrection

Let's consider another option in the time period. We use the Vacation document for this. It must indicate the start date of the vacation and the end date.

Example of a Vacation document

Example of a Vacation document

I think that many employees go on vacation on Monday and end on Sunday. You also need to take into account that the vacation document is entered into the system in advance. In about 2 or 3 weeks. Therefore, we will proceed as follows:

  • For the start date – if the current day is Monday, then add 14 days, and if it’s Tuesday, then 13, etc.

  • For the end date, you need to calculate the resurrection date relative to the start date of the vacation. It turns out that you need to add 6 days to Monday and you get the date of resurrection. If the vacation is for 2 weeks, then add 13 days.

It turns out that the following operator code is If:

сли ТекущийДеньНедели = 1 Тогда
  ДатаНачала = Формат(ТекущаяДата() + 14*86400,"ДФ=дд.ММ.гггг;");
  ДатаОкончания = Формат(ТекущаяДата() + 14*86400 + 6*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 2 Тогда  
  ДатаНачала = Формат(ТекущаяДата() + 13*86400,"ДФ=дд.ММ.гггг;");
  ДатаОкончания = Формат(ТекущаяДата() + 13*86400 + 6*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 3 Тогда  
  ДатаНачала = Формат(ТекущаяДата() + 12*86400,"ДФ=дд.ММ.гггг;");
  ДатаОкончания = Формат(ТекущаяДата() + 12*86400 + 6*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 4 Тогда  
  ДатаНачала = Формат(ТекущаяДата() + 11*86400,"ДФ=дд.ММ.гггг;");
  ДатаОкончания = Формат(ТекущаяДата() + 11*86400 + 6*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 5 Тогда  
  ДатаНачала = Формат(ТекущаяДата() + 10*86400,"ДФ=дд.ММ.гггг;");
  ДатаОкончания = Формат(ТекущаяДата() + 10*86400 + 6*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 6 Тогда  
  ДатаНачала = Формат(ТекущаяДата() + 9*86400,"ДФ=дд.ММ.гггг;");
  ДатаОкончания = Формат(ТекущаяДата() + 9*86400 + 6*86400,"ДФ=дд.ММ.гггг;");
ИначеЕсли ТекущийДеньНедели = 7 Тогда  
  ДатаНачала = Формат(ТекущаяДата() + 8*86400,"ДФ=дд.ММ.гггг;");  
  ДатаОкончания = Формат(ТекущаяДата() + 8*86400 + 6*86400,"ДФ=дд.ММ.гггг;");      
КонецЕсли; 

And then we write down the required dates in the document – I think it’s not difficult. The only thing is that it’s better to add a cycle to the date input. It is necessary because Sometimes the date may not be entered in the field.

Entering a date in a field

Entering a date in a field

Bottom line

We have automated the script for creating the document “Work on weekends and holidays” and “Vacation”. Now, depending on the current date, our documents will always indicate the required day of the week and vacation period. I think this algorithm can be used to solve other problems related to dates and days of the week.

If you have interesting questions, write.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *