hallatore / Netling

Netling is a load tester client for easy web testing.
MIT License
1.34k stars 210 forks source link

How to switch b/w socket and http client worker? #43

Open QAInsights opened 3 years ago

QAInsights commented 3 years ago

Could you please explain how do we configure or switch between the workers. Read me is confusing.

simon-flanagan commented 3 years ago

In order to switch to the HttpClientWorkerJob you need to replace:

var worker = new Worker(new SocketWorkerJob(uri)); with var worker = new Worker(new HttpClientWorkerJob(uri));

In the demo WPF app this is in MainWindow.xaml.cs in the StartButton_Click method. You will find something similar in the console application.

I wanted to inject some cookies into the request - in order to do this you need to modify HttpClientWorkerJob to add the cookie when the HttpClient is instantiated e.g.

           var cookieContainer = new CookieContainer();
            var cookieHandler = new HttpClientHandler { 
                CookieContainer = cookieContainer
            };

            var cookie = new Cookie("cookieName", "cookieValue");
            cookie.Domain = "https://somedomain.com";
            cookieContainer.Add(cookie);

            _httpClient = new HttpClient(cookieHandler);

Hope this helps someone else!

QAInsights commented 3 years ago

Thanks @simon-flanagan