Tips for Speeding Up Your Remote Appium Sessions
I am the laminitis of this confab firm called CloudGrey, where we focus on mobile mechanization and helping clients get their mobile automation strategy going and whether they should use Appium or something else, training team, stuff like that. I also work with the Appium open source task and have been involved with that since the beginning. The first topic that I want to cover today is something that ’ s a new feature in Appium called executeDriverScript, and it sounds a lot like execute script which you might know as a feature from Selenium and Appium in web mode. This is something a slight bit different. So, first let ’ s talk about the problem this lineament is trying to solve. As a bit of background, we can remember that Appium is progress around something called the client-server architecture. If we take a look at this diagram hither, what client-server architecture intend is that the piece of Appium which is actually automating devices, physically connected to a device, is not necessarily located in the same property as your test code. When you ’ re pen Appium test codification, you ’ re importing an Appium node into your favorite programming language and writing dictation like driver.findElement or whatever. But what ’ s actually happen under the hood when you run those commands in your programming language is that those bid are turned into HTTP request and sent to an Appium server, which is running somewhere on a meshing that ’ s approachable to you. It might be on your local web. If you ’ re running Appium locally, you don ’ t really notice very much that Appium might be far away, because it ’ s not. It ’ s in the same spot as your examination script, but Appium might be run somewhere on the former side of the world from your trial script. Because Appium has this client-server architecture, Appium servers can be situate anywhere in the world as long as you can mail an HTTP request to them, and this ply a ton of benefits. This client-server architecture is outstanding for a lot of intellect. It intend that you can feature clients written in any different words, but they all speak to the server which is just a single implementation of a sort of respite API which can get bidding, doesn ’ t have to be written in all of these different languages. You can talk to Appium servers around the reality, which might be skillful because those Appium servers might be link to devices around the world – device that you don ’ t have access to locally, and yet you can still write and run your exam script locally on your machine without receive to zip it up and mail it somewhere. There ’ s a lot of actually great benefits to this architecture, but it does experience some downsides as well. One of the thing we can observe is thatevery Appium bid, because of this client-server architecture, is a freestanding HTTP petition. This isn ’ t a big deal when you ’ re running your test against an Appium server that ’ s running topically, because HTTP requests over the local interface are essentially inst. There ’ s a bit of clip that it take of course, but it ’ s essentially instantaneous. So, you don ’ t really notice any problems there, but opine if the Appium servers across the world. Now every command that you execute in your tryout script is triggering an HTTP request that ’ s having to traverse the global internet all the way around the world, which can be a bit time-consuming. Let ’ s take a look at this in a slight bit more detail. What this diagram is showing is a sort of timeline from top to penetrate of an Appium exam which usually guide place within the course of a individual Appium session. So in any Appium test, you typically have a new session call which starts up the device or simulator or whatever that you ’ re working with, and then at some point you have a quit session call. So those are always there in any given test, but so in between those two you might receive any number of commands. You might have two commands. You might have 200 commands. It all depends on what you ’ re trying to achieve in your test. Now the thing that this diagram is pointing out, is that for each of these, your client is sending a web postulation to the Appium server, and then the waiter is sending a response rearwards. Now if we imagine that the server is somewhere far away from you, or if you have particularly slow net, or if the packets hold to route through a peculiarly slow path, so you might be looking at a decent amount of clip for each of these request and responses to lead place. Maybe let ’ s say a hundred milliseconds as an arbitrary surmise. I think from where I ’ m sitting in Vancouver to let ’ s say Tokyo, Japan, average latency, kind of base latency, would be something like 90 milliseconds. So we could imagine that this might be a real-world example of me run a test against an Appium server in Tokyo. So what we observe from all this is that if we want to figure out our total examination time, we obviously feature to factor latency into the equation. It ’ s not just the time that the Appium server takes to execute the command, it ’ s too the clip that it occupy her client to send the command and the clip that the Appium host takes to send the response backwards to the client. So that full latency we could develop with this little schema that I receive devour at the arse. Total latency equal the number of test dictation or test steps plus 2. Plus 2 because we always have the new session and the quit session, so those aren ’ t consider as test steps. Those are kind of boilerplate the things that are aside of every single session, because so you get your figure of actual examination commands. Each of those is breed by the latency that exists. I should say average latency, really, that exist between the node and server, and then x2 because we have both a request and a response of course. So let ’ s take a look at what that would look like with an instance in praxis. So here ’ s the formula define again using something that looks like code. I guess this would be like PHP code or something like that, but hopefully you can understand it. If we substitute actual number for these variable here, like let ’ s use the figure of 90 milliseconds, or that this 90 hither is the number of commands that are occurring in my test, so that ’ s the figure of commands. So total we have 92 commands that are going back and forth across the network, and let ’ s say we receive a latency of a hundred milliseconds for each direction of each dictation. Then what we see is that the latency, or I should say clip lost due to latency or the total latency of our test, is 18.4 seconds. So 18,400 msec. 18.4 seconds. This is a fair amount of time we ’ ve lose just due to latency in our test. This is time that our Appium host isn ’ t execute anything. Client isn ’ t doing anything. It ’ s just information passing over the wire. So if you multiply this number by the number of tryout in your body-build, if you ’ ve got a hundred examination, that ’ s now 1,840 minute. If you fraction that by 60, you get the number of minutes that you ’ ve waste in your note just due to latency. Obviously squander is a strong term. Part of this is just a fact of life and you might be fine with it, but it ’ s something that we can optimize, and that ’ s what the point of this executeDriverScript lineament is, which I ’ m coming to describe here somewhat soon. Other than exactly bring time to your build,network latency can also lead to undependableness.Imagine you have a test where there is a clump of interaction happening within your application, and that interaction is fairly fast and fairly time-dependent. So, this is specially true in apps like game where rapidity is rattling important. If you ’ re trying to play a game, if you await two seconds too long to tap a button or an object – that object might not still be there anymore. If you now imagine trying to automate playing that game with Appium, you can see that time loss due to latency isn ’ t precisely time that you blow. It could also be time that prevents your test from actually succeeding. So this is one understanding that the authors of the Webdriver API decide to do something pretty unique with the touch actions API in the new edition of the Webdriver protocol. Where rather of sending each activeness one at a clip like put the finger here and then press it down and then swipe it here and so do something else with it. If each of those individual components of the activity were sent over the network, there would be no guarantee as to when they would happen in relation to one another, because web latency is there. Sometimes requests take long than former times. Sometimes there ’ s internet weather. All this kind of stuff. So, thatAPI allows pigeonholing of a lot of different actions togetherthat are then sort of unpacked and executed on the host which is local to the device, and therefore can control that things are happen with a very exact measure of time in between them. So, what executeDriverScript is is basically an attempt to do this for all Appium bid. Not just action, but any command that you can think of. It ’ s essentially a way of grouping commands together to act around latency or batch them together. You could think about it as creating a flock of commands which all get executed on the server rather than being send over the meshwork one at a time. So how does this command employment? Well, if you are utilize the Java client, it appear like telephone driver.executeDriverScript. Of course, depend on the speech you use, this might look a little different to you and you ’ ll get to touch to the support to see the dictation in your favorite language. It ’ ll look something like this: driver.executeDriverScript. How do we use this in practice? Well, let ’ s first direct a aspect at a very unproblematic test that ’ s written without this feature. So this is a tryout of login in my featherbrained little examination app that I have, where we ’ re first setting an unquestioning wait time out, because we ’ re lazy and don ’ t want to use explicit hold, so we ’ re using an implicit wait. Then we ’ re regain these different elements by accessibilityID and interact with them using the standard Appium Webdriver API driver.findElement, and then we ’ re clicking driver.Findelement, and then we ’ re sending keys. So we ’ re filling out a username and a parole, snap the login button, and then assert that we see the log out text to prove that we actually logged in successfully. So this is how we would normally write this test without use executeDriverScript. What if we desire to batch all of these commands together? So so instead of be action one at a time and expect for the request and the response to occur for each of these, what if we grouping them together? Let ’ s remember that it ’ s not just the six or so line hither, but it actually is almost twofold that in terms of the act of commands that we ’ re running – so finding an element is a command, detent as a bidding, and so on. So we ’ ve actually got about eight or nine or ten different commands represented hither. So if we wanted to group all these together, we could use executeDriverScript like so. Basically ring driver.executeDriverScript, and putting all of what looks same code into basically one long string. So what ’ s going on here? Let ’ s have a look at this with a reference to the previous codification that we just saw: the normal method. So what we have is basically how each of the lines in the normal method is now represented by a different line within our twine hither. So instead of saying driver.manage.timeouts.iimplicitlyWait, we are saying await driver.SetImplicitTimeout. So if you cognize the Webdriver API, you can say this code within this string here and directly see this is just Webdriver codification. For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users. Now you might not know what this word await means, you might not cognize what this dollar sign function is doing, and why there ’ s a tilde fibre in front of the accessibility IDs. That might seem a slight opaque to you, but if you know how to indite Appium tests in any language, you could probably appear at this and say what ’ s bechance hither is we ’ re encoding a unscathed set of steps, a whole multitude of commands in one twine. Basically you can do it in JavaScript when you call the eval role. You can put a cluster of JavaScript in a string and then evaluate it all in one go. That ’ s really more or less what ’ s happening hither. This is actually JavaScript code that we ’ ve written in this string. It ’ s not merely JavaScript code, but it ’ s codification that ’ s compose with access to a driver object, and this driver object comes from the Webdriver I/O library. So, executeDriverScript is basically a method that allow you to remotely execute a WebdriverIO script – merely written as a single twine. If you ’ ve ne'er heard of WebdriverIO, it ’ s probably the good Webdriver client for JavaScript, and it supports selenium. It indorse Appium. It ’ s very good maintained. I ’ ve made a few part to it myself. It ’ s a outstanding project, really fun to work with, and a lot of people use it to write their test automation codification. Basically if you wanted to know about what does this buck sign function mean? What does this tilde mean? You would go to the WebdriverIO corroboration and APIs and learn about that. Just to share – since we ’ re on this blind – what they do mean the buck sign function is essentially the findElement call, just a little more concise, and the tilde in front of a string means use the accessibilityID locator strategy. So instead of having freestanding strategies and selectors in the WebdriverIO API, they ’ re all sort of coquet together into one twine, and the Webdriver I/O Library kind of intelligently looks at the shape of the string and decides what locator strategy to use. For accessibilityID the form of magic first fibre is this tilde, where as you can see in the XPath query, because we begin with two forward slashes, the library is able to detect that that ’ s an XPath locator strategy without us having to specify that explicitly. We also experience this await keyword. That ’ s because in JavaScript, we are treat with promises and a weight is a way of kind of wait for the results of a hope and on wrapping it without having to variety of mess with hope in their aboriginal way. It allow us write cleaner code. We ’ ve got two awaits here on each of the line, because we ’ re actually running two commands: one for finding and one for clicking. There might be a more elegant way to write this. This is the first way that come to me and that works using the WebdriverIO Library. So, that ’ s a slight bit about WebdriverIO, but we can step backwards and actually ask why JavaScript? Why use JavaScript in the initiatory spot? The answer is that Appium itself is written in JavaScript, so executing this codification on the server side was more or less lilliputian, because we had access to the WebdriverIO API natively from within node.js (which is what Appium escape on). Also, a lot of citizenry use this library. Most citizenry have some familiarity with JavaScript, even if they don ’ t with early languages and we wish, on the Appium squad, execute things in JavaScript. Sometimes it bothers some people, but we ’ ve be fairly successful by deposit with JavaScript, so it seemed like a full idea. You might also be thinking: wait a 2d, every clip I ’ ve compose JavaScript or read anything about JavaScript, I ’ ve ever heard to ne'er put code in strings and evaluate it blindly. That ’ s actually truly good advice, because what we ’ re enabling here through this feature is basically a kind of remote code execution, which is constantly risky if you permit your users to wind up arbitrary code and run it in another context. Who knows what kinds of clever and dastardly things they might do? So this is direct for granted. This is true. Because there is a fundamental concern about protection (because we ne'er know what somebody might be capable to do), to use this feature in your Appium server, you actually hold to start the server with a special iris. This is a new flag that has been inclose late: the allow-insecure flag, where you can afford a special label to tell Appium to turn a feature on which is not on by nonpayment. So if you ’ re running an Appium host, this lineament is not on by default. You don ’ t have to vex about any protection implemented implication of it, unless you explicitly become this characteristic on. What kind of security implications are we really talking about here? How concerned should you be by turning this feature on if you are an Appium administrator? Personally, I don ’ t consider you should be that concerned because we take a lot of forethought in really delimitate what you can and can ’ t do with the codification snippets you send in. First of all, all the code is not really executed in the Appium context. It ’ s execute in a completely freestanding node.js summons, so it doesn ’ t get entree to any of the object in Appium ’ s memory. It can ’ t snooper on other sessions that are happening. It really has no access to any of the node.js API itself, so it can ’ t read anything from the file system or call any of the standard node.js library. All it has access to is the driver object from WebDriverIO, which is pre-connected to your session, not anyone else ’ s session. There ’ s a console objective, so you can write logs to the console. There ’ s a promise object in case you need to tuck some sleeps or something into your script. So this is a pretty minimal set of things. You have accession to the full JavaScript language and syntax, so you can write loops and if statements and things like that. Otherwise, it ’ s not like you have a lot of tools at your administration to try and do anything nasty. I should also say that with this API you can write logs which get returns to you as part of the API reply, and you can also return any kind of objective that you want. As long as it ’ s JSON serializable, you ’ ll get that object back in your customer script. Also, if you return an element from this hand, like you wanted to find an factor and regress it as the concluding footstep in your driver script, that will be become into a web element that you can use as a native web element in your exam script too. So it ’ s a pretty intuitive and pretty utile feature. So, let ’ s talking about what this appear like in practice in terms of solving the latency trouble. Because remember the whole mind behind this is that if you can combine a caboodle of commands into a batch and have them executed locally to the Appium server, so you save the clip lost due to latency for the request and reply for each of those commands. So we should expect that if we use executeDriverScript and put our commands in this batch mode (alternatively of escape them one at a clip) that the latency problem will fundamentally go away. That could have a large speeding up or time savings within our tryout steps, if we ’ re execute our test on servers that are not very closely to our client ’ s script. So this is so what we find. Here is a small chart of some tryout that I ran in this series of examination. I basically compared time loss due to latency across local executing on device that are not close to me but not too far aside in California and then devices which are quite a bit farther away in Tokyo, Japan. So what we can see is if we just look at the ordinary tryout clip for the scenarios where we ’ re not using execute driver, that the further the server gets aside from the client, the high the fair trial time and this is solely due to latency. This isn ’ t due to the Appium waiter twist guide longer in those spot. We ’ re actually just adding all of these seconds due to latency. So, you cognise between scat topically and running in Tokyo, we ’ ve got about 2x different. So it takes doubly as long for a tryout to run in Tokyo as it does locally, just because Tokyo ’ s farther forth. So when we seem at the situations where we are using execute driver what we see is a pretty important speed up. We don ’ t see the speed up locally. We see a 0.8 % speed up. That ’ s because we save nearly no time by batch dictation. I ’ m surprised we see anything at all. This 0.8 % should believably be regarded as nill, because clip loss due to latency on the local network is basically nill. When I ’ m running tests on device in California from my part in Vancouver, I see about a 40 % velocity up if I put my commands within the executeDriverScript batch. Against Tokyo device, I see an even bigger swiftness up. So just in case you ’ re wondering what are the details of the test that I ran. These are on existent Android device in these different property around the world. Each test condition: so combination of server location and alternative of executeDriverScript or not contain 15 separate tests. Each test bear five cringle of a login/logout flow, the like steps that I showed you earlier. In other words: each of these 15 test contain 90 commands for a total of 1,350 command for condition. So we be able to get a pretty significant number of commands, so I think that our results here are pretty solid. It ’ s also we ’ re tell that the speed-up percentages you see are speed-up of exam time, not total session clip, so this doesn ’ t include session start up. Session inauguration can be a big factor in overall examination time, but test time is extremely dependent and variable based on the number of test steps you have, whereas startup clip is not. So, I didn ’ t ingredient that into the speed-up, so that we are really equate apple to apples hither. So to summarize this section on executeDriverScript, latency can be a immense cause of slowness and unreliability. We can work around this using executeDriverScript by batching whatever commands we want into a single HTTP call. ExecuteDriverScript uses the Webdriver IO API. You fundamentally write WebdriverIO code as a twine and then send that to the Appium server (which then expose that and executes it). Because of potential protection care, you do need to start Appium with a peculiar masthead to make sure that you ’ re not unknowingly opening yourself up to the protection implication. That being said, there are very few really bad things that I think are possible within this model, but I should disclaim that I ’ m not a security expert. There are hackers out there that are probably a lot voguish than me who might be able to lead advantage of this. So, talking to your security people. Figure it out. Beware. I should likewise say that while this is I think a really interesting feature, you shouldn ’ t use it just because you want to speed things up. If you don ’ t have a existent problem with latency, there are lot of problems with it. For illustration, stack traces no longer will be shown to you at a certain line in your node script. You ’ ll have to dig through the Appium logs to figure out what precisely failed and where. So there ’ s a few different ground that it ’ s probably not a full idea to use this unless you really need the performance benefits that it can provide. That being said, I think it ’ s a pretty interesting new lineament. So, let ’ s move on and talk about another strategy for reduce the sum of clip lost to latency – this time specifically when running tests on cloud services that themselves have devices scattered around the world. So, another way of putting this is that execute driver hand helps latency lose or clip loss due to latency between your node book and the endpoint where your client is speak to at the cloud service. But what about latency that live within a cloud service itself? This can be an issue becausemany Appium clouds use load balancersto make living easier for the users of that service. In other words, what we can find is an architecture like this, where you ’ re the user of this cloud service writing a exam and you ’ re using an Appium customer, which is local to you. Then as the emplacement of the Appium waiter that you encode in your scripts, you ’ re given some kind of cloud service launching point. This is often a load balancer. So no topic which devices or locations or platforms you ’ re automating, there ’ s often a single Appium endpoint that ’ s kind of an entry point into the whole cloud service. That cargo haltere is creditworthy for sending your Appium requests to former Appium server, potentially century or thousands of other Appium servers, which are themselves connected to devices or emulators or simulators. The shipment balancer is creditworthy for keep trail of session IDs and making certain that create session requests are getting send to the correct spot and that subsequent commands are getting sent to the right property. So this is a rattling common architecture that we find. Notice that within this architecture, we don ’ t exactly have an HTTP request between the client and the cloud service entry point. We likewise have HTTP asking between the entry point, the consignment halter, and the sort of most outside Appium servers or the furthermost Appium servers that are actually connected to device and really scarper the Appium software. So what kind of network connection lies between the load halter and these Appium server? Well as a user of the cloud service, you don ’ t necessarily know. It could be local, it could be within a single data centerfield, but it could also be across the existence. You might have a load balancer in California and an Appium host in Tokyo, and that ’ s quite a bit of a way apart. So if you ’ re running a tryout from Tokyo, now your requests are going to California and then rearwards to Tokyo, when theoretically that ’ s a bit unneeded. So there is clip loss due to latency within cloud environments as easily. Unfortunately, you have no real control over that. It all depend on how the cloud service has architected scheme. So if before we have this formula where full latency or time lost is the number of commands plus 2, time the latency doubled, now we actually get something a little bit more complex where we have both the extraneous latency and the inside or internal latency. You really have to add those together when you ’ re address with a loading haltere and then multiply the result by 2. So here ’ s an example. This is what I really ran in my experiments with this. We ’ ve got commands going from Vancouver to a lading balancer in California and then over to Japan (where this is not wholly out of the way, but there is a more optimal path for my request take, which would be if I travel directly from Vancouver to Japan). Depending on the way that internet traffic routing plant, this might be really a lot faster, because they ’ re obviously physical constraints due to the speed of light. Things like that. But there are also former hard-nosed restraint, like which paths packets have to take. It might be yet less effective going through California than this simple picture shows. So, the good intelligence is that because of some work that we ’ ve done in the Appium client libraries,cloud providers can now have their load balancers (their entry point) directly connect node your test scripts to more remote Appium servers(the ones that are directly connected to the Appium device). So that turns the previous architectural diagram into something that looks a lot more like this: where after the initial request to the payload balancer, any subsequent requests from the client to the Appium server no longer goes through the load balancer as an intermediary. Instead, it locomote directly to the Appium server. So, it fundamentally cuts out the wholesaler, saving any clip loss due to latency that you get from making these multiple hops. We call this Unmediated Connect. Basically the way it works is that your client first speaks to the load balancer, which starts a session on a more remote Appium legion somewhere within the cloud service. Then the load balancer, when it responds with the new session result to your client, it ornament that response with information about these specific remote Appium host (which is going to be servicing your session). Now the Appium client can use that information to verbalise directly to that host, rather than locomote through the load balancer if it wants. So, the way that the load balancer decorates the reaction is by adding specifically these key to the response objective. They all start with Direct Connect. Obviously, we have to specify these four pieces of information: the protocol that should be used, the horde, the porthole, and the path that should be prefix to any of the API calls. So, HeadSpin was able to implement this for me so I was able to again gather some data on the existent consequences of using this lineament in term of clip loss due to latency. So again, let ’ s run some numbers. The way that this test worked was very alike to the way that the executeDriverScript worked. I fundamentally had all the tests clients located in my office in Vancouver, and I ran tests on device located in California and Tokyo, Japan – sometimes using Direct Connect and sometimes not using Direct Connect. Sometimes when I wasn ’ t using Direct Connect, my requests be go to California and then on to the devices. Sometimes they were using Direct Connect and going directly to the most distant Appium waiter. So interestingly, and I reckon this is a good illustration hither, what we see when using Direct Connect with sessions pointed at the California device, is essentially no speed – a very very small hurrying up of 1.2 % (which you might consider real or might just be an artifact of the trial that I ran). That ’ s because the payload balancer is in California and the device are as good. Whether or not I ’ m apply Direct Connect, basically the commands are follow the same itinerary. There might be a slight bit of an extra bit of time loss due to latency between the loading haltere in California and the devices in California, but they ’ re so close to each other it basically doesn ’ t create any difference. We can see a huge difference, however, when I ran tests on devices in Tokyo. Because when expend Direct Connect, my test commands were able to go directly to Tokyo and back sooner than going 1st to California and then onto Tokyo. We saw that just by slue out this hop to California, we were able to get a speed-up of about 30 %. The details of the test that I ran are basically the like as before – about 1,350 commands per condition. These answer are pretty solid in my opinion. Ans: WebDriver is a remote control interface that provides introspection and control of user agents. It offers a platform- and language-neutral wire protocol for out-of-process programs to remotely teach the behavior of web browser. Ans: Appium driver is an abstractionist class derived from the selenium java client. This category is inherit by the Android driver and iOS driver family to provide implementation and extra functions use in a nomadic automation test on Android devices/iOS devices. Ans: Testers can run the trial in a multithreaded environment utilise Appium. However, testers must ensure that no more than one tryout runs simultaneously against the like Appium server. Ans: Appium supports all words that support HTTP requests, like Java, JavaScript with Node.js, Python, Ruby, PHP, and Perl. Lead, Content Marketing, HeadSpin Inc. Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in crafting occupy story and marketing collateral across diverse industriousness. She excels in collaborating with cross-functional squad to germinate innovative content strategy and deliver compelling, unquestionable, and impactful content that vibrate with target audiences and enhances brand authenticity. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts..png)



Tips for Speeding Up Your Remote Appium Sessions
AI-Powered Key Takeaways
Execute Driver Script



Execute Driver Script Allows Remote Running of a WebdriverIO Script
Why Javascript?



Direct Connect


FAQs
1. What is WebDriver?
2. What is the difference between Appium driver and Android driver?
3. Is it possible for testers to run tests in a multithreaded environment by use Appium?
4. Which languages perform Appium support?
Piali Mazumdar
Tips for Speeding Up Your Remote Appium Sessions
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for advanced users (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence pragmatic guide for advanced users (Part 4)
Discover how HeadSpin can invest your business with superior test capabilities







Discover how HeadSpin can empower your occupation with superior testing capabilities
Discover how HeadSpin can authorize your business with superior testing capabilities
Connet Now


Automate This With SUSA
Test Your App Autonomously







.png)












