New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 651909 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Oct 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

Need ability to scroll until element is on screen in telemetry user stories

Project Member Reported by rnep...@chromium.org, Sep 30 2016

Issue description

Sometimes we need to be able to interact with parts of the page that are currently off screen, so we need a way to be able to scroll down until they are in view.

Example:
_Start of screen
a
_End of screen
b


A benchmark that clicks on A, clicks back, scrolls down until b is in view, clicks on B is currently hard to implement.

 
Description: Show this description
Cc: benjhayden@chromium.org
I think the easiest way could be using getBoundingClientRect() which returns the element's position relative to the viewport.

Based on that, we can calculate the number of pixel to scroll so that the element is in the middle of view port.

Ben: do you think this seems like a sound strategy?
Sorry, clarifying question: does the scroll need to be smooth? If so, you can use jquery or manually animate window.scrollTo() as Ned suggests. If not, element.scrollIntoView() should work.
We are trying to emulate real user action, and it looks like element.scrollIntoView() just jumps to the element (based on local experimenting); so I am thinking it is probably not a good fit for this.
Ah, yep, you can do something like this:
https://github.com/GabrielDelepine/smooth-scroll
but maybe requestAnimationFrame instead of setTimeout.
Ben: we have hook in Chrome for synthesize the smooth scroll already (see https://cs.chromium.org/chromium/src/third_party/catapult/telemetry/telemetry/internal/actions/scroll.js?rcl=0&l=35)

For this bug, the problem we are trying to solve is figure out how much to scroll to get to the element. After that, we can just pass the direction & speed to existing code in https://cs.chromium.org/chromium/src/third_party/catapult/telemetry/telemetry/internal/actions/scroll.py?rcl=0&l=90
Components: Tests>Telemetry
Cc: perezju@chromium.org alexandermont@chromium.org charliea@chromium.org
+Some other folks: does any one has bandwidth to take on implementing this? 
I have a quick quesiton about how EvaluateJavaScript in the action runner works..

On the same page I run the following command: document.querySelectorAll(".pinImageDim")[5].getBoundingClientRect()

Running from the JS console I get:
ClientRect {top: 765, right: 1102.5, bottom: 1118, left: 866.5, width: 236…}

Running from telemetry via action_runner.EvaluateJavaScript('document.querySelectorAll(".pinImageDim")[5].getBoundingClientRect()') I get
{}

Shouldn't they return the same value? 
They should return the same value. Randy, do you have a CL? I will patch yours & see what's going on.
I dont have a CL for it, I was just experimenting.

In browsing_stories.py in the _MediaBrowsingStory class I just made _DidLoadDocument the following:

  def _DidLoadDocument(self, action_runner):
    print 'Test'
    print
    i = 'document.querySelectorAll("%s")[5]' % self.ITEM_SELECTOR
    i = i + '.getBoundingClientRect()'
    print i
    print action_runner.EvaluateJavaScript(i)

    index = self.ITEM_SELECTOR_INDEX
    for _ in xrange(self.ITEMS_TO_VISIT):
      print action_runner.EvaluateJavaScript(i)
      self._NavigateToItem(action_runner, index)
      self._ViewMediaItem(action_runner)
      if self.INCREMENT_INDEX:
        index += 1


It outputs "document.querySelectorAll(".pinImageDim")[5].getBoundingClientRect()" Which I then open the JSConsole mid run(which pauses telemetry) and see that it returns something, while the print statement 'print action_runner.EvaluateJavaScript(i) just prints {}.
Did you get a chance to try and repo this Ned?
Sorry, I am quite busy with issue 653519 & can't use my desktop do anything else besides running the benchmark with many repetition. 

For fast checking, can you do:
window.alert("document.querySelectorAll(".pinImageDim")[5].getBoundingClientRect()") to see if this is a js problem or telemetry problem?
nvm, my run just finished and I found the problem:
JSON.stringify(document.querySelectorAll(".pinImageDim")[5].getBoundingClientRect()) also return "{}" in devtool.

The reason is that getBoundingClientRect() doesn't return a raw dictionary, but an actual instance of a class. Therefore you can't convert it to json string & send back to telemetry.

For your case, I would suggest doing the code of computing the distance to scroll in js land & pass it to window.__scrollAction.start (similar to the code in https://cs.chromium.org/chromium/src/third_party/catapult/telemetry/telemetry/internal/actions/scroll.py?rcl=0&l=86)
Owner: rnep...@chromium.org
Status: Started (was: Untriaged)
Thanks for taking this, Randy!
Cc: hjd@chromium.org
Project Member

Comment 19 by bugdroid1@chromium.org, Oct 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/0d801d5aa8208459720512e845fe82507dc7bea3

commit 0d801d5aa8208459720512e845fe82507dc7bea3
Author: catapult-deps-roller <catapult-deps-roller@chromium.org>
Date: Fri Oct 14 20:44:05 2016

Roll src/third_party/catapult/ baf2eab47..f506b6809 (2 commits).

https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git/+log/baf2eab473e1..f506b6809e99

$ git log baf2eab47..f506b6809 --date=short --no-merges --format='%ad %ae %s'
2016-10-14 rnephew Add ScrollPageToElement to action_runner.
2016-10-14 lpy Fix the usage of StackFrame in tests.

BUG= 651909 

CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_optional_gpu_tests_rel
TBR=catapult-sheriff@chromium.org

Review-Url: https://codereview.chromium.org/2422723002
Cr-Commit-Position: refs/heads/master@{#425458}

[modify] https://crrev.com/0d801d5aa8208459720512e845fe82507dc7bea3/DEPS

Status: Fixed (was: Started)

Sign in to add a comment