Protractor is the end to end test case runner for AngularJS. These end to end test cases can be repurposed to record performance metrics when the scenario is being run. This is a sample repository with an example of how this can be done.
Install all dependencies using npm install
Protractor currently supports only synchronous configurations. Here is the issue asking for support of asynchronous configurations. Till this feature is added, you would need to generate a temporary configuration that would have the browser parameters required for performance analysis. Run to following command to generate conf.js.tmp
.
node index.js --config conf.js
Once the configration file is generated, run protractor against this using
node_modules/.bin/protractor conf.js.tmp
This will run the example spec and also record the performance metrics. Note the calls to perfRunner in lines 4 8 and 16 that initialize, start and stop the performance metrics.
To start using it in your projects,
- Add browser-perf to your project
- Copy index.js and use it in your test case to mark the start and stop of the scenario.
- Ensure that in your build, you generate the configuration, live done in Step 1 above.
Thanks for sharing this!
I've been trying to integrate this with a project I'm working on, and everything works great apart from one little thing, which I'm hoping I can get some advice on:
Using directConnect in Protractor, when Chrome opens the about:tracing tab, the test suite gets stuck, and will only continue if I manually go back to the original tab.
This is reproducible with the original code from this gist, but with
directConnect : true
set in conf.js.It seems like it's getting stuck on
me.browserPerfRunner.stop(function(err, data) {
. I can get the previous line to log something, but anything inside this stop() method won't log, and it looks like the function isn't executing at all. I'm not sure if this is because a previous promise is timing out; I'm still trying to understand how all these synchronous calls relate to each other.I suspect Selenium is losing control of the original tab, and I've tried switching back to the original tab using browser.switchTo(). This doesn't seem to change the visible tab, but some logging in protractor suggests that protractor thinks it's successfully switched. Unfortunately this isn't enough to get the tests to resume automatically.
Thanks in advance if you can think of anything, I'm lost.