Issue
As part of a test suite measuring FPS for a web application I need to perform a smooth scroll of the web page. That is, the same smoothness as when a user grabs the scroll bar and moves it with the mouse.
So far I have tried by using simulating key presses with sikuli, i.e. pressing the arrow up/down keys multiple times to scroll the whole page. I have also tried using a Javascript approach:
public void scrollSmooth(int durationOfScroll){
long timeWhenStarting = System.currentTimeMillis() / 1000L;
while (System.currentTimeMillis() / 1000L - timeWhenStarting < durationOfScroll) {
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,10)", "");
}
}
Both these approaches fails to fulfill their purpose, as they both generate a step-by-step scroll, which is not suitable when I simultaneously want to measure the FPS (e.g. the smoothnes of the page when scrolling).
Solution
The solution was a lot more simple than expected. Instead of using a time-based condition for the loop I tried the following:
public void scrollSmooth(){
for(int i=0;i<6000;i++) {
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,1)", "");
}
}
This works well, with the small downside that I cannot specify the length (in time) of the scroll, only the actual pixels to be scrolled.
Answered By - Agent Shoulder
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.