1

Selenium Webdriver interacts with any browser through HTTP, as discussed - here. I have some automated tests written using selenium through the Protractor framework in JavaScript.

My use case is I want a clean way to record all interactions originating from my JS-based test cases to the browser, including - user action emulations and any DOM interrogations originating from test-cases.

What would be the easiest way to record these interactions?

2 Answers2

0

Protractor is a wrapper around Webdriverjs , so you should be able to use addEventListener command to add any browser supported events that will cover most user actions and DOM interrogations

Note, this is only supported in chrome currently

Also, this is an experimental feature in webdriver.js so have to add

var client = WebdriverJS.remote({
    logLevel: 'verbose',
    experimental: true, // <-- enables browser side eventhandling
    desiredCapabilities: {
        browserName: 'chrome'
    }
});

And then register events like

client
    .url('http://google.com')
    .addEventListener('dblclick','#hplogo', function(e) {
        console.log(e.target); // -> 'id("hplogo")'
        console.log(e.type); // -> 'dblclick'
        console.log(e.clientX, e.clientY); // -> 239 524
    })
    .doubleClick('#hplogo') // triggers event
    .end();

You can use removeEventListener to unregister any registered listeners

Evenhandling in Node.js environment is also supported as implied by this

WebdriverJS inherits several function from the NodeJS EventEmitter object

If you want to also capture network traffic , you can do that with browsermob-proxy

Here is a tutorial on browsermob-proxy

user1207289
  • 3,060
  • 6
  • 30
  • 66
0

Since the interaction is over HTTP, I was able to capture the HTTP calls using - httflow library. Once I got the HTTP calls, I sanitized the HTTP dump to remove irrelevant calls and then mapped the Protractor code areas to the calls by defining a custom mapping.