Screenshot issue of iOS mobile app

I am executing iOS mobile scripts using Java, Appium. Screenshot is working inconsistent. I used the following versions
iOS 16.1
Mac os: 14.0 (23A344)
Xcode: 15.0
WebDriver agent: 5.10.0
Java 1.8
Appium: 1.22.3
Capabilities:
capabilities.setCapability(“automationName”, “XCUITest”);
capabilities.setCapability(“platformName”, “iOS”);
capabilities.setCapability(“platformVersion”, platformVersion);
capabilities.setCapability(“deviceName”, deviceName);
capabilities.setCapability(“udid”, udid);
capabilities.setCapability(“bundleId”, “com.abc.mobileapp”);
capabilities.setCapability(“appActivity”, “.MainActivity”);
capabilities.setCapability(“acceptInsecureCerts”, true );
capabilities.setCapability(“autoAcceptAlerts”, true );
capabilities.setCapability(“autoDismissAlerts”, true );
capabilities.setCapability(“autoGrantPermissions”, true );
capabilities.setCapability(“systemAlertsDelayEnabled”, true );
capabilities.setCapability(“noReset”, false );
capabilities.setCapability(“fullReset”, false );
capabilities.setCapability(“autoWebview”, true );
capabilities.setCapability(“takesScreenshots”, true );
capabilities.setCapability(MobileCapabilityType. FORCE_MJSONWP , true );
capabilities.setCapability(“newCommandTimeout”, 300);

It is capturing screenshot sometimes and working sometime, due to that unable to find the exact issue
Code:
public boolean getScreenshotForLog(IOSDriver driver, ExtentTest logger, String name) {
try {
logger.addScreenCaptureFromBase64String(
“data:image/png;base64,” + ((TakesScreenshot) driver).getScreenshotAs(OutputType. BASE64 ),
name+ timeStamp());
logger.info(“ScreenshotCaptured success”);
return true ;
} catch (Exception e) {
try {
String path = ScreenShotUtils. getScreenShotAsFile (driver, Constants. SCREENSHOTS_PATH + name);
logger.info(“screenshot Path is :” + path);
logger.addScreenCaptureFromPath(path, “afterLogin”);
} catch (Exception e2) {
logger.info(“ScreenshotCapturing failed at second time also:” + e.getMessage().toString());
}
return false ;
}
}

reusable:
public static String getScreenShotAsFile(IOSDriver driver,String name) {
File file;
String screenShotName = name+"_"+BasePage. timeStamp2 ()+".png";
try {
file = ((TakesScreenshot) driver).getScreenshotAs(OutputType. FILE );
FileUtils. copyFile (file, new File(screenShotName));
} catch (IOException e1) {
e1.printStackTrace();
}
}

