!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: AndroidDriver takeScreenshot returns unscaled version of page  (Read 3033 times)

Lukus

  • Web User
Having waited a while for automated tests on Android because of this
 screenshot issue, that now appears to be corrected:
 http://code.google.com/p/selenium/issues/detail?id=1236
 .. experimenting with AndroidDriver again for screenshots shows
 another issue with pages that are scaled to fit the window.  On the
 emulator screen, a page that does not have a mobile version is scaled
 to fit the viewport and looks correct, however, when a screenshot is
 requested via selenium:
 
((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE)
 
... the result is only the top-left corner of the web page.  For pages
 like Yahoo that deliver a custom mobile version of the page, this is
 not an issue.  You can test wikipedia.com to see an example of the
 issue I am seeing.
 
Before submitting this as an official issue, I want to check with the
 selenium group to see if anyone else has seen this issue.  Maybe
 there's a way to set things up different on the emulator, or maybe how
 AndroidDriver() is called with activity or capabilities?
 
My results are running an emulator on Win 7 64-bit, both Android
 platform 2.2 (which is what I want my target to be) and 4.0.  I've
 tested using webdriver 2.11 and 2.12 with relative android.apk
 realeases.
 
Any one else seeing this issue or have an idea on correcting?   Could
 this is be a bug?

Dounia Berrada

  • Web User
Re: AndroidDriver takeScreenshot returns unscaled version of page
« Reply #1 on: April 12, 2012, 07:37:12 PM »
Which emulator version / SDK/ WebDriver APK are you using? Also can you
 share a repro case I can use to take a look at this issue?
 


- Show quoted text -

--
 Dounia

Lukus

  • Web User
Re: AndroidDriver takeScreenshot returns unscaled version of page
« Reply #2 on: April 12, 2012, 07:37:27 PM »
Hi Dounia, thanks for responding.  Not sure you got my response and I
 hit "reply to author" instead of "reply" so re-posting for everyone's
 benefit:
 As mentioned, I installed the Android SDK the other day so have the
 latest versions of the SDK and AVD manager.  Using the SDK manager, I
 downloaded the SDK and samples for target platforms Android 2.2 and
 4.0.  I created emulators for each of these as well.  After starting
 the 2.2 emulator, I first tried installing android-2.11.apk and
 compiling the test below with selenium standalone version 2.11.0.
 When this gave me the unscaled screenshot results on www.wikipedia.com
 and other sites, I uninstalled the 2.11 apk, installed 2.12 apk and
 compiled and ran the test with selenium standalone 2.12. This produced
 the same results, so tried the same methods on the Android 4.0
 emulator with no difference.
 
I am not using a Junit test nor using an IDE.  I am compiling and
 running on the command line.  Here's the sample test code I ran after
 running an emulator, launching the webdriver, and forwarding the port:
 
import org.openqa.selenium.By;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.android.AndroidDriver;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.JavascriptExecutor;
 import org.openqa.selenium.OutputType;
 import org.openqa.selenium.TakesScreenshot;
 import org.openqa.selenium.io.FileHandler;
 import org.apache.commons.io.FileUtils;
 import java.io.File;
 import java.io.IOException;
 
public class AndroidTest {
 
  public static void main(String[] args) throws Exception {
 
    WebDriver driver = new AndroidDriver();
 
        //open the page
     driver.get("http://wikipedia.com");
 
        //js object
         JavascriptExecutor js = (JavascriptExecutor) driver;
 
        //get initial screenshot
         try {
                 final File screenshot = new File("screenshot1.png");
                 final File tmpScreenshot = ((TakesScreenshot)
 driver).getScreenshotAs(OutputType.FILE);
                 FileUtils.copyFile(tmpScreenshot, screenshot);
         }
         catch(IOException e){
                 System.out.println("Failed to take screenshot."+e.getMessage());
         }
 
        //try scrolling down the page
         js.executeScript("window.scrollTo(0,400)");
 
        //wait a few seconds
         try{
                 Thread.sleep(5000);
         }
         catch(InterruptedException e){
                 System.out.println("Thread.sleep interrupted: "+e.getMessage());
         }
 
        //take another screenshot
         try {
                 final File screenshot = new File("screenshot2.png");
                 final File tmpScreenshot = ((TakesScreenshot)
 driver).getScreenshotAs(OutputType.FILE);
                 FileUtils.copyFile(tmpScreenshot, screenshot);
         }
         catch(IOException e){
                 System.out.println("Failed to take screenshot."+e.getMessage());
         }
 
        //quit
     driver.quit();
   }
 

- Show quoted text -

Selenium Webdriver

Re: AndroidDriver takeScreenshot returns unscaled version of page
« Reply #2 on: April 12, 2012, 07:37:27 PM »

Dounia Berrada

  • Web User
Re: AndroidDriver takeScreenshot returns unscaled version of page
« Reply #3 on: April 12, 2012, 07:37:43 PM »
You mean that after scrolling you still get the screenshot of the very top
 of the page rather than the screenshot of the actual view port, right? This
 seems to be an issue, so please file a bug :).
 


- Show quoted text -

--
 Dounia

Lukus

  • Web User
Re: AndroidDriver takeScreenshot returns unscaled version of page
« Reply #4 on: April 12, 2012, 07:37:58 PM »
No, it's not the scrolling issue that was already corrected.  I will
 file a bug, thanks.


 

Related Topics

  Subject / Started by Replies Last post
9 Replies
384 Views
Last post April 12, 2012, 06:51:20 PM
by Lukus
4 Replies
214 Views
Last post February 22, 2012, 08:40:11 PM
by Patrick Lightbody
4 Replies
210 Views
Last post February 23, 2012, 03:52:35 PM
by Patrick Lightbody
3 Replies
1370 Views
Last post March 28, 2012, 03:59:19 PM
by Derek Washington
1 Replies
978 Views
Last post March 28, 2012, 08:31:56 PM
by Jason
0 Replies
149 Views
Last post April 12, 2012, 06:50:15 PM
by Lukus
0 Replies
376 Views
Last post October 02, 2012, 05:37:00 AM
by saleh.hazrami

Review www.seleniumwebdriver.com on alexa.com