Capture web driver network traffic across all browsers - selenium

I want to capture all the network calls from Web Driver in Java. I am not doing any UI testing, just testing JS execution and, requests and responses of some network calls.
I tried using Browser Mob as is suggested in most forums, but I need it to work across all browsers. It worked flawlessly with Firefox, but I was facing some issues with the others. Safari driver doesn't event support a Proxy capability.
I don't want to use Fiddler as it involves some manual steps around invoking and storing the calls. Whereas, Browser Mob being an in-code proxy can be integrated in a more smoother fashion.
I also tried using the RC-like package included in Selenium standalone server package. But, I have some HTTPS calls and some nested iframes in cross domains. I am particularly interested in some cross domain POST call and it doesn't work out that well. Also, people keep saying it's not recommended to use that package.
So, I had a solution where we can use a standalone proxy server running on a machine. Using host entries, we'll point Web Driver to hit the proxy instead of the actual server. The proxy will record all the incoming calls and route them to the actual server host. Later, I can make a request to the proxy which will return me all the calls it intercepted. I am not sure whether it's still called a proxy or a router.
I came across TCPmon, but it's no longer being supported. Does anyone know some similar tools that could run on Unix systems or any alternate solutions?

We modified the Fiddler rules script to include a new exec action. If you use their native script editor, it also provide auto complete features and we were comfortably able to get around it. The syntax is similar to that of JavaScript.
The Fiddler package comes with a ExecActions.exe which can be used to pass console arguments to a running Fiddler instance using the command prompt.
The code we wrote processed all the sessions captured by Fiddler and wrote it to a file in a custom JSON format and later used GSON to deserialize it.
Please let me know, if you want further details.

Related

Recording scripts using HTTP Test Script Recording vs Blazemeter plugins

Just a simple question, which Jmeter recording method is better for the timebeing? Record script using HTTP Test Script Recording (using proxy) or Blazemeter plugins? Can provide justification for each?
Because at first I record with blazemeter plugins, when I tried to apply correlation, it never works. But then I try to record manual using proxy, my correlation works. I tried to correlate userSession in the webtours test application.
Mind if you can share your thoughts on that? In which scenario we have to choose scripting using Blazemeter plugins or proxy in Jmeter apps? Thanks!
Both basically intercept HTTP requests and convert them to JMeter's HTTP Request samplers
HTTP(S) Test Script Recorder requires extra steps like importing certificates, configuring proxy server, etc.
BlazeMeter Chrome Extension doesn't require any extra setup, however for certain POST requests it may add multipart/form-data where it's not needed
Going forward you can consider the following alternatives:
Correlations Recorder Plugin for JMeter - where you can add correlation rules beforehand and they will be automatically applied to the content substituting hard-coded values with the appropriate JMeter Variarbles, you will still have to perform correlation, but it will be one place only
BlazeMeter Proxy Recorder - which is capable of exporting recorded requests in "SmartJMX" mode with automatic detection and correlation of dynamic parameters (even including timestamps), but it requires Internet connectivity so if you're recording a local application you won't be able to use it.
If you're still interested in my "thoughts" I don't think that any "recording" solution can substitute a human, especially when it comes to more complex topics like simulation of AJAX requests so I would recommend using a 3rd-party sniffer tool to compare the network footprint from the real browser with JMeter's and amend JMeter configuration so it would be 100% accuracy.

Unable to get fingerprint in browser using Apache JMeter

I performed performance testing using Apache JMeter version 3.X.
At one of the step, I'm not able to get the browser fingerprint value. I receive NULL value and it cause my program to be terminated.
But when I'm using normal browser, it works find.
Is there any limitation on Apache JMeter where it cannot get the browser fingerprint value?
First of be aware that it's recommended to use latest version of JMeter so consider upgrading to JMeter 5.2 (or whatever is the latest stable version available at JMeter Downloads page)
With regards to the "fingerprint" itself, according to the main page of JMeter project:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
so you need to investigate the logic of this "fingerprint" check, you can make JMeter to behave like a real browser up to certain extent like:
use HTTP Cookie Manager to represent browser cookies
use HTTP Header Manager to send at least User-Agent and other headers which normal browser sends
etc.
however if the "fingerprint" check relies on JavaScript you will need to re-implement the same JavaScript using JSR223 Test Elements
The main rule is: the network footprint of JMeter must be exactly the same as network footprint of the real browser (apart from dynamic values which need to be correlated), if you will send proper requests using JMeter - your system under test will not see the difference.

Selenium RemoteWebDriver and Windows Authentication Dialogs

