Unable to capture Response Headers Location through browsermob proxy - selenium

I'm using selenium php webdriver and php wrapper for browsermob proxy to fetch the access token from facebook. Once the user authetication was sucessfull, the facebook will redirect to
'http://www.karkala.in/index.html#state=ads_management%2Cread_insights&access_token=ABCDEFZCLkK3EBAJOxrzwq0BdXzT6DCA6QDZBbwUpc8ArgdAv5ly3nNSHME9W19cF7a06pGGGyQdkpVtqc4OnZAnAQT4eKDqeaipxLlVEgZDZD&expires_in=5569'
Now I need to read this token. I use the following php code to fetch the response
$har = self::$client->__get("har");
But I'm not able to see the location (above url) in response headers.
My response text is available here:
http://www.karkala.in/har.txt

Selenium itself has got an option to read the url.
selenium.GetLocation()
Can be achieved without using browsermob proxy.

Related

Requestly chrome extension mock api response to 503

I want to change HTTP Status Code to 503 with a custom response body on URL ending with .mpd. I am using Requestly chrome extension to intercept the request and have it failed with 503.
Here is the Modify API Response rule screenshot
Here's Requestly logs in devtools which shows that request was correctly intercepted.
The rule looks like it kicks in but is not showing the correct response code. Looking at the network tab it looks like the interception did not work
Need help with mocking the status code to 503 and custom response body.
HTTP Status Code can not be changed by Chrome Extension. Chrome doesn't provide any APIs which allow Chrome Extensions to change the status code.
You should be able to solve this problem using the Requestly desktop app where you can also specify the status code while defining your mocked API response.
A desktop app-based solution is more reliable however if you really want to work with Chrome extension only. Here's a workaround that you can try
Setup a new API Mock with 503 Status Code and the Response Body
Setup a new Redirect Rule to redirect your actual URL to the Mock URL
More details are covered in this SO answer
References
https://requestly.medium.com/simulate-different-api-status-code-using-requestly-76f917c445eb

Allowing HTTP API calls in Chrome

I am writing a test JSP-Servlet page that calls an HTTP API. But when I run the call in Chrome browser it is converting the call to HTTPS and the call fails. The API is not mine and the developer of the API insists that the call has to be on HTTP.
So is there a way to allow this API call using HTTP and prevent Chrome from converting it to an HTTPS call?
Note: I checked the Web and all are saying to change the browser settings. But we will not be able to tell each and every user of our site to do so!
Add this Script on top of your JSP File!
<script>
if (location.protocol == "https:") {
location.protocol = "http:";
</script>
Note:
First, location.protocol checks Url
and the second location.protocol will change it to http.
This will redirect your Client. If he visits your website as https: it will redirect him as http:

Capture the URL in the javascript initiated HTTP GET/POST requests using selenium

I'm using selenium for automating a procedure I frequently use on a site.
When I press on specific element on the site it runs some complex javascript code that eventually downloads a csv file using HTTP GET request.
I can see that the URL of this request looks like: www.somesite.com/somepage.php?token=RAPO09834HROLQ340HGIE309W&....
My question is: how can I get the token in this URL with selenium? (I need it for executing other HTTP GET requests for extracting more data from the site)
I am using Firefox driver on windows.
I tried to search all the html, js, cookies I get from this site, the token is not there. (its probably generated by the javascript code before it does the HTTP request)
I understand this is some kind of session id token as all the javascript generated HTTP requests are using the same token during my session.

How can I intercept SSL requests with BrowserMob proxy

I am using BrowserMob proxy 2.0-beta-8 in a test automation project with Selenium. The page I'm testing against is using https and I need to rewrite the user agent header. For plain http requests everything works fine - the request interceptor is called and I can rewrite the header. However, for https requests the interceptor is not called at all.
Does BrowserMob currently not support intercepting https requests or am I missing something here?
You did not mention what browser are you using:
1) If you are using Firefox/Chrome, Selenium2 and BrowserMob >=2.0-beta8 then everything should work out of the box
2) If you are using other browser, check how to install browser CA certificate

Set request header and User Agent in Geb

When using Geb, is it possible to set custom request headers and user agent when using the Browser API (and not the Direct Download API)?
While this is possible with the FirefoxDriver (see here), I am looking for a way of doing this with the WebKitDriver.
A possible solution is via a proxy.
BrowserMob has a standalone mode with REST api, or embedded in your test programmatically: https://github.com/webmetrics/browsermob-proxy . Useful when there are a lot of custom headers you want to test.
If you already have Apache, you can create another VirtualHost on a different port having that particular request header, and point your browser to that port before the test. Given that your header doesn't change between tests.
This might not be the direct solution to your question: modify request headers directly in Browser API, but it achieves the end result.