appium-uiautomator2-server: screenshot failed !

When I do screenshots, it throws the following exception


selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: io.appium.uiautomator2.common.exceptions.TakeScreenshotException: Failed to capture a screenshot. Does the current view have 'secure' flag set?
	at io.appium.uiautomator2.utils.ScreenshotHelper.takeDeviceScreenshot(ScreenshotHelper.java:70)
	at io.appium.uiautomator2.utils.ScreenshotHelper.takeScreenshot(ScreenshotHelper.java:48)
	at io.appium.uiautomator2.utils.ScreenshotHelper.takeScreenshot(ScreenshotHelper.java:63)
	at io.appium.uiautomator2.handler.CaptureScreenshot.safeHandle(CaptureScreenshot.java:19)
	at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:36)
	at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:250)
	at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:241)
	at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
	at java.lang.Thread.run(Thread.java:818)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

Yes. I tried everything vysor, screen mirror, capture the specific object using appium nothing worked. I wonder how AWS device farm was able to capture the video without any issues!. Anyways thanks for confirming that UIAutomator2 or appium doesn’t support capturing screens with secure flag set. … On Tue, May 5, 2020 at 7:24 AM Kazuaki Matsuo @.***> wrote: secure source set to true. Do you mean https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_SECURE ? Then, we can not get screenshot technically. It is the limitation of Android framework. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#275 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGLABG66PF2GDL4PVFCYSADRQAHRLANCNFSM4HNZXJ2A . – Thanks and Regards, Lavanya Bathina 303-676-7825

I was also facing same exception from last one week & tried out different ways for taking screenshots but nothing worked out. In between 2-3 times it worked but it took random screenshots of whatever was open on my laptop screen & not of the android application. So yea i agree with you appium doesn’t allow taking screenshots with FLAG_SECURE enabled for security purposes. Also i think DeviceFarm uses some different functionality for screen capture & recordings as it works fine over there.