Exception is:
ScreenshotCapturing failed: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: connect ECONNREFUSED 127.0.0.1:8100 (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’ System info: host: ‘C02FFJUZMD6M’, ip: ‘2401:4900:4d07:2495:fd98:d37e:83af:32ce%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘14.0’, java.version: ‘1.8.0_381’ Driver info: io.appium.java_client.ios.IOSDriver Capabilities {acceptInsecureCerts: true, appActivity: .MainActivity, autoAcceptAlerts: true, autoDismissAlerts: true, autoGrantPermissions: true, autoWebview: true, automationName: XCUITest, browserName: , bundleId: com.abc.mobileapp, databaseEnabled: false, deviceName: IPhoneAuto, fullReset: false, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: false, newCommandTimeout: 300, noReset: false, platform: MAC, platformName: iOS, platformVersion: 16.1, resetKeyboard: true, systemAlertsDelayEnabled: true, takesScreenshot: true, takesScreenshots: true, udid: 00008020-000375683C84003A, webStorageEnabled: false} Session ID: e55533eb-b70f-4c02-84ea-1925e87fcc14

Thanks in Advance for you response.

enable DEBUG appium server logs. you will see more info - e.g. exact command that failed…

Hi Aleksei,
Thanks for your input.
I used the following command to start Appium from terminal.
appium --address 0.0.0.0 --port 4723 --log /Users/abc/Desktop/Code/Others/appiumlogs/debugLogs.txt --log-level error:debug --local-timezone
is this correct way to get the DEBUG appium logs?
Ex logs:
2023-11-20 21:36:11:569 [XCUITest] Executing command ‘title’
2023-11-20 21:36:11:569 [RemoteDebugger] Executing atom ‘title’ with ‘args=[]; frames=’
2023-11-20 21:36:11:569 [RemoteDebugger] Executing ‘title’ atom in default context
2023-11-20 21:36:11:569 [RemoteDebugger] Sending javascript command: ‘(function(){return function(){var g=this;functi…’
2023-11-20 21:36:11:569 [RemoteDebugger] Sending ‘_rpc_forwardSocketData:’ message to app ‘PID:931’, page ‘1’, target ‘page-9’ (id: 678): ‘Runtime.evaluate’
2023-11-20 21:36:11:584 [RemoteDebugger] Received data response from send (id: 678): ‘"{“status”:0,“value”:“Dashboard”}"’
2023-11-20 21:36:11:584 [RemoteDebugger] Sending to Web Inspector took 15ms
2023-11-20 21:36:11:584 [RemoteDebugger] Received result for atom ‘title’ execution: “Dashboard”
2023-11-20 21:36:11:584 [MJSONWP (0ad59748)] Responding to client with driver.title() result: “Dashboard”
2023-11-20 21:36:11:585 [HTTP] <-- GET /wd/hub/session/0ad59748-a800-4b00-a97f-0cdc5f3a6bde/

--log-level debug

Thanks for your update @Aleksei
used command:
appium --address 0.0.0.0 --port 4723 --log /Users/abc/Desktop/Code/Others/appiumlogs/241123_debugbuilrun10.txt --log-level debug --local-timezone

please find the following Debug logs:
"
2023-11-24 14:31:25:809 [HTTP] --> GET /wd/hub/session/0f174c3c-969a-48f4-86bc-f724647d5457/screenshot
2023-11-24 14:31:25:809 [HTTP] {}
2023-11-24 14:31:25:809 [MJSONWP (0f174c3c)] Calling AppiumDriver.getScreenshot() with args: [“0f174c3c-969a-48f4-86bc-f724647d5457”]
2023-11-24 14:31:25:809 [XCUITest] Executing command 'getScreenshot’
2023-11-24 14:31:25:809 [XCUITest] Taking screenshot with WDA
2023-11-24 14:31:25:810 [WD Proxy] Matched ‘/screenshot’ to command name 'getScreenshot’
2023-11-24 14:31:25:810 [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/4336232F-AA69-4F1C-A999-6DA8010B2517/screenshot] with no body
2023-11-24 14:31:25:811 [WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:25:811 [XCUITest] Error getting screenshot: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:25:811 [XCUITest] Taking screenshot with WDA
2023-11-24 14:31:25:843 [WD Proxy] Matched ‘/screenshot’ to command name ‘getScreenshot’
2023-11-24 14:31:25:844 [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/4336232F-AA69-4F1C-A999-6DA8010B2517/screenshot] with no body
2023-11-24 14:31:25:849 [WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:26:850 [XCUITest] Taking screenshot with WDA
2023-11-24 14:31:26:851 [WD Proxy] Matched ‘/screenshot’ to command name ‘getScreenshot’
2023-11-24 14:31:26:851 [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/4336232F-AA69-4F1C-A999-6DA8010B2517/screenshot] with no body
2023-11-24 14:31:26:852 [WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at JWProxy.command (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:274:13)
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at runMicrotasks ()
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at processTicksAndRejections (node:internal/process/task_queues:96:5)
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at XCUITestDriver.proxyCommand (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/proxy-helper.js:96:12)
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at getScreenshotFromWDA (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/screenshots.js:11:18)
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at wrapped (/usr/local/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:60:13)
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at retry (/usr/local/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:43:13)
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at retryInterval (/usr/local/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:70:10)
2023-11-24 14:31:26:853 [MJSONWP (0f174c3c)] at XCUITestDriver.getScreenshot (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/screenshots.js:42:10)
2023-11-24 14:31:26:853 [HTTP] <-- GET /wd/hub/session/0f174c3c-969a-48f4-86bc-f724647d5457/screenshot 500 1044 ms - 268
2023-11-24 14:31:26:853 [HTTP]
2023-11-24 14:31:27:862 [HTTP] --> GET /wd/hub/session/0f174c3c-969a-48f4-86bc-f724647d5457/screenshot
2023-11-24 14:31:27:862 [HTTP] {}
2023-11-24 14:31:27:863 [MJSONWP (0f174c3c)] Calling AppiumDriver.getScreenshot() with args: [“0f174c3c-969a-48f4-86bc-f724647d5457”]
2023-11-24 14:31:27:863 [XCUITest] Executing command ‘getScreenshot’
2023-11-24 14:31:27:863 [XCUITest] Taking screenshot with WDA
2023-11-24 14:31:27:863 [WD Proxy] Matched ‘/screenshot’ to command name ‘getScreenshot’
2023-11-24 14:31:27:863 [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/4336232F-AA69-4F1C-A999-6DA8010B2517/screenshot] with no body
2023-11-24 14:31:27:864 [WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:27:864 [XCUITest] Error getting screenshot: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:27:864 [XCUITest] Taking screenshot with WDA
2023-11-24 14:31:27:893 [WD Proxy] Matched ‘/screenshot’ to command name ‘getScreenshot’
2023-11-24 14:31:27:894 [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/4336232F-AA69-4F1C-A999-6DA8010B2517/screenshot] with no body
2023-11-24 14:31:27:895 [WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:28:896 [XCUITest] Taking screenshot with WDA
2023-11-24 14:31:28:898 [WD Proxy] Matched ‘/screenshot’ to command name ‘getScreenshot’
2023-11-24 14:31:28:898 [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/4336232F-AA69-4F1C-A999-6DA8010B2517/screenshot] with no body
2023-11-24 14:31:28:901 [WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: connect ECONNREFUSED 127.0.0.1:8100
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] at JWProxy.command (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:274:13)
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] at processTicksAndRejections (node:internal/process/task_queues:96:5)
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] at XCUITestDriver.proxyCommand (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/proxy-helper.js:96:12)
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] at getScreenshotFromWDA (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/screenshots.js:11:18)
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] at wrapped (/usr/local/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:60:13)
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] at retry (/usr/local/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:43:13)
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] at retryInterval (/usr/local/lib/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:70:10)
2023-11-24 14:31:28:902 [MJSONWP (0f174c3c)] at XCUITestDriver.getScreenshot (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/screenshots.js:42:10)
2023-11-24 14:31:28:903 [HTTP] <-- GET /wd/hub/session/0f174c3c-969a-48f4-86bc-f724647d5457/screenshot 500 1040 ms - 268
2023-11-24 14:31:28:903 [HTTP]
2023-11-24 14:31:28:906 [HTTP] --> GET /wd/hub/session/0f174c3c-969a-48f4-86bc-f724647d5457/screenshot
"
Thanks

what was before? maybe 1 min passed?
try add to appium server:

--keep-alive-timeout 1800 

-> https://appium.io/docs/en/2.1/cli/args/

Appium 1 is heavily outdated. The driver it includes does not support modern iOS versions

Hi @Aleksei,
There is no pass timeout before steps.
before step completed in same second only.

I have been facing same issue still.
Can you help on this?
Can anyone suggest any other way?
Thanks in advance.

Hi,
I am facing same issue again.
Could anyone please help me on this above issue.

Thanks in advance.