Appium крашится, после попытки снять скриншот с дейвайса iOS.

Appium 1.4.16, Java 1.8.0, iOS 9.3.

Appium log:
http://screencast.com/t/ZDoY0EJr

Java code:

public void takeScreenShotOnFailure(ITestResult testResult, String name) throws IOException  {
        if (testResult.getStatus() == ITestResult.FAILURE) {
            File scrFile = dr.getScreenshotAs(OutputType.FILE);
            Date date = new Date();
            SimpleDateFormat home = new SimpleDateFormat("dd.MM hh:mm:ss");
            String homedate = home.format(date);
            FileUtils.copyFile(scrFile, new File("test-output/screenshots/" + name + ".jpg"));
        }
    }

Кто-нибудь сталкивался стаким? Спасибо заранее.

Проверяем Web или нативные приложения?
Тестировал, правда, только Android, тонкостей iOS не знаю, но однозначно не делаются скриншоты с WebView. Надо переключаться на нативный контекст.

Нативное приложение
Все падает на этой строке: File scrFile = dr.getScreenshotAs(OutputType.FILE);
Раньше этот код работал, видимо где-то/что-то затронул.

Какой тип у Вашего драйвера - AppiumDriver, IOSDriver или WebDriver? Если один из первых двух, попробуйте использовать WebDriver.

Кроме этого, судя по всему Вы тестируете на iPad. В таком случае можно попробовать поменять ориентацию перед снятием скриншота:

   driver.rotate(ScreenOrientation.LANDSCAPE);

Я сталкивался с подобной ошибкой, но она проявлялась в других ситуациях. В основном проблема решалась переустановкой Аппиума и обновлением всех сопутствующих инструментов (brew, node, npm, Xcode).

IOSDriver, тестирую на iPad, да
решение: dr.rotate(ScreenOrientation.PORTRAIT);
Спасибо!
Но мне все равно не понятно, в чем суть проблемы.

Если смена ориентации помогла, значит Аппиум пытался снять скриншот за границами экрана. При работе с айпадами желательно явно указывать ориентацию на этапе инициализации.

Что странно, приложение для юзера отображается с ориентацией LANDSCAPE, но значение атрибута ScreenOrientation у него PORTRAIT.

Appium снова начал крашиться, изменение ориентации почему-то не помогает. Причина в том, что iOSDriver выключается раньше, чем происходит снятие скриншота. Как это можно исправить?

Могу предположить, что вы делаете

driver.quit();

раньше, чем снимаете скриншот. Проверьте свои listener’ы. Что за ошибка-то?

закомментил выключение драйвера (было в AfterSuite), не решилось.
В Eclipse отдается ошибка, что упал сервер Appium, в Appium такой лог:

