问题
I am attempting to capture client/server response time as recorded by the browser using Selenium WebDriver. My selenium test cases are written in Java. I don't control the code in which I am testing and have tried a variety of solutions as laid out below but none of them meet my requirements 100%.
At the end of the day, I am looking to be able to surround a test step with start() and stop() logic and save the client/server response time as recorded by the browser to a database for reporting.
If I am missing something obvious, please suggest a different approach!
Things I've tried:
1.) Manually surround the test step with start() and stop() timer logic.
PROS: Simplest solution and it works for both page loads and ajax calls. CONS: Does not capture what the true response time from the browser and if there is unusually long wait time on the Selenium side, it falsely reports the numbers. It also considers things like user input as part of the transaction which I don't want. I don't necessarily control the Page Objects I am dealing with so it is not an easy work around.
2.) Using Navigation Timings API
PROS: This works great for page loads CONS: Does not work for AJAX calls. AJAX calls are simply added to the overall page load time and the getEvents() call is not available in Firefox for me to attempt to manually calculate the ajax time.
3.) Using Browser MOB
PROS: Can surround a transaction, not just a request and save it in HAB format. CONS: I had high hopes for this but the numbers are not reported from a browser perspective and thus are just as inaccurate as (1). There is also setup overhead creating a proxy server and the resulting HAB file does not have client/server response times broken down.
4.) Firefox and Networking Export plugin
PROS: Nice automated solution CONS: The export functionality creates a new file for each request but can not aggregate multiple requests into a transaction. There is also no way in which to specify the file name so it makes it impossible to attempt to read in the files which are simply appended with a timestamp.
5.) Relying on "framework" response times.
PROS: Works and at at least on the surface appears accurate. CONS: Does not work across frameworks and thus can not be considered a scalable solution for a busy production site where multiple frameworks are in use.
Things I haven't tried:
1.) Javascript injection
PROS: Perhaps I could inject javascript like the boomerang plugin into the site to measure response times.
CONS: May be difficult and I worry about losing my injection through page events which I may not be aware of or control.
2.) Relying on HTTPWatch plugin
PROS: Appears to do what I want CONS: There is no Java plugin and I don't know if I am up for creating a COM based integration layer when I don't even know if it will suit my needs. I do like the ability to start/stop transactions though vs. individual requests.
3.) YSlow, Google Page Speed and WebPageTest
PROS: Seamless? CONS: Non-starter since I am behind a firewall although I am intrigued on how they attach to the requests.
来源:https://stackoverflow.com/questions/22549429/capturing-selenium-automated-performance-metrics