I've seen this question has been asked a few times, and lots of solutions get suggested - but none of them seem to work for the RemoteWebDriver (ie: using Selenium Grid). They're usually centered around using the local ChromeDriver/FirefoxDriver/IEDriver classes.
I am using the .NET bindings, by the way :).
What I want to do is fairly simple (in terms of requirement). I have a Selenium Server setup, and am currently using the RemoteWebDriver to perform automated UI tests on various sites. This setup is working fine.
However, some sites use NTLM/Windows Authentication, and we need to start writing automated tests for these. However, as far as I can tell, there is no solution for this.
I have seen the following "solutions", but - unless someone can correct me - they either don't work consistently, or will not work using RemoteWebDriver:
Using the IAlert functionality (like here). However, this isn't implemented in the .NET bindings, and doesn't work for all browsers as far as I can tell.
Using the Robot API to interact with the popup (like here). But this is for running on your local machine, and not supported by RemoteWebDriver.
Using AutoIt to do a similar thing to the Robot API. However, this won't work using RemoteWebDriver.
Passing the credentials in the URL (eg: http://username:password#example.com). However, this doesn't work for Windows Authentication - just normal HTTP Basic Authentication.
I can't actually see any other solutions, unless anyone else can help?
A workaround currently is to log onto the Selenium server, go to the sites in each browser, and save the credentials. But this isn't ideal, and adds a level of manual interaction to each test.
Any help would be appreciated :).
It appears I have found my own solution - use a proxy which adds the NTLM negotiation/authorisation automatically. Pretty simple to setup :).
http://cntlm.sourceforge.net/

IE8 Post Body Becomes Empty after form submission

Okay here is our setup:
Simple form being submitted via AJAX using Prototype 1.7 to a Apache server captured by ColdFusion. (We have noticed similar bugs on pages that submit form data in the conventional way but these pages are used far less.)
Some of our clients are reporting an error. After looking through the logs and doing live testing from their machine Firebug Light is reporting that the request was being sent with the post data.
However on the server side the post data is not present in raw logs or ColdFusion's FORM object or in GetHttpRequestData().
This problem has been isolated to IE only even when running Chrome Frame and is intermittent.
We can not reproduce this error with our IE8 installs on our machines OR on their machines running Firefox or Chrome.
Any thoughts on this extremely difficult bug to track down?
Do you have an HTTP proxy involved in this somewhere? We have had issues in the past, I can't recall the details, but I know that it had something to do with using AJAX to POST. The proxy was configured such that a certain combination of headers would make it misbehave. Take a good look at the HTTP headers coming from the browser, comparing one that works and one that doesn't.

Getting Orbited to work with my Twisted app

I can't seem to get Orbited working with my Twisted app. I have a page, served by Twisted (say localhost:8000/page) which includes Orbited.js from the orbited server (localhost:8001/static/Orbited.js). I then have a TCP chat server example running on port 7777. I try to use Orbited.TCPSocket to connect to the chat server:
conn=new Orbited.TCPSocket();
conn.open("localhost", 7777);
conn.send("test\r\n"); //error: bad readyState
It works fine when Orbited is serving the page, but not when twisted serves it from a different port. My orbited.cfg looks like this:
[listen]
http://:8001
[access]
* -> localhost:7777
And before (which worked) I had this in it as well:
[static]
test=index.html
Where index.html was another page grabbing localhost:8001/static/Orbited.js, and was accessed from localhost:8001/test.
How do I need to change my config file to work with requests from my twisted site on another port?
Update
I tried changing Orbited.settings.port to 8001 before trying to open the connection, but I got an error: "unsafe javascript attempt to access frame with url http://localhost:8000/page from frame with url http://localhost:8001/static/xsdrBridge.html#1. Domains, protocols and ports must match."
Hmm, also, I just looked at the orbited wiki, and apparently, setting Orbited.settings.port is exactly what I'm supposed to do. but I'm getting horrible errors
You can call send() only after the connection is in opened state.
Put a handler for .onopen() and do a .send() from there.
I have used Orbited in the past. It works in general but there are several quirks to get it set up and running smoothly. The project itself seems to be in a state of flux (it seems to be moving to node.js). Both of these points lead me to suggest that - if you can avoid it - not to use Orbited.
Are there alternatives that are cleaner? I would say, yes. You can pretty much emulate Orbited with Websockets on stock Twisted. This will clearly work for newer browsers. What about older ones? Well, there are open-source projects that wrap websockets and fall back to flash as a transport for older browsers. The setup works quite well, and actually feels cleaner than using a solution like orbited.
If you check out http://github.com/rlotun/txWebSocket you'll find the current state of Twisted's websocket implementation, as well as an example of how to fall back to flash on older browsers. Hopefully this will be useful enough for you to serve as a drop in replacement to Orbited.