Repository: facebookarchive/WebDriverAgent

Issue #845: WDAError(status=13, value=To screenshot a frame, it must have non-0 area.
Created: 2018-01-15T02:22:53Z
when i use screenshot(), it works when my phone on home page, but it fails when i enter any apps.
File "/Users/liukaihang/Downloads/MillionHeroes-master/hero.py", line 37, in 
pull_screenshot()
File "/Users/liukaihang/Downloads/MillionHeroes-master/hero.py", line 28, in pull_screenshot
c.screenshot('1.png')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wda/init.py", line 295, in screenshot
value = self.http.get('screenshot').value
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wda/init.py", line 101, in fetch
return self._fetch_no_alert(method, url, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wda/init.py", line 107, in _fetch_no_alert
return httpdo(target_url, method, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wda/init.py", line 83, in httpdo
raise WDAError(r.status, r.value)
wda.WDAError: WDAError(status=13, value=To screenshot a frame, it must have non-0 area.
(
0   CoreFoundation                      0x000000018b21c1d8  + 148
1   libobjc.A.dylib                     0x0000000189c5455c objc_exception_throw + 56
2   CoreFoundation                      0x000000018b21c094  + 0
3   Foundation                          0x000000018bca682c  + 112
4   XCTest                              0x00000001001e806c -[XCUIScreen _screenshotDataForQuality:rect:error:] + 192
5   XCTest                              0x00000001001e7f38 -[XCUIScreen screenshotDataForQuality:rect:error:] + 108
6   WebDriverAgentLib                   0x00000001015e32dc -[XCUIDevice(FBHelpers) fb_screenshotWithError:] + 624
7   WebDriverAgentLib                   0x00000001015c4dbc +[FBScreenshotCommands handleGetScreenshot:] + 132
8   WebDriverAgentLib                   0x00000001015d1a10 -[FBRoute_TargetAction mountRequest:intoResponse:] + 208
9   WebDriverAgentLib                   0x00000001015c963c __37-[FBWebServer registerRouteHandlers:]_block_invoke + 496
10  RoutingHTTPServer                   0x00000001016823cc -[RoutingHTTPServer handleRoute:withRequest:response:] + 144
11  RoutingHTTPServer                   0x0000000101682b80 __72-[RoutingHTTPServer routeMethod:withPath:parameters:request:connection:]_block_invoke + 44
12  libdispatch.dylib                   0x000000018a0a51c0  + 16
13  libdispatch.dylib                   0x000000018a0b60c4  + 320
14  libdispatch.dylib                   0x000000018a0a51c0  + 16
15  libdispatch.dylib                   0x000000018a0a9d6c _dispatch_main_queue_callback_4CF + 1000
16  CoreFoundation                      0x000000018b1c9f2c  + 12
17  CoreFoundation                      0x000000018b1c7b18  + 1660
18  CoreFoundation                      0x000000018b0f6048 CFRunLoopRunSpecific + 444
19  Foundation                          0x000000018bc04b1c  + 304
20  WebDriverAgentLib                   0x00000001015c8630 -[FBWebServer startServing] + 424
21  WebDriverAgentRunner                0x00000001007bfbe4 -[UITestingUITests testRunner] + 132
22  CoreFoundation                      0x000000018b222160  + 144
23  CoreFoundation                      0x000000018b115c3c  + 284
24  XCTest                              0x00000001001d2654 __24-[XCTestCase invokeTest]_block_invoke.275 + 48
25  XCTest                              0x00000001001d2404 __24-[XCTestCase invokeTest]_block_invoke + 680
26  XCTest                              0x00000001002189d8 -[XCUITestContext performInScope:] + 208
27  XCTest                              0x00000001001d214c -[XCTestCase invokeTest] + 136
28  XCTest                              0x00000001001d3224 __26-[XCTestCase performTest:]_block_invoke.382 + 48
29  XCTest                              0x000000010021da78 +[XCTContext runInContextForTestCase:block:] + 164
30  XCTest                              0x00000001001d2c20 -[XCTestCase performTest:] + 596
31  XCTest                              0x00000001001cee14 __27-[XCTestSuite performTest:]_block_invoke + 288
32  XCTest                              0x00000001001ce83c -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44
33  XCTest                              0x00000001001cea4c -[XCTestSuite performTest:] + 236
34  XCTest                              0x00000001001cee14 __27-[XCTestSuite performTest:]_block_invoke + 288
35  XCTest                              0x00000001001ce83c -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44
36  XCTest                              0x00000001001cea4c -[XCTestSuite performTest:] + 236
37  XCTest                              0x00000001001cee14 __27-[XCTestSuite performTest:]_block_invoke + 288
38  XCTest                              0x00000001001ce83c -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44
39  XCTest                              0x00000001001cea4c -[XCTestSuite performTest:] + 236
40  XCTest                              0x0000000100227484 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 44
41  XCTest                              0x00000001001e1994 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 420
42  XCTest                              0x0000000100227300 -[XCTTestRunSession runTestsAndReturnError:] + 292
43  XCTest                              0x00000001001be3d4 -[XCTestDriver runTestsAndReturnError:] + 312
44  XCTest                              0x000000010021cc20 _XCTestMain + 620
45  CoreFoundation                      0x000000018b1ca160  + 20
46  CoreFoundation                      0x000000018b1c995c  + 288
47  CoreFoundation                      0x000000018b1c77b0  + 788
48  CoreFoundation                      0x000000018b0f6048 CFRunLoopRunSpecific + 444
49  GraphicsServices                    0x000000018cb79198 GSEventRunModal + 180
50  UIKit                               0x00000001910d0628  + 684
51  UIKit                               0x00000001910cb360 UIApplicationMain + 208
52  WebDriverAgentRunner-Runner         0x00000001000d4444 WebDriverAgentRunner-Runner + 33860
53  libdyld.dylib                       0x000000018a0d85b8  + 4
))

Duplicate issue #868: Session-less screenshot not working
Created: 2018-02-15T17:30:01Z
Might be related to #845. The most recent comment in Appium Issue #9549 mentions something about XCode 9 compatibility issues with iOS 10 which might be what I am experiencing here now.
My environment:

macOS 10.13.3
iOS 10.1.1
Xcode 9.0
a real iPhone 5s

I am attempting to grab screenshots without a session using the /screenshot endpoint. Grabbing screenshots in a session (/session//screenshot) works perfectly fine. However session-less only works on occasion, and fails most of the time. The response I am getting when it fails is:

{"value" : "To screenshot a frame, it must have non-0 area.\n\n(\n\t0   CoreFoundation                      0x0000000188e121d8  + 148\n\t1   libobjc.A.dylib                     0x000000018784c55c objc_exception_throw + 56\n\t2   CoreFoundation                      0x0000000188e12094  + 0\n\t3   Foundation                          0x000000018989f79c  + 112\n\t4   XCTest                              0x0000000100251ac0 -[XCUIScreen _screenshotDataForQuality:rect:error:] + 192\n\t5   XCTest                              0x000000010025198c -[XCUIScreen screenshotDataForQuality:rect:error:] + 108\n\t6   WebDriverAgentLib                   0x0000000101de2dec -[XCUIDevice(FBHelpers) fb_screenshotWithError:] + 740\n\t7   WebDriverAgentLib                   0x0000000101dc4400 +[FBScreenshotCommands handleGetScreenshot:] + 132\n\t8   WebDriverAgentLib                   0x0000000101dd1054 -[FBRoute_TargetAction mountRequest:intoResponse:] + 208\n\t9   WebDriverAgentLib                   0x0000000101dc8c80 __37-[FBWebServer registerRouteHandlers:]_block_invoke + 496\n\t10  RoutingHTTPServer                   0x0000000101e823cc -[RoutingHTTPServer handleRoute:withRequest:response:] + 144\n\t11  RoutingHTTPServer                   0x0000000101e82b80 __72-[RoutingHTTPServer routeMethod:withPath:parameters:request:connection:]_block_invoke + 44\n\t12  libdispatch.dylib                   0x0000000187c9d1c0  + 16\n\t13  libdispatch.dylib                   0x0000000187cae0c4  + 320\n\t14  libdispatch.dylib                   0x0000000187c9d1c0  + 16\n\t15  libdispatch.dylib                   0x0000000187ca1d6c _dispatch_main_queue_callback_4CF + 1000\n\t16  CoreFoundation                      0x0000000188dbff2c  + 12\n\t17  CoreFoundation                      0x0000000188dbdb18  + 1660\n\t18  CoreFoundation                      0x0000000188cec048 CFRunLoopRunSpecific + 444\n\t19  Foundation                          0x00000001897fda8c  + 304\n\t20  WebDriverAgentLib                   0x0000000101dc7c74 -[FBWebServer startServing] + 424\n\t21  WebDriverAgentRunner                0x00000001018bbbe4 -[UITestingUITests testRunner] + 132\n\t22  CoreFoundation                      0x0000000188e18160  + 144\n\t23  CoreFoundation                      0x0000000188d0bc3c  + 284\n\t24  XCTest                              0x000000010023c0a8 __24-[XCTestCase invokeTest]_block_invoke.275 + 48\n\t25  XCTest                              0x000000010023be58 __24-[XCTestCase invokeTest]_block_invoke + 680\n\t26  XCTest                              0x0000000100281780 -[XCUITestContext performInScope:] + 208\n\t27  XCTest                              0x000000010023bba0 -[XCTestCase invokeTest] + 136\n\t28  XCTest                              0x000000010023cc78 __26-[XCTestCase performTest:]_block_invoke.382 + 48\n\t29  XCTest                              0x0000000100286778 +[XCTContext runInContextForTestCase:block:] + 164\n\t30  XCTest                              0x000000010023c674 -[XCTestCase performTest:] + 596\n\t31  XCTest                              0x0000000100238868 __27-[XCTestSuite performTest:]_block_invoke + 288\n\t32  XCTest                              0x0000000100238290 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44\n\t33  XCTest                              0x00000001002384a0 -[XCTestSuite performTest:] + 236\n\t34  XCTest                              0x0000000100238868 __27-[XCTestSuite performTest:]_block_invoke + 288\n\t35  XCTest                              0x0000000100238290 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44\n\t36  XCTest                              0x00000001002384a0 -[XCTestSuite performTest:] + 236\n\t37  XCTest                              0x0000000100238868 __27-[XCTestSuite performTest:]_block_invoke + 288\n\t38  XCTest                              0x0000000100238290 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44\n\t39  XCTest                              0x00000001002384a0 -[XCTestSuite performTest:] + 236\n\t40  XCTest                              0x000000010028ff5c __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 44\n\t41  XCTest                              0x000000010024b3e8 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 420\n\t42  XCTest                              0x000000010028fdd8 -[XCTTestRunSession runTestsAndReturnError:] + 292\n\t43  XCTest                              0x0000000100227ed0 -[XCTestDriver runTestsAndReturnError:] + 312\n\t44  XCTest                              0x0000000100285920 _XCTestMain + 620\n\t45  CoreFoundation                      0x0000000188dc0160  + 20\n\t46  CoreFoundation                      0x0000000188dbf95c  + 288\n\t47  CoreFoundation                      0x0000000188dbd7b0  + 788\n\t48  CoreFoundation                      0x0000000188cec048 CFRunLoopRunSpecific + 444\n\t49  GraphicsServices                    0x000000018a772198 GSEventRunModal + 180\n\t50  UIKit                               0x000000018ecd82fc  + 684\n\t51  UIKit                               0x000000018ecd3034 UIApplicationMain + 208\n\t52  WebDriverAgentRunner-Runner         0x00000001000dc430 WebDriverAgentRunner-Runner + 33840\n\t53  libdyld.dylib                       0x0000000187cd05b8  + 4\n)",
"sessionId" : "E7E3B7A2-A404-43D4-AFE2-AFB29C2DA868",
"status" : 13
}

I've done a little bit more digging and I see now that FBApplication's applicationWithPID method checks to see if the application has already been registered, and if not, it calls [super applicationWithPID:processID] and then registers that application. As an aside, the fb_registerApplicationwithProcessID method accepts an FBApplication and pid_t but just pulls the PID from the FBApplication, so the pid_t passed in is never used. I didn't know if there was a reason for that or not. But as for the call to super, it returns "Application 'local.pid.52'" as the FBApplication which has a .frame CGSize of 0 by 0, hence the error message stating it needs a non-zero area.
Another thing I see in the console output is that during the call to XCUIApplication's applicationWithPID method, two lines print out saying that the application is not running.

2018-02-16 08:48:01.723126 WebDriverAgentRunner-Runner[275:10813] Call super's applicationWithPID...
t =     3.67s Find the Application "local.pid.52" 0x1700a7980
2018-02-16 08:48:01.887328 WebDriverAgentRunner-Runner[275:10813] Enqueue Failure: Application local.pid.52 is not running /Users/czapfel/Documents/WebDriverAgent/WebDriverAgentRunner/UITestingUITests.m 37 1
t =     3.79s Find the Application "local.pid.52" 0x1700a7980
2018-02-16 08:48:01.903884 WebDriverAgentRunner-Runner[275:10813] Enqueue Failure: Application local.pid.52 is not running /Users/czapfel/Documents/WebDriverAgent/WebDriverAgentRunner/UITestingUITests.m 37 1
2018-02-16 08:48:01.910390 WebDriverAgentRunner-Runner[275:10813] Supers call got us: local.pid.52 found at (null) with dimensions WxH -> 0.000000 x 0.000000

I am going to continue to look into this, but if anyone has any ideas please let me know.

Closing comment (2018-02-16T16:21:01Z): Yep duplicate of #845