C# blocks are not executed in the launcher

Valbers

Client
Регистрация
27.12.2021
Сообщения
8
Благодарностей
1
Баллы
3
Hi, when I launch a project with c# blocks outside the project maker the c# code is not executed, I tried with very basic instructions like "sendInfoToLog", but nothing... has anyone encountered the problem?
 

Phoenix78

Client
Read only
Регистрация
06.11.2018
Сообщения
11 790
Благодарностей
5 683
Баллы
113
Hi, when I launch a project with c# blocks outside the project maker the c# code is not executed, I tried with very basic instructions like "sendInfoToLog", but nothing... has anyone encountered the problem?
outside the project maker the c# code is not executed... where is this for example ?
 

Valbers

Client
Регистрация
27.12.2021
Сообщения
8
Благодарностей
1
Баллы
3

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 189
Благодарностей
5 830
Баллы
113
what errors do you get in execution log?
 

Phoenix78

Client
Read only
Регистрация
06.11.2018
Сообщения
11 790
Благодарностей
5 683
Баллы
113

Valbers

Client
Регистрация
27.12.2021
Сообщения
8
Благодарностей
1
Баллы
3
I didn't pay attention to this parameter!

The problem comes from my c# code with the getTraffic() method

I tried to send the header of a request that I capture and I get this message

Executing action CSharp OwnCode: Récupérer Header Frais.id: 45e7887d-fff0-47fb-86fa-bad6754129c4 Object reference not set to an instance of an object.
C#:
Thread.Sleep(1000);

project.SendInfoToLog("Hey bro", true);

instance.UseTrafficMonitoring = true;

var traffic = instance.ActiveTab.GetTraffic();

foreach (var t in traffic){
    
    
    if(Regex.IsMatch(t.Url, "Check-checkAvailabilityWith")){
        
        
            project.Variables["Header"].Value = t.RequestHeaders;
            project.SendInfoToLog(t.RequestHeaders , true);
        
        
    }
}
 

Phoenix78

Client
Read only
Регистрация
06.11.2018
Сообщения
11 790
Благодарностей
5 683
Баллы
113

Valbers

Client
Регистрация
27.12.2021
Сообщения
8
Благодарностей
1
Баллы
3

Phoenix78

Client
Read only
Регистрация
06.11.2018
Сообщения
11 790
Благодарностей
5 683
Баллы
113
Everything works fine in the project maker, and t is not empty because I can get the url, only the requestHeader method, causes this problem
Once again, I repeat. this field may be empty, checks are needed. moreover, it is possible that the request does not have this header at all, or it is of a different type, for example responseHeaders. Working with this object requires a lot of checks and a try/catch block.
It is also very possible that the request was not loaded to the end in the Zennoposter, since the speed of work there is much higher than in the Project Maker, where there is an artificial slowdown in the execution of the project. And in your code, this moment is not taken into account, from the word "at all".
 

Valbers

Client
Регистрация
27.12.2021
Сообщения
8
Благодарностей
1
Баллы
3
I understood, unlike the project maker it is necessary to pass instance.UseTrafficMonitoring to true before making the request, I used a "Go to page" block followed by my c# block
 

Valbers

Client
Регистрация
27.12.2021
Сообщения
8
Благодарностей
1
Баллы
3
If someone can explain me why it works like this, is it due to the execution speed in zenoposter, to the precompilation?
 

Вложения

Phoenix78

Client
Read only
Регистрация
06.11.2018
Сообщения
11 790
Благодарностей
5 683
Баллы
113
instance.UseTrafficMonitoring = true; this should be before going to the page and doing things with it.
var traffic = instance.ActiveTab.GetTraffic(); Receives and resets all requests

I don't know why you have such a design as in the 2nd picture. It shouldn't work and it doesn't work for me.
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)