Closed uschouhan closed 2 weeks ago
@uschouhan There is a typo in the command name. Replace the command name with interceptor: addMock
and give it a try.
@sudharsan-selvaraj I didnt get that error after using code which you have mentioned as example for java.However one doubt why am getting the exception at last here -Error: Cannot write headers after they are sent to the client
[bdb65103][AndroidUiautomator2Driver@51ef] Calling AppiumDriver.execute() with args: ["interceptor: addMock",[{"config":{"url":"*/v4/watchlist","statusCode":401}}],"bdb65103-f712-40b2-b084-42a5ca9bd0fa"]
[bdb65103][AppiumDriver@2f75] Clearing new command timeout pre-emptively since plugin(s) will handle this command
[bdb65103][AppiumDriver@2f75] Plugins which can handle cmd 'execute': appium-interceptor
[bdb65103][AppiumDriver@2f75] Plugin appium-interceptor is now handling cmd 'execute'
[bdb65103][AppiumDriver@2f75] Command 'execute' was not handled by the following behaviours or plugins, even though they were registered to handle it: ["default"]. The command was* handled by these: ["appium-interceptor"].
[bdb65103][AppiumDriver@2f75] Restarting new command timeout via umbrella driver since plugin did not allow default handler to execute
[bdb65103][AndroidUiautomator2Driver@51ef] Responding to client with driver.execute() result: "7a9ef9cc-d85f-4cd7-95f3-d10c52c97efa"
[bdb65103][HTTP] <-- POST /session/bdb65103-f712-40b2-b084-42a5ca9bd0fa/execute/sync 200 56 ms - 48
[bdb65103][HTTP] --> POST /session/bdb65103-f712-40b2-b084-42a5ca9bd0fa/element {"using":"id","value":"com.msf.angelmobile:id/watchListActivitiesFragment"}
[bdb65103][AndroidUiautomator2Driver@51ef] Calling AppiumDriver.findElement() with args: ["id","com.msf.angelmobile:id/watchListActivitiesFragment","bdb65103-f712-40b2-b084-42a5ca9bd0fa"]
[bdb65103][AndroidUiautomator2Driver@51ef] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
[bdb65103][AndroidUiautomator2Driver@51ef] Waiting up to 0 ms for condition
[bdb65103][AndroidUiautomator2Driver@51ef] Matched '/element' to command name 'findElement'
[bdb65103][AndroidUiautomator2Driver@51ef] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/01ea2710-625a-46c2-9edc-b36ff3b4699a/element] with body: {"strategy":"id","selector":"com.msf.angelmobile:id/watchListActivitiesFragment","context":"","multiple":false}
[bdb65103][AndroidUiautomator2Driver@51ef] Got response with status 200: {"sessionId":"01ea2710-625a-46c2-9edc-b36ff3b4699a","value":{"ELEMENT":"00000000-0000-001c-ffff-ffff0000007d","element-6066-11e4-a52e-4f735466cecf":"00000000-0000-001c-ffff-ffff0000007d"}}
[bdb65103][AndroidUiautomator2Driver@51ef] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"00000000-0000-001c-ffff-ffff0000007d","ELEMENT":"00000000-0000-001c-ffff-ffff0000007d"}
[bdb65103][HTTP] <-- POST /session/bdb65103-f712-40b2-b084-42a5ca9bd0fa/element 200 98 ms - 137
[bdb65103][HTTP] --> POST /session/bdb65103-f712-40b2-b084-42a5ca9bd0fa/element/00000000-0000-001c-ffff-ffff0000007d/click {"id":"00000000-0000-001c-ffff-ffff0000007d"}
[bdb65103][AndroidUiautomator2Driver@51ef] Calling AppiumDriver.click() with args: ["00000000-0000-001c-ffff-ffff0000007d","bdb65103-f712-40b2-b084-42a5ca9bd0fa"]
[bdb65103][AndroidUiautomator2Driver@51ef] Matched '/element/00000000-0000-001c-ffff-ffff0000007d/click' to command name 'click'
[bdb65103][AndroidUiautomator2Driver@51ef] Proxying [POST /element/00000000-0000-001c-ffff-ffff0000007d/click] to [POST http://127.0.0.1:8200/session/01ea2710-625a-46c2-9edc-b36ff3b4699a/element/00000000-0000-001c-ffff-ffff0000007d/click] with body: {"element":"00000000-0000-001c-ffff-ffff0000007d"}
[bdb65103][AndroidUiautomator2Driver@51ef] Got response with status 200: {"sessionId":"01ea2710-625a-46c2-9edc-b36ff3b4699a","value":null}
[bdb65103][AndroidUiautomator2Driver@51ef] Responding to client with driver.click() result: null
[bdb65103][HTTP] <-- POST /session/bdb65103-f712-40b2-b084-42a5ca9bd0fa/element/00000000-0000-001c-ffff-ffff0000007d/click 200 438 ms - 14
[bdb65103][HTTP] --> DELETE /session/bdb65103-f712-40b2-b084-42a5ca9bd0fa {}
[bdb65103][AndroidUiautomator2Driver@51ef] Calling AppiumDriver.deleteSession() with args: ["bdb65103-f712-40b2-b084-42a5ca9bd0fa"]
[bdb65103][AppiumDriver@2f75] Clearing new command timeout pre-emptively since plugin(s) will handle this command
[bdb65103][AppiumDriver@2f75] Plugins which can handle cmd 'deleteSession': appium-interceptor
[bdb65103][AppiumDriver@2f75] Plugin appium-interceptor is now handling cmd 'deleteSession'
[bdb65103][ADB] Running '/Users/upendra.chouhan/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 -s emulator-5554 shell settings put global http_proxy :0'
[bdb65103][AppiumDriver@2f75] Executing default handling behavior for command 'deleteSession'
[bdb65103][AppiumDriver@2f75] Event 'quitSessionRequested' logged at 1724744026577 (13:03:46 GMT+0530 (India Standard Time))
[bdb65103][AppiumDriver@2f75] Removing session bdb65103-f712-40b2-b084-42a5ca9bd0fa from our master session list
[bdb65103][AndroidUiautomator2Driver@51ef] Deleting UiAutomator2 session
[bdb65103][AndroidUiautomator2Driver@51ef] Deleting UiAutomator2 server session
[bdb65103][AndroidUiautomator2Driver@51ef] Matched '/' to command name 'deleteSession'
[bdb65103][AndroidUiautomator2Driver@51ef] Proxying [DELETE /] to [DELETE http://127.0.0.1:8200/session/01ea2710-625a-46c2-9edc-b36ff3b4699a] with no body
(node:26250) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead
(Use node --trace-deprecation ...
to show where the warning was created)
[bdb65103][AndroidUiautomator2Driver@51ef] Got response with status 200: {"sessionId":"01ea2710-625a-46c2-9edc-b36ff3b4699a","value":null}
[bdb65103][AndroidUiautomator2Driver@51ef] [Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:
[bdb65103][AndroidUiautomator2Driver@51ef] [Instrumentation] The process has exited with code null, signal SIGTERM
[bdb65103][ADB] Running '/Users/upendra.chouhan/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys activity services io.appium.settings/.recorder.RecorderService'
[bdb65103][ADB] Removing forwarded port socket connection: 8200
[bdb65103][ADB] Running '/Users/upendra.chouhan/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp:8200'
[bdb65103][AndroidUiautomator2Driver@51ef] Restoring hidden api policy to the device default configuration
[bdb65103][ADB] Running '/Users/upendra.chouhan/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy''
[bdb65103][Logcat] Stopping logcat capture
[bdb65103][AppiumDriver@2f75] Event 'quitSessionFinished' logged at 1724744026779 (13:03:46 GMT+0530 (India Standard Time))
[bdb65103][AppiumDriver@2f75] Received response: null
[bdb65103][AppiumDriver@2f75] But deleting session, so not returning
[bdb65103][AppiumDriver@2f75] Responding to client with driver.deleteSession() result: null
[bdb65103][HTTP] <-- DELETE /session/bdb65103-f712-40b2-b084-42a5ca9bd0fa 200 312 ms - 14
uncaughtException: Cannot write headers after they are sent to the client
Error: Cannot write headers after they are sent to the client
at ServerResponse.writeHead (node:_http_server:345:11)
at /Users/upendra.chouhan/.appium/node_modules/appium-interceptor/src/utils/proxy.ts:102:33
at /Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/http-mitm-proxy/lib/proxy.ts:1384:25
at /Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/async/dist/async.js:2589:44
at eachOfArrayLike (/Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/async/dist/async.js:507:13)
at eachOf (/Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/async/dist/async.js:627:16)
at awaitable (/Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/async/dist/async.js:212:32)
at Object.eachLimit$2 (/Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/async/dist/async.js:2692:16)
at Object.awaitable (/Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/async/dist/async.js:212:32)
at Proxy._onResponseEnd (/Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/http-mitm-proxy/lib/proxy.ts:1382:11)
at ProxyFinalResponseFilter.end (/Users/upendra.chouhan/.appium/node_modules/appium-interceptor/node_modules/http-mitm-proxy/lib/ProxyFinalResponseFilter.ts:40:22)
at Gunzip.onend (node:internal/streams/readable:946:10)
at Object.onceWrapper (node:events:634:28)
at Gunzip.emit (node:events:520:28)
at endReadableNT (node:internal/streams/readable:1696:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
This looks like a known issue https://github.com/AppiumTestDistribution/appium-interceptor-plugin/issues/40. we will look into it.
@sudharsan-selvaraj wanted to express my sincere gratitude for the incredible work you've done on the interceptor plugin. I would say this is game changer tool especially on mocking api responses and manipulating based upon need without any proxy server. Thank you so much !!! If I may ask, are there any plans to extend support for iOS in the near future?
appium verion = 2.10.3 interceptor version = appium-interceptor@1.0.0-b
Code - ((JavascriptExecutor) DriverManager.getDriver()).executeScript("interceptor: startListening"); Thread.sleep(5000);
Exception -> [e19c5795][AndroidUiautomator2Driver@9b02] Encountered internal error running command: NotImplementedError: Method is not implemented at AndroidUiautomator2Driver.execute (/Users/upendra.chouhan/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/execute.js:121:11) at commandExecutor (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/driver.ts:106:18) at /opt/homebrew/lib/node_modules/appium/node_modules/async-lock/lib/index.js:171:12 at AsyncLock._promiseTry (/opt/homebrew/lib/node_modules/appium/node_modules/async-lock/lib/index.js:306:31) at exec (/opt/homebrew/lib/node_modules/appium/node_modules/async-lock/lib/index.js:170:9) at AsyncLock.acquire (/opt/homebrew/lib/node_modules/appium/node_modules/async-lock/lib/index.js:189:3) at AndroidUiautomator2Driver.executeCommand (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/driver.ts:122:39) at processTicksAndRejections (node:internal/process/task_queues:95:5) at defaultBehavior (/opt/homebrew/lib/node_modules/appium/lib/appium.js:1123:14) at AppiumInterceptorPlugin.executeMethod (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-plugin/lib/plugin.js:73:14)