info: [debug] Got result from instruments: {"status":0,"value":"PORTRAIT"} info: [debug] Responding to client with success: {"status":0,"value":"PORTRAIT","sessionId":"c4959510-76ff-411a-9835-facef75895c0"} info: <-- POST /wd/hub/session/c4959510-76ff-411a-9835-facef75895c0/orientation 200 1875.211 ms - 82 {"status":0,"value":"PORTRAIT","sessionId":"c4959510-76ff-411a-9835-facef75895c0"} info: --> GET /wd/hub/session/c4959510-76ff-411a-9835-facef75895c0/screenshot {} info: [debug] Pushing command to appium work queue: "au.getScreenOrientation()" info: [debug] Sending command to instruments: au.getScreenOrientation() info: [debug] [INST] 2016-04-25 12:13:57 +0000 Debug: evaluation finished info: [debug] [INST] 2016-04-25 12:13:57 +0000 Debug: responding with: info: [debug] [INST] 2016-04-25 12:13:57 +0000 Debug: Running system command #6: /usr/local/bin/node /Users/aap/Temp/Appium/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":"PORTRAIT"}... info: [debug] [INST] 2016-04-25 12:13:58 +0000 Debug: Got new command 6 from instruments: au.getScreenOrientation() info: [debug] [INST] 2016-04-25 12:13:58 +0000 Debug: evaluating au.getScreenOrientation() info: [debug] Socket data received (33 bytes) info: [debug] Socket data being routed. info: [debug] Got result from instruments: {"status":0,"value":"PORTRAIT"} info: [debug] Setting internal orientation to PORTRAIT info: [debug] Pushing command to appium work queue: "au.capture('screenshota26dc86a-deea-4f13-816e-0038f2cb9350')" info: [debug] Sending command to instruments: au.capture('screenshota26dc86a-deea-4f13-816e-0038f2cb9350') info: [debug] [INST] 2016-04-25 12:13:58 +0000 Debug: evaluation finished info: [debug] [INST] 2016-04-25 12:13:58 +0000 Debug: responding with: info: [debug] [INST] 2016-04-25 12:13:58 +0000 Debug: Running system command #7: /usr/local/bin/node /Users/aap/Temp/Appium/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":"PORTRAIT"}... info: [debug] [INST] 2016-04-25 12:13:59 +0000 Debug: Got new command 7 from instruments: au.capture('screenshota26dc86a-deea-4f13-816e-0038f2cb9350') info: [debug] [INST] 2016-04-25 12:13:59 +0000 Debug: evaluating au.capture('screenshota26dc86a-deea-4f13-816e-0038f2cb9350') info: [debug] [INST] 2016-04-25 12:13:59 +0000 Debug: target.captureRectOnScreenWithName("{origin:{x:-256.00,y:-0.00}, size:{height:768.00,width:1024.00}}", UIScreen, "screenshota26dc86a-deea-4f13-816e-0038f2cb9350") info: [debug] Socket data received (25 bytes) info: [debug] Socket data being routed. info: [debug] Got result from instruments: {"status":0,"value":""} info: [debug] Waiting 10000 ms for screenshot to ge generated. info: [debug] Didn't get a new command in 10 secs, shutting down... info: Shutting down appium session info: [debug] Stopping ios info: [debug] Destroying instruments client socket. info: [debug] Closing socket server. info: [debug] Instruments socket server was closed info: [debug] Sending sigterm to instruments info: [debug] [INST] 2016-04-25 12:14:08 +0000 Stopped: Script was stopped by the user info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina SpringBoard[54] <Warning>: HW kbd: Failed to set (null) as keyboard focus info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina SpringBoard[54] <Warning>: Unable to get short BSD proc info for 2088: No such process info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina SpringBoard[54] <Warning>: Unable to get short BSD proc info for 2088: No such process info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina SpringBoard[54] <Warning>: Unable to get short BSD proc info for 2088: No such process info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina mediaserverd[25] <Notice>: '' tv.moyo.entlime(pid = 2088) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina mediaserverd[25] <Notice>: '' tv.moyo.entlime(pid = 2088) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina SpringBoard[54] <Warning>: UNNotificationRegistrarConnectionListener connection invalidated info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina SpringBoard[54] <Warning>: UNNotificationSchedulerConnectionListener connection invalidated info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina com.apple.xpc.launchd[1] (UIKitApplication:tv.moyo.entlime[0x3f5a][2088]) <Notice>: Service exited due to signal: Killed: 9 info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina mediaserverd[25] <Notice>: 'FigPlayer - 32' (pid = 32) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None info: [debug] [INST] 2016-04-25 12:14:00 +0000 Screenshot captured. info: [debug] [INST] 2016-04-25 12:14:00 +0000 Debug: evaluation finished 2016-04-25 12:14:00 +0000 Debug: responding with: 2016-04-25 12:14:00 +0000 Debug: Running system command #8: /usr/local/bin/node /Users/aap/Temp/Appium/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}... info: [debug] [INST STDERR] 2016-04-25 15:14:08.314 instruments[11732:1286263] Attempting to change event horizon while disengage info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina SpringBoard[54] <Warning>: Application 'UIKitApplication:tv.moyo.entlime[0x3f5a]' exited abnormally via signal. info: [IOS_SYSLOG_ROW ] Apr 25 15:14:07 Testers-mini-Retina UserEventAgent[23] <Warning>: 3677748212277: id=tv.moyo.entlime pid=2088, state=0 info: [IOS_SYSLOG_ROW ] Apr 25 15:14:08 Testers-mini-Retina SpringBoard[54] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application. info: [IOS_SYSLOG_ROW ] Apr 25 15:14:08 Testers-mini-Retina SpringBoard[54] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application. info: [IOS_SYSLOG_ROW ] Apr 25 15:14:08 Testers-mini-Retina SpringBoard[54] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application. info: [IOS_SYSLOG_ROW ] Apr 25 15:14:08 Testers-mini-Retina SpringBoard[54] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application. info: [debug] [INST] Instruments Trace Complete (Duration : 21.319983s; Output : /tmp/appium-instruments/instrumentscli0.trace)

