Modify Header

Ask general questions here.
adel
Posts: 2
Joined: Wed Feb 21, 2018 5:54 pm

Modify Header

Post by adel » Wed Feb 21, 2018 7:31 pm

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
Attachments
ExtensionSnapshot.rxsnp
popup
(8.85 KiB) Downloaded 17 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Modify Header

Post by odklizec » Thu Feb 22, 2018 9:31 am

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?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

adel
Posts: 2
Joined: Wed Feb 21, 2018 5:54 pm

Re: Modify Header

Post by adel » Mon Feb 26, 2018 4:03 pm

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.