Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inspection of network resources requested by the page #710

Closed
stsvilik opened this issue Feb 2, 2017 · 5 comments
Closed

Allow inspection of network resources requested by the page #710

stsvilik opened this issue Feb 2, 2017 · 5 comments
Milestone

Comments

@stsvilik
Copy link

stsvilik commented Feb 2, 2017

I was recently tasked to test for tracking calls initiated when user performs some action on the page, and to my astonishment could not find any good solution for it. I attempted to use Performance API accessible through executeScript (on the client), but that solution turned out to be flawed because

a. API is not available on all browsers and
b. Performance API is buffered and thus resets often leaving tester w/o access to historical resources data.

My proposal is to extend webdriver protocol to permit querying of historical network resources data accessed during browsing session. This would be the same data currently available when you inspect "Network" tab of Chrome (or any other browser) development tools. I know that practically all browsers have that data, so it is just a matter of making this data accessible through webdriver protocol.

The usage would look something like this:

browser.getNetworkResources("script").contains("myscript.js")

or if we want to obtain resource data

var appCss = browser.getNetworkResources("css").find("app.css");
expect(appCss.duration).to.be.atMost(200);

IMHO Network resources data would be extremely valuable not only for testing weather a certain network call was made but also to assert if requested resources performed within permitted threshold.

@shs96c
Copy link
Contributor

shs96c commented Feb 3, 2017

There's a logging API within the Selenium project that allows access to things like performance logs in a consistent format without needing to add an endpoint for each and every kind of logged data. It's available for use in the chromedriver, and Michael Klepikov has given talks on using it at SeConf.

We've discussed how to clean up this logging API and make it available as part of the webdriver spec at F2F meetings, and decided it's out of scope for Level 1. I'd love to see it in Level 2, since it's a handy feature to have.

In the case where people want to inspect actual network traffic the OSS solution is generally to use a proxy to capture this kind of data.

@shs96c shs96c added this to the Level 2 milestone Feb 3, 2017
@stsvilik
Copy link
Author

stsvilik commented Feb 3, 2017

@shs96c Thanks for prompt reply. Logging maybe a useful feature however I need the later - inspection of network traffic. Issue with using proxies is that it creates a disconnect with a test suite and makes it almost impossible to connect say user action with a network call being made. I'm not just interested in knowing that call was made, but when it was made and what action caused it. As I mentioned previously Performance API has that information in most browsers, but that information is not accumulated throughout duration of the browsing session, so I can't check if some essential resource was loaded at the beginning of the session.

@shs96c
Copy link
Contributor

shs96c commented Feb 3, 2017

@stsvilik, the logs returned by the chromedriver contain exactly the information you're requesting. Have you looked at those yet? You may need to store this information at key points in your tests, but it's all exposed. This is what I think would be more valuable to standardise.

It's quite hard to tie a particular network request to a user action, since browsers and web pages are seldom quiescent these days --- prefetching of links, JS updating the UI on a regular or irregular basis, browser extensions hooking into the page, and regular AJAX calls that don't need to modify the UI, as well as Web Workers. I'm unsure what kind of language would be used in a specification to say how a particular network request was tied to a particular user action.

@stsvilik
Copy link
Author

stsvilik commented Feb 3, 2017

@shs96c Yes, I'm well aware of kind of data that chromedriver provides and do agree with you that it should be standardized, it doesn't however solve my original problem.

As for tying a particular network request to a user action, I don't think its as hard as you make it sound. When say a request to perform a click on a page and a query of what network call was initiated since then is done on same browser instance it wouldn't be that difficult to tie them together. It is way more difficult to tie them together when "clicking" and network logging is done on separate systems.

@shs96c
Copy link
Contributor

shs96c commented Feb 6, 2017

This isn't a webdriver issue. We already have an issue for adding a logging command (#406), and requests to improve dev tools for browsers are out of scope for this specification. I'd suggest talking to the relevant WGs in order to make this information more readily amenable to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@shs96c @stsvilik and others