4

I need to capture and print all the browser steps being executed in test script into HTML report. I'm currently using protractor and protractor-html-screenshot-reporter for reporting. Can anyone suggest if this can be achieved using any tool or are there any api's for this. Desired sample is attached.enter image description here

1 Answers1

3

In order to achieve what you are asking about, you need to understand what is going on under-the hood and how the browser actions you need to log are sent and executed.

Here is a very brief high-level overview.

Interactions between a webdriver, selenium server and a browser are happening through the JSON Wire Protocol - JSON over HTTP:

enter image description here

See also: Protractor: How It Works.

In other words, finding an element, sending keys to an element, click etc are, basically, sent as HTTP requests that could be monitored and logged, see Monitoring JSON wire protocol logs. For instance, here are the Chrome service logs:

[2.389][INFO]: COMMAND FindElement {
   "sessionId": "b6707ee92a3261e1dc33a53514490663",
   "using": "css selector",
   "value": "input"
}
[2.389][INFO]: Waiting for pending navigations...
[2.389][INFO]: Done waiting for pending navigations
[2.398][INFO]: Waiting for pending navigations...
[2.398][INFO]: Done waiting for pending navigations
[2.398][INFO]: RESPONSE FindElement {
   "ELEMENT": "0.3367185448296368-1"
}

This is exactly what, for example, BrowserStack is doing. They are parsing the raw logs and producing a user-friendly report of all actions performed:

enter image description here


In protractor, the closest functionality to what you are asking about, is being currently developed under a timeline plugin:

  • configure plugins section in your protractor config:

    plugins: [{
        path: 'node_modules/protractor/plugins/timeline/index.js',
        outdir: 'timelines'
    }],
    
  • run tests

  • open timelines/index.html report and see:

enter image description here

Basically, it parses the webdriver's "client" logs and builds a time frame highlighting the commands that were sent during a test session. This is something you can use as a starting point, explore the source code of the plugin.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • @Alecxe- very well explained! – Sakshi Singla Jan 30 '15 at 04:27
  • @Alecxe- I'm having trouble with timeline plugin, there is no such plugin which came while installing protractor. Can you please tell me how to get this in my local machine. – Anirudh Banerji Jan 30 '15 at 09:33
  • @BonJovi this is available in protractor installed from the github, master branch. – alecxe Jan 30 '15 at 09:41
  • @Alecxe- thanks! got this working. Now only thing left is that the index.html doesn't shows anything, but the timeline.json does contains steps while were executed on browser. Not sure what exactly the reason is? – Anirudh Banerji Jan 30 '15 at 10:41
  • 1
    I'm getting Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/DPC/workspaces/automation/dpc-login-plugin/timelines/timeline.json' on the console. – Anirudh Banerji Jan 30 '15 at 11:03