Got 500 errors when use real iphone

Hi,
My appium server: 2.0.0-beta.23
Webagentdriver: cloned from git hub at master branch 33a110209035a3017080340dd9b4c75c4997e991
Sometimes i got the following 500 error:
Original error: Cannot get ‘xml’ source of the current application
and
Got response with status 500: {“value”:{“error”:“unable to capture screen”,“message”:"Error Domain=XCTDaemonErrorDomain Code=41 “Not authorized for performing UI testing actions.”
I use a free apple id. Googled some info and somebody said can solve this with a paid account, but I doubt it because sometimes i don’t have this issue.
Thanks in advance.

[HTTP] {“capabilities”:{“alwaysMatch”:{“appium:platformName”:“iOS”,“appium:platformVersion”:“15.2”,“appium:udid”:“00008030-0012754A3E03802E”,“appium:bundleId”:“hk.com.prudential.ebriefcase.uat”,“appium:deviceName”:“iPhone SE”,“appium:newCommandTimeout”:60,“appium:noReset”:true,“appium:automationName”:“XCUITest”,“appium:showXcodeLog”:true,“appium:usePrebuiltWDA”:true,“appium:connectHardwareKeyboard”:true},“firstMatch”:[{}]},“desiredCapabilities”:{“appium:platformName”:“iOS”,“appium:platformVersion”:“15.2”,“appium:udid”:“00008030-0012754A3E03802E”,“appium:bundleId”:“hk.com.prudential.ebriefcase.uat”,“appium:deviceName”:“iPhone SE”,“appium:newCommandTimeout”:60,“appium:noReset”:true,“appium:automationName”:“XCUITest”,“appium:showXcodeLog”:true,“appium:usePrebuiltWDA”:true,“appium:connectHardwareKeyboard”:true}}

[debug] [W3C] Calling AppiumDriver.createSession() with args: [{“appium:platformName”:“iOS”,“appium:platformVersion”:“15.2”,“appium:udid”:“00008030-0012754A3E03802E”,“appium:bundleId”:“hk.com.prudential.ebriefcase.uat”,“appium:deviceName”:“iPhone SE”,“appium:newCommandTimeout”:60,“appium:noReset”:true,“appium:automationName”:“XCUITest”,“appium:showXcodeLog”:true,“appium:usePrebuiltWDA”:true,“appium:connectHardwareKeyboard”:true},null,{“alwaysMatch”:{“appium:platformName”:“iOS”,“appium:platformVersion”:“15.2”,“appium:udid”:“00008030-0012754A3E03802E”,“appium:bundleId”:“hk.com.prudential.ebriefcase.uat”,“appium:deviceName”:“iPhone SE”,“appium:newCommandTimeout”:60,“appium:noReset”:true,“appium:automationName”:“XCUITest”,“appium:showXcodeLog”:true,“appium:usePrebuiltWDA”:true,“appium:connectHardwareKeyboard”:true},“firstMatch”:[{}]}]

[debug] [BaseDriver] Event ‘newSessionRequested’ logged at 1641888508837 (16:08:28 GMT+0800 (China Standard Time))

[BaseDriver] The capabilities [“platformName”] are standard capabilities and do not require “appium:” prefix

[Appium] Attempting to find matching driver for automationName ‘XCUITest’ and platformName ‘iOS’

[Appium] The ‘xcuitest’ driver was installed and matched caps.

[Appium] Will require it at /Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-xcuitest-driver

[Appium] Appium v2.0.0-beta.23 creating new XCUITestDriver (v3.59.0) session

[Appium] Checking BaseDriver versions for Appium and XCUITestDriver

[Appium] Appium’s BaseDriver version is 8.2.2

[Appium] Could not determine XCUITestDriver’s BaseDriver version

[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided

[debug] [BaseDriver] Creating session with W3C capabilities: {

[debug] [BaseDriver] “alwaysMatch”: {

[debug] [BaseDriver] “platformName”: “iOS”,

[debug] [BaseDriver] “appium:platformVersion”: “15.2”,

[debug] [BaseDriver] “appium:udid”: “00008030-0012754A3E03802E”,

[debug] [BaseDriver] “appium:bundleId”: “hk.com.prudential.ebriefcase.uat”,

[debug] [BaseDriver] “appium:deviceName”: “iPhone SE”,

[debug] [BaseDriver] “appium:newCommandTimeout”: 60,

[debug] [BaseDriver] “appium:noReset”: true,

[debug] [BaseDriver] “appium:automationName”: “XCUITest”,

[debug] [BaseDriver] “appium:showXcodeLog”: true,

[debug] [BaseDriver] “appium:usePrebuiltWDA”: true,

[debug] [BaseDriver] “appium:connectHardwareKeyboard”: true

[debug] [BaseDriver] },

[debug] [BaseDriver] “firstMatch”: [

[debug] [BaseDriver] {}

[debug] [BaseDriver] ]

[debug] [BaseDriver] }

[BaseDriver] Session created with session id: 082bb305-7e6a-4300-aaad-0995f049aedf

[debug] [XCUITest] Current user: ‘huwei’

[debug] [XCUITest] Available devices: 00008101-00151C120C02001E, 00008030-0012754A3E03802E

[debug] [XCUITest] Creating iDevice object with udid ‘00008030-0012754A3E03802E’

[XCUITest] Determining device to run tests on: udid: ‘00008030-0012754A3E03802E’, real device: true

[debug] [BaseDriver] Event ‘xcodeDetailsRetrieved’ logged at 1641888508896 (16:08:28 GMT+0800 (China Standard Time))

[debug] [BaseDriver] Event ‘appConfigured’ logged at 1641888508896 (16:08:28 GMT+0800 (China Standard Time))

[debug] [BaseDriver] Event ‘resetStarted’ logged at 1641888508897 (16:08:28 GMT+0800 (China Standard Time))

[debug] [XCUITest] Reset: fullReset not set. Leaving as is

[debug] [BaseDriver] Event ‘resetComplete’ logged at 1641888508897 (16:08:28 GMT+0800 (China Standard Time))

[WebDriverAgent] Using WDA path: ‘/Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-webdriveragent’

[WebDriverAgent] Using WDA agent: ‘/Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj’

[debug] [XCUITest] Crash reports root ‘/Users/huwei/Library/Logs/CrashReporter/MobileDevice/IPhone SE’ does not exist. Got nothing to gather.

[debug] [BaseDriver] Event ‘logCaptureStarted’ logged at 1641888509123 (16:08:29 GMT+0800 (China Standard Time))

[XCUITest] Setting up real device

[debug] [WebDriverAgent] No obsolete cached processes from previous WDA sessions listening on port 8100 have been found

[DevCon Factory] Requesting connection for device 00008030-0012754A3E03802E on local port 8100, device port 8100

[debug] [DevCon Factory] Cached connections count: 0

[DevCon Factory] Successfully requested the connection for 00008030-0012754A3E03802E:8100

[debug] [XCUITest] Starting WebDriverAgent initialization with the synchronization key ‘XCUITestDriver’

[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’

[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body

[debug] [WD Proxy] Got response with status 200: {“value”:{“message”:“WebDriverAgent is ready to accept commands”,“state”:“success”,“os”:{“testmanagerdVersion”:28,“name”:“iOS”,“sdkVersion”:“14.2”,“version”:“15.2”},“ios”:{“ip”:“169.254.76.204”},“ready”:true,“build”:{“upgradedAt”:“1640933683454”,“time”:“Jan 11 2022 15:32:21”,“productBundleIdentifier”:“com.facebook.WebDriverAgentRunner”}},“sessionId”:null}

[debug] [WebDriverAgent] Upgrade timestamp of the currently bundled WDA: 1640933683454

[debug] [WebDriverAgent] Upgrade timestamp of the WDA on the device: 1640933683454

[WebDriverAgent] Will reuse previously cached WDA instance at ‘http://127.0.0.1:8100/’ with ‘com.facebook.WebDriverAgentRunner’. Set the wdaLocalPort capability to a value different from 8100 if this is an undesired behavior.

[debug] [XCUITest] Trying to start WebDriverAgent 1 times with 10000ms interval

[debug] [XCUITest] These values can be customized by changing wdaStartupRetries/wdaStartupRetryInterval capabilities

[debug] [BaseDriver] Event ‘wdaStartAttempted’ logged at 1641888509641 (16:08:29 GMT+0800 (China Standard Time))

[WebDriverAgent] Using provided WebdriverAgent at ‘http://127.0.0.1:8100/

[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’

[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body

[debug] [WD Proxy] Got response with status 200: {“value”:{“message”:“WebDriverAgent is ready to accept commands”,“state”:“success”,“os”:{“testmanagerdVersion”:28,“name”:“iOS”,“sdkVersion”:“14.2”,“version”:“15.2”},“ios”:{“ip”:“169.254.76.204”},“ready”:true,“build”:{“upgradedAt”:“1640933683454”,“time”:“Jan 11 2022 15:32:21”,“productBundleIdentifier”:“com.facebook.WebDriverAgentRunner”}},“sessionId”:null}

[debug] [BaseDriver] Event ‘wdaSessionAttempted’ logged at 1641888509655 (16:08:29 GMT+0800 (China Standard Time))

[debug] [XCUITest] Sending createSession command to WDA

[debug] [WD Proxy] Matched ‘/session’ to command name ‘createSession’

[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8100/session] with body: {“capabilities”:{“firstMatch”:[{“bundleId”:“hk.com.prudential.ebriefcase.uat”,“arguments”:[],“environment”:{},“eventloopIdleDelaySec”:0,“shouldWaitForQuiescence”:true,“shouldUseTestManagerForVisibilityDetection”:false,“maxTypingFrequency”:60,“shouldUseSingletonTestManager”:true,“shouldTerminateApp”:false,“forceAppLaunch”:false,“useNativeCachingStrategy”:true,“forceSimulatorSoftwareKeyboardPresence”:false}],“alwaysMatch”:{}}}

[debug] [WebDriverAgent] Parsed BUILD_DIR configuration value: ‘/Users/huwei/Library/Developer/Xcode/DerivedData/WebDriverAgent-ayqrtspigankrjgyyxxtchhfsndq/Build/Products’

[debug] [WebDriverAgent] Got derived data root: ‘/Users/huwei/Library/Developer/Xcode/DerivedData/WebDriverAgent-ayqrtspigankrjgyyxxtchhfsndq’

[[email protected]:8100] The connection has been closed

[debug] [WD Proxy] Got response with status 200: {“value”:{“sessionId”:“CCCBBFDD-606E-413C-9859-B0CBDEAA78E2”,“capabilities”:{“device”:“iphone”,“browserName”:null,“sdkVersion”:“15.2”,“CFBundleIdentifier”:null}},“sessionId”:“CCCBBFDD-606E-413C-9859-B0CBDEAA78E2”}

[WD Proxy] Determined the downstream protocol as ‘W3C’

[debug] [BaseDriver] Event ‘wdaSessionStarted’ logged at 1641888572221 (16:09:32 GMT+0800 (China Standard Time))

[debug] [BaseDriver] Event ‘wdaStarted’ logged at 1641888572222 (16:09:32 GMT+0800 (China Standard Time))

[XCUITest] Skipping setting of the initial display orientation. Set the “orientation” capability to either “LANDSCAPE” or “PORTRAIT”, if this is an undesired behavior.

[debug] [BaseDriver] Event ‘orientationSet’ logged at 1641888572222 (16:09:32 GMT+0800 (China Standard Time))

[debug] [BaseDriver] The value of ‘elementResponseAttributes’ setting did not change. Skipping the update for it

[debug] [BaseDriver] The value of ‘shouldUseCompactResponses’ setting did not change. Skipping the update for it

[Appium] New XCUITestDriver session created successfully, session 082bb305-7e6a-4300-aaad-0995f049aedf added to master session list

[debug] [BaseDriver] Event ‘newSessionStarted’ logged at 1641888572223 (16:09:32 GMT+0800 (China Standard Time))

[debug] [W3C (082bb305)] Cached the protocol value ‘W3C’ for the new session 082bb305-7e6a-4300-aaad-0995f049aedf

[debug] [W3C (082bb305)] Responding to client with driver.createSession() result: {“capabilities”:{“webStorageEnabled”:false,“locationContextEnabled”:false,“browserName”:"",“platform”:“MAC”,“javascriptEnabled”:true,“databaseEnabled”:false,“takesScreenshot”:true,“networkConnectionEnabled”:false,“platformName”:“iOS”,“platformVersion”:“15.2”,“udid”:“00008030-0012754A3E03802E”,“bundleId”:“hk.com.prudential.ebriefcase.uat”,“deviceName”:“iPhone SE”,“newCommandTimeout”:60,“noReset”:true,“automationName”:“XCUITest”,“showXcodeLog”:true,“usePrebuiltWDA”:true,“connectHardwareKeyboard”:true}}

[HTTP] <-- POST /session 200 63384 ms - 566

[HTTP]

[HTTP] --> GET /session/082bb305-7e6a-4300-aaad-0995f049aedf/source

[HTTP] {}

[debug] [W3C (082bb305)] Calling AppiumDriver.getPageSource() with args: [“082bb305-7e6a-4300-aaad-0995f049aedf”]

[debug] [XCUITest] Executing command ‘getPageSource’

[debug] [WD Proxy] Matched ‘/source?scope=AppiumAUT’ to command name ‘getPageSource’

[debug] [WD Proxy] Proxying [GET /source?scope=AppiumAUT] to [GET http://127.0.0.1:8100/session/CCCBBFDD-606E-413C-9859-B0CBDEAA78E2/source?scope=AppiumAUT] with no body

[WD Proxy] Got response with status 500: {“value”:{“error”:“unknown error”,“message”:“Cannot get ‘xml’ source of the current application”,“traceback”:""},“sessionId”:“CCCBBFDD-606E-413C-9859-B0CBDEAA78E2”}

[debug] [W3C] Matched W3C error code ‘unknown error’ to UnknownError

[debug] [W3C (082bb305)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Cannot get ‘xml’ source of the current application

[debug] [W3C (082bb305)] at errorFromW3CJsonCode (/Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/protocol/errors.js:780:25)

[debug] [W3C (082bb305)] at ProxyRequestError.getActualError (/Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/protocol/errors.js:663:14)

[debug] [W3C (082bb305)] at JWProxy.command (/Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:272:19)

[debug] [W3C (082bb305)] at runMicrotasks ()

[debug] [W3C (082bb305)] at processTicksAndRejections (internal/process/task_queues.js:97:5)

[HTTP] <-- GET /session/082bb305-7e6a-4300-aaad-0995f049aedf/source 500 33 ms - 876

[HTTP]

[HTTP] --> GET /session/082bb305-7e6a-4300-aaad-0995f049aedf/screenshot

[HTTP] {}

[debug] [W3C (082bb305)] Calling AppiumDriver.getScreenshot() with args: [“082bb305-7e6a-4300-aaad-0995f049aedf”]

[debug] [XCUITest] Executing command ‘getScreenshot’

[debug] [XCUITest] Taking screenshot with WDA

[debug] [WD Proxy] Matched ‘/screenshot’ to command name ‘getScreenshot’

[debug] [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/CCCBBFDD-606E-413C-9859-B0CBDEAA78E2/screenshot] with no body

[WD Proxy] Got response with status 500: {“value”:{“error”:“unable to capture screen”,“message”:“Error Domain=XCTDaemonErrorDomain Code=41 “Not authorized for performing UI testing actions.” UserInfo={NSLocalizedDescription=Not authorized for performing UI testing actions.}”,“traceback”:""},“sessionId”:“CCCBBFDD-606E-413C-9859-B0CBDEAA78E2”}

[debug] [W3C] Matched W3C error code ‘unable to capture screen’ to UnableToCaptureScreen

[XCUITest] Error getting screenshot: Error Domain=XCTDaemonErrorDomain Code=41 “Not authorized for performing UI testing actions.” UserInfo={NSLocalizedDescription=Not authorized for performing UI testing actions.}

[debug] [XCUITest] Taking screenshot with WDA

[debug] [WD Proxy] Matched ‘/screenshot’ to command name ‘getScreenshot’

[debug] [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/CCCBBFDD-606E-413C-9859-B0CBDEAA78E2/screenshot] with no body

[WD Proxy] Got response with status 500: {“value”:{“error”:“unable to capture screen”,“message”:“Error Domain=XCTDaemonErrorDomain Code=41 “Not authorized for performing UI testing actions.” UserInfo={NSLocalizedDescription=Not authorized for performing UI testing actions.}”,“traceback”:""},“sessionId”:“CCCBBFDD-606E-413C-9859-B0CBDEAA78E2”}

[debug] [W3C] Matched W3C error code ‘unable to capture screen’ to UnableToCaptureScreen

[debug] [XCUITest] Taking screenshot with WDA

[debug] [WD Proxy] Matched ‘/screenshot’ to command name ‘getScreenshot’

[debug] [WD Proxy] Proxying [GET /screenshot] to [GET http://127.0.0.1:8100/session/CCCBBFDD-606E-413C-9859-B0CBDEAA78E2/screenshot] with no body

[WD Proxy] Got response with status 500: {“value”:{“error”:“unable to capture screen”,“message”:“Error Domain=XCTDaemonErrorDomain Code=41 “Not authorized for performing UI testing actions.” UserInfo={NSLocalizedDescription=Not authorized for performing UI testing actions.}”,“traceback”:""},“sessionId”:“CCCBBFDD-606E-413C-9859-B0CBDEAA78E2”}

[debug] [W3C] Matched W3C error code ‘unable to capture screen’ to UnableToCaptureScreen

[debug] [W3C (082bb305)] Encountered internal error running command: UnableToCaptureScreen: Error Domain=XCTDaemonErrorDomain Code=41 “Not authorized for performing UI testing actions.” UserInfo={NSLocalizedDescription=Not authorized for performing UI testing actions.}

[debug] [W3C (082bb305)] at errorFromW3CJsonCode (/Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/protocol/errors.js:780:25)

[debug] [W3C (082bb305)] at ProxyRequestError.getActualError (/Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/protocol/errors.js:663:14)

[debug] [W3C (082bb305)] at JWProxy.command (/Users/huwei/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:272:19)

[debug] [W3C (082bb305)] at runMicrotasks ()

[debug] [W3C (082bb305)] at processTicksAndRejections (internal/process/task_queues.js:97:5)

[HTTP] <-- GET /session/082bb305-7e6a-4300-aaad-0995f049aedf/screenshot 500 1031 ms - 986

[HTTP]

[HTTP] --> GET /session/082bb305-7e6a-4300-aaad-0995f049aedf/window/rect

[HTTP] {}

[debug] [W3C (082bb305)] Calling AppiumDriver.getWindowRect() with args: [“082bb305-7e6a-4300-aaad-0995f049aedf”]

[debug] [XCUITest] Executing command ‘getWindowRect’

[debug] [WD Proxy] Proxying [GET /window/size] to [GET http://127.0.0.1:8100/session/CCCBBFDD-606E-413C-9859-B0CBDEAA78E2/window/size] with no body

[debug] [WD Proxy] Got response with status 200: {“value”:{“width”:0,“height”:0},“sessionId”:“CCCBBFDD-606E-413C-9859-B0CBDEAA78E2”}

[debug] [W3C (082bb305)] Responding to client with driver.getWindowRect() result: {“width”:0,“height”:0,“x”:0,“y”:0}

[HTTP] <-- GET /session/082bb305-7e6a-4300-aaad-0995f049aedf/window/rect 200 33 ms - 44

[HTTP]

What is the Appium method you are calling when you get this error? If you were to try/catch the error and retry, would you get the error again?

The reason I ask is that I will often get the ‘page_source’ so that I can identify the screen we are on. Sometimes I get Selenium::WebDriver::Error::UnknownError, which I think is very close to what you are seeing. In my experience, if I use a wait and ignore that error I will usually have success. If for some reason we cannot get the source, I will capture the timeout exception thrown by wait, and then move on to another strategy.

Hi @wreed,
I got this error when I start the appium inspector. I think the command is to get screenshot. I haven’t tried with some test code yet. I’ll try to catch the error and see what will happen

  1. did you enable UI Automation on phone?
  2. did you complete prepare WDA for real phone? https://appium.io/docs/en/drivers/ios-xcuitest-real-devices/

1, Yes i have turned the UI automation switch on.
2, I think yes, because this problem occurs randomly( or i haven’t find the rules yet).

try look at https://github.com/facebookarchive/WebDriverAgent/issues/1088