Page 1 of 1

Modify Header

Posted: Wed Feb 21, 2018 7:31 pm
by adel
Hello,

I have windows 10 installed, however, I might also be working with windows 7. I have upgraded to ranorex 8.0.1.

I need to run a test case, in which the headers of any http request must be modified before sending that request (I basically want to set the User-Agent header to "ranorex" and add one additional header). For this purpose I developed a chrome extension that enables me to modify/add headers before sending requests. However, I need this process also to be automated inside my test case, but ranorex is unable to identify any input field or button inside the popup of the extension (it only recognizes the whole popup as one element). Is there any way to automate that?. If not, can the above mentioned requirement be achieved in any other way?.
In the attachment you can find a screenshot of the popup

Thank you in advance

Re: Modify Header

Posted: Thu Feb 22, 2018 9:31 am
by odklizec
Hi,

Could you please specify, what exactly you mean by "modifying headers" and sending "http requests"? Maybe dumb questions, but if you simply want to send the HTTP requests and before sending them you need to modify their headers, I would suggest to do both things from code.

Here is the code I'm using for SOAP requests, but I believe it could be used (maybe with some modifications) for HTTP requests as well:
restful-web-service-testing-t8413.html

And request header could be modified by xml parsing/editing, for which you can find a lot of samples via google (most probably even here). I think it's much better way than doing it via some kind of extension?

Re: Modify Header

Posted: Mon Feb 26, 2018 4:03 pm
by adel
Hello,

Your questions are not dumb. I will try to explain with the following example:

If you observe the network section in chrome developer tools while loading (for example) Microsoft's website, you will notice that the browser sends about 40 requests (for loading javaScript, css and images, some of them even have a different url). I want the headers of each one of these requests to be modified (i.e. User-Agent: ranorex + one additional header - this additional header must be modified several times inside the test-). I have read your code and the code provided in the question of that post (RESTful web service testing). In your code I focused on the following method:

Code: Select all

 private static HttpWebRequest CreateWebRequest(string url, string action)  
        {  
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);  
            webRequest.Headers.Add("SOAPAction", action);  
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";  
            webRequest.Accept = "text/xml";  
            webRequest.Method = "POST";  
            return webRequest;  
        }  
I also tried to use this method from the other code:

Code: Select all

      public static HttpResponseMessage GetFromService_RAW(Uri serviceUri) {
         using (HttpClient client = new HttpClient()) {
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Host = serviceUri.Host;
            
            return client.GetAsync(serviceUri).Result;
         }
The problem is that even if I provide a specific url, it's not just one simple web request, there are many.
If I just could make ranorex recognize any element inside the popup/tab/window of any chrome or Firefox modify headers extension, that would solve the whole problem. In the past I used this extension: https://addons.mozilla.org/en-US/firefo ... y-headers/
It worked perfectly with ranorex 6 and Firefox 44, but it seems not to be available any more in the new versions of Firefox (ranorex 8 works only with Firefox 50 and higher).
I have also tried to use fiddler, but ranorex can't write any scripts in the fiddlerScripts section (it just considers the whole page as one element).
I am an absolute beginner to ranorex and I have no experience neither with c# nor with .Net. So, any help will be very appreciated.