How does the appium-xcuitest-driver knows what to do when receive an api call at a code level?

I am diving into the Appium code at the API part today and found routeConfiguringFunction inside packages/base-driver/lib/protocol/protocol.js. I am guessing the METHOD_MAP constant is some kind of structure or default API for Mobile JSON Wire Protocol. Is that correct?

I am also diving into appium-xcuitest-driver code and found that lib/commands might be some kind of override or extension of default behavior. Is that correct?

Now the more important question is the lib/commands/gesture.js has commands.nativeClick function. Would you mind explaining what is unwrapElement and proxyCommand is trying to do? I tried to go back to the main repo at the packages/base-driver and read parent’s class proxyCommand and still can’t wrap my head around it at the moment.

I want to understand where “Oh hey, I am server and I receive click command or is this element exist command, I am going to do XYZ with ios/android app”. Maybe I don’t understand the concept of proxy and protocol enough.

Hope this makes sense. Cheers!

There are several handy videos around about how to build Appium drivers or plugins, for example:

protocol.js contains a mapping between actual REST calls and their javascript handlers in the driver code.
The proxy code though is needed if the particular driver does not handle commands on its own, but rather proxies them to some other server, like for example appium-xcuitest-driver does to WebDriverAgent.

unwrapElement is used to extract element identifier from a map. this map is usually a universal W3C/JSONWP representation of an element.

1 Like

Appreciate all your answers. Thank you.

I see. I just check appium-uiautomator2-driver. It’s using this.jwproxy.command as well. I suppose it’s similar(or the same just different code style) to this.proxyCommand in appium-xcuitest-driver.

How does the driver know where to proxy those requests to(url, port that WebDriver is using etc)?


 this.proxyReqRes = this.wda.proxyReqRes.bind(this.wda);
 this.jwpProxyActive = true;

I will check out the video thank you so much.