Android - Screenshot not being honored in Landscape orientation

I am testing the use of Appium V1.4.0 on a Samsung Galaxy S5 (Android 5.0) device on Windows 7. Screenshots look good in Portrait mode, but Landscape is not being honored. I start the Appium server on my local box and communicate with it with Java and RemoteWebDriver

I started the server in command line:

C:\Program Files\Appium\node_modules\appium\bin>“C:\Program Files\Appium\node.ex
e” “C:\Program Files\Appium\node_modules\appium\bin\Appium.js” --address 127.0.0
.1 --device-name XXXXXXXX --browser-name Chrome

Code:
package com.esurance.selenium.appium;

import org.openqa.selenium.*;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.URL;
import java.io.File;
import java.net.MalformedURLException;

public class AndroidChrome {
public static void main(String[] args) throws MalformedURLException {

	WebDriver driver = null;

	System.out.println("Starting driver");

	try
	{
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("platformName", "Android");
		capabilities.setCapability("deviceName", "XXXXXXXX");
		driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		driver.get("https://www.esurance.com/");
        
        Thread.sleep(5000);
		
		WebDriver augmentedDriver = new Augmenter().augment(driver);
        File screenshot = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
        
        FileUtils.copyFile(screenshot, new File("C:\\Users\\Stranger\\Downloads\\Screenshots\\esurange-1.jpeg")); 
	}
     catch(Exception ex)
     {
    	 System.out.println(ex.toString());
     }
     finally
     {
    	 if(driver != null)
    	 {
    		 driver.quit();
    	 }
     }
}

}

Any ideas??

it is. we do detect orientation in code and rotate images for our convenience in code.

Can you please provide the details?? Remember, I am using RemoteWebDriver communicating with Appium server. I am still working on connecting Appium to Selenium Grid.

In my test I rotated the phone, but I did not updated anything in code.

Can you provide little more details on the problem, logs etc.

  1. How does app go into landscape mode? Are you doing it pro-grammatically or ?

use case scenario would be good to have in accordance with the debug info

Much of the info has been already provided. The only thing I do I put my Samsung Galaxy phone in landscape orientation, and then execute the test case. I am not adding anything programmatically.

You should be able to reproduce this fairly easy. I wanted to post the screenshots, but I cannot find a way to upload screenshots.

What I meant to say is that the screen is being captured. The issue is that the screenshot does not look the nearly the same of what I see on the phone. I am wondering if I can submit the screenshots.

In order to post screenshots, you can press ctrl+G or click the upload option on the options bar above textfield.

1 - how to upload your image: http://screencast.com/t/AePgbgG8
2 - code auto-rotate image

package com.REMOVED.tests.base;

import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;

import javax.imageio.ImageIO;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;

public class temp {

    protected WebDriver driver;

    //Example of usage: saveScreenToFile(takeShot(),urlToSaveScreenshotLocally+"screenshot.png)

    public void saveScreenToFile(BufferedImage image, String fileUrl) {
        try {
            ImageIO.write(image, "png", new File(fileUrl));
            System.out.println("   screenshot saved: " + fileUrl);
        } catch (Exception e) {
        }
    }

    public BufferedImage takeShot() {
        for (int i = 0; i < 5; i++) {
            if (driver.manage().window().getSize().getHeight() > driver.manage().window().getSize().getWidth()) {
                System.out.println("   takeShot: portrait mode w: " + driver.manage().window().getSize().getWidth()
                        + ", h: " + driver.manage().window().getSize().getHeight());
                try {
                    return ImageIO.read(((AppiumDriver) driver).getScreenshotAs(OutputType.FILE));
                } catch (Exception e) {
                    System.err.println("    get screenshot failed.");
                }
            } else {
                System.out.println("   takeShot: landscape mode w: " + driver.manage().window().getSize().getWidth()
                        + ", h: " + driver.manage().window().getSize().getHeight());
                BufferedImage image = null;
                try {
                    image = ImageIO.read(((AppiumDriver) driver).getScreenshotAs(OutputType.FILE));
                } catch (Exception e) {
                    System.err.println("    get screenshot failed.");
                }
                if(image!=null) {
                    //System.out.println("    original image height: "+image.getHeight()+", width: "+image.getWidth());
                    int diff = (image.getHeight() - image.getWidth());
                    diff = diff / 2;
                    //System.out.println("   diff: "+diff);

                    AffineTransform tx = new AffineTransform();
                    tx.rotate(Math.PI * 1.5, image.getHeight() / 2, image.getWidth() / 2);//(radian,arbit_X,arbit_Y)
                    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
                    image = op.filter(image, null);//(source,destination)
                    //System.out.println("    rotated image height: "+image.getHeight()+", width: "+image.getWidth());

                    image = image.getSubimage(diff, diff, image.getWidth() - diff, image.getHeight() - diff);
                    //System.out.println("    result image height: "+image.getHeight()+", width: "+image.getWidth());
                    return image;
                }
            }
        }
        return null;
    }
}