Take Screenshot in Appium

Hi,

I am doing some automation of website on Android emulator (using platform version 5.0.1 and API 21)
I tried using below code …

Driver Setup Code
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“platformVersion”, “5.0.1”);
capabilities.setCapability(“deviceName”, “Nexus7”);
capabilities.setCapability(“browserName”, “Browser”);
driver = new RemoteWebDriver(new URL(“http://192.168.1.17:4723//wd/hub”), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

And Code for taking screenshot:
WebDriver driver1 = new Augmenter().augment(driver);
File file = ((TakesScreenshot) driver1).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File(“Screenshot.png”));

But getting following exception …
unknown error: cannot activate web view
(Session info: webview=)
(Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 94 milliseconds
Build info: version: ‘2.43.1’, revision: ‘5163bce’, time: ‘2014-09-10 16:27:33’
System info: xxxxxxxxxx
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=, platform=ANDROID, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 98d6e4fb5a03da367a2821bd3e221e55

public static void getScreenshot(AndroidDriver driver, String outputlocation ) throws IOException {
	System.out.println("Capturing the snapshot of the page ");
	File srcFiler=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
	FileUtils.copyFile(srcFiler, new File(outputlocation));
}	

I don’t see any issue with the code, here is a snippet from my code and it works fine. Just make sure that you pass the exact output location
Something like “/Users/abhishek/Desktop/pol.png”

try with :
capability.setCapability(MobileCapabilityType.TAKES_SCREENSHOT, “true”);

capability.setCapability(MobileCapabilityType.TAKES_SCREENSHOT, “true”);

is this code working.

public static void getScreenshot(AndroidDriver driver, String outputlocation ) throws IOException {
System.out.println("Capturing the snapshot of the page ");
File srcFiler=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFiler, new File(outputlocation));
}

this code is working but I am unable to get screen shot in specified location.

Please someone help me …

try
{
if (scenario.isFailed())
{
File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenShotFile, new File(“path goes here” + “appImage” + “.png”));
}
}

1 Like

Hey Abhishek , it worked for me.

Thanks
All folks, it can work for you as well. It simple and quick