Здесь приложение на девайсе уже выключилось.

info: [debug] [INSTSERVER] Instruments exited with code 0 info: [debug] Cleaning up after instruments exit info: [debug] Stopping iOS log capture info: [debug] Reset not set, not ending sim or cleaning up app state info: [debug] Cleaning up appium session info: [debug] We shut down because no new commands came in info: [debug] Pushing command to appium work queue: "au.getScreenOrientation()" info: [debug] Pushing command to appium work queue: "au.capture('screenshota26dc86a-deea-4f13-816e-0038f2cb9350')" info: [debug] Waiting 10000 ms for screenshot to ge generated. error: uncaughtException: cb is not a function date=Mon Apr 25 2016 15:14:21 GMT+0300 (MSK), pid=10739, uid=501, gid=20, cwd=/Users/aap/Temp/Appium/appium, execPath=/usr/local/bin/node, version=v4.2.4, argv=[/usr/local/bin/node, /Users/aap/Temp/Appium/appium/lib/server/main.js, --address, 10.65.5.167, --debug-log-spacing, --platform-version, 9.3, --platform-name, iOS, --app, /Users/aap/Documents/lime-mobile-automation/lime-iOS/src/test/resources/apps/LimeDemo-2.ipa, --udid, ad54a856d44ed949aa524c2736ea19bb7e43c155, --no-reset, --show-ios-log, --show-ios-log, --device-name, Tester's mini Retina], rss=117444608, heapTotal=70302304, heapUsed=64194656, loadavg=[1.98486328125, 2.01123046875, 1.982421875], uptime=16386, trace=[column=24, file=/Users/aap/Temp/Appium/appium/lib/devices/ios/ios-controller.js, function=null, line=1296, method=null, native=false, column=13, file=/Users/aap/Temp/Appium/appium/node_modules/async/lib/async.js, function=Object.async.until, line=712, method=async.until, native=false, column=23, file=/Users/aap/Temp/Appium/appium/node_modules/async/lib/async.js, function=null, line=708, method=null, native=false, column=19, file=/Users/aap/Temp/Appium/appium/lib/devices/ios/ios-controller.js, function=ReadFileContext.callback, line=1290, method=callback, native=false, column=13, file=fs.js, function=FSReqWrap.readFileAfterOpen [as oncomplete], line=303, method=readFileAfterOpen [as oncomplete], native=false], stack=[TypeError: cb is not a function, at /Users/aap/Temp/Appium/appium/lib/devices/ios/ios-controller.js:1296:24, at Object.async.until (/Users/aap/Temp/Appium/appium/node_modules/async/lib/async.js:712:13), at /Users/aap/Temp/Appium/appium/node_modules/async/lib/async.js:708:23, at ReadFileContext.callback (/Users/aap/Temp/Appium/appium/lib/devices/ios/ios-controller.js:1290:19), at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:303:13)]

Возможно, стоит маленький таймаут для сервера. В логах видно, что он не дождался команды от девайса и выключился. Попробуйте увеличить.

http://screencast.com/t/rZGkwzwdJYk - это таймаут сервера?


Еще раз большое спасибо) Убрал из capabilities “setCapability(“newCommandTimeout”, 10);” и все заработало. Изменение ориентации также не потребовалось.
Правда аппиум, судя по логу все равно ждет 10000ms (хотя в Appium GUI выставил